// ****************************************************************************
// Investigator_Relative.h version: 1.0 date: 12/10/2005
// ---------------------------------------------------------------------------
// Summary:class Investigator_Relative
// ---------------------------------------------------------------------------
// Copyright (C) LYH_Studio @ 2005 - All Rights Reserved
// ****************************************************************************
//
// ****************************************************************************
#ifndef _LYH_STUDIO_INVESTIGATOR_RELATIVE
#define _LYH_STUDIO_INVESTIGATOR_RELATIVE
#include <string>
using std::string;
#include "Investigator_Base.h"
namespace Investigator {
//class define
class Investigator_Relative : public Investigator_Base {
public:
Investigator_Relative();
Investigator_Relative(const string &strData, const string &strCI);
virtual ~Investigator_Relative();
//member functions
virtual bool InvtAndNotice(const stringEx &strRelativeItem) throw(char*);
virtual bool InvtAndDrawMast(const stringEx &strRelativeItem) throw(char*);
virtual bool InvtAnd_N_DM(const stringEx &strRelativeItem) throw(char*);
virtual bool InvtAndNoticeAll() ;
virtual bool InvtAndDrawMastAll() ;
virtual bool InvtAnd_N_DMAll() ;
//内部类定义
/*--------->class @ Command @ discription<-----------*
*@name: Command
*@member functions:
*/
static class Command {
public:
enum command {ALL = 1, NOTICE = 2, PICTURE = 4};
enum com_err {COM_ERR_ELEMENT_TOO_FEW, COM_ERR_RELATIVE_ELEMENT_OUT_OF_RANGE};
static const char *m_comErr[2];
/*------>Function @ GetParameter @ discription <---------
*@name:int GetParameter(const stringEx ¶meter) const throw(char*);
*@parameter:const stringEx ¶meter =====>>the paremeter of console line
*@purpose:get the mix bitset correspond to the parameter which client has selected
*@return value:int
*/
static int GetParameter(const stringEx ¶meter) throw(char*);
};
};
}
#endif
///
// ****************************************************************************
// Investigator_Relative.cpp version: 1.0 date: 12/12/2005
// ---------------------------------------------------------------------------
// Summary:
// ---------------------------------------------------------------------------
// Copyright (C) LYH_Studio @ 2005 - All Rights Reserved
// ****************************************************************************
//
// ****************************************************************************
#include <cassert>
#include <iostream>
using std::cout;
using std::endl;
#include "MainInclude.h"
#include "Investigator_Relative.h"
using Investigator::Investigator_Relative;
const char *Investigator_Relative::Command::m_comErr[2] = {"关联选项太少!", "关联选项没定义!"};
Investigator_Relative::Investigator_Relative() {
}
Investigator_Relative::Investigator_Relative(const string &strData, const string &strCI) : Investigator_Base(strData,strCI) {
}
Investigator_Relative::~Investigator_Relative() {
}
bool Investigator_Relative::InvtAndNotice(const stringEx &strRelativeItem) throw(char*) {
//排错
if (strRelativeItem.length() < 2 ) {
throw Command::m_comErr[Command::COM_ERR_ELEMENT_TOO_FEW];
}
else if (!strRelativeItem.IsSubCharSet(m_strCI)) {
throw Command::m_comErr[Command::COM_ERR_RELATIVE_ELEMENT_OUT_OF_RANGE];
}
cout << '<' << strRelativeItem << "之间的关联次数>---> " << m_strData.FindInSubString(strRelativeItem, ' ') << endl;
return true;
}
bool Investigator_Relative::InvtAndDrawMast(const stringEx &strRelativeItem) throw(char*) {
//排错
if (strRelativeItem.length() < 2 ) {
throw Command::m_comErr[Command::COM_ERR_ELEMENT_TOO_FEW];
}
else if (!strRelativeItem.IsSubCharSet(m_strCI)) {
throw Command::m_comErr[Command::COM_ERR_RELATIVE_ELEMENT_OUT_OF_RANGE];
}
//获得参加调查的人数
int total = m_strData.GetSubStringNum(DATA_DIVIDER);
cout << "同时选:" << strRelativeItem << "/n:|";
const int num = m_strData.FindInSubString(strRelativeItem, DATA_DIVIDER) * (Investigator_Amount::WINDOWWIDTH -2) / total;
int times;
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),
FOREGROUND_BLUE|FOREGROUND_GREEN|FOREGROUND_INTENSITY);
for (times =0; (times < (Investigator_Base::WINDOWWIDTH-2) / 5) && (times < num); times++) {
cout << '*';
}
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),
FOREGROUND_BLUE|FOREGROUND_INTENSITY);
for ( ; (times < 2*(Investigator_Base::WINDOWWIDTH-2) / 5) && (times < num); times++) {
cout << '*';
}
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),
FOREGROUND_GREEN|FOREGROUND_INTENSITY);
for ( ; (times < 3*(Investigator_Base::WINDOWWIDTH-2) / 5) && (times < num); times++) {
cout << '*';
}
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),
FOREGROUND_GREEN|FOREGROUND_RED|FOREGROUND_INTENSITY);
for ( ; (times < 4*(Investigator_Base::WINDOWWIDTH-2) / 5)&& (times < num); times++) {
cout << '*';
}
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),
FOREGROUND_RED|FOREGROUND_INTENSITY);
for ( ; times < Investigator_Base::WINDOWWIDTH-3 && (times < num); times++) {
cout << '*';
}
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),
FOREGROUND_GREEN|FOREGROUND_RED|FOREGROUND_BLUE);
cout << endl;
return true;
}
bool Investigator_Relative::InvtAnd_N_DM(const stringEx &strRelativeItem) throw(char*) {
//排错
if (strRelativeItem.length() < 2 ) {
throw Command::m_comErr[Command::COM_ERR_ELEMENT_TOO_FEW];
}
else if (!strRelativeItem.IsSubCharSet(m_strCI)) {
throw Command::m_comErr[Command::COM_ERR_RELATIVE_ELEMENT_OUT_OF_RANGE];
}
cout << endl;
cout << '<' << strRelativeItem << "之间的关联次数>---> " << m_strData.FindInSubString(strRelativeItem, ' ') << endl;
cout << endl;
//获得参加调查的人数
int total = m_strData.GetSubStringNum(DATA_DIVIDER);
cout << endl;
cout << "同时选:" << strRelativeItem << "/n:|";
const int num = m_strData.FindInSubString(strRelativeItem, DATA_DIVIDER) * (Investigator_Amount::WINDOWWIDTH -2) / total;
int times;
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),
FOREGROUND_BLUE|FOREGROUND_GREEN|FOREGROUND_INTENSITY);
for (times =0; (times < (Investigator_Base::WINDOWWIDTH-2) / 5) && (times < num); times++) {
cout << '*';
}
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),
FOREGROUND_BLUE|FOREGROUND_INTENSITY);
for ( ; (times < 2*(Investigator_Base::WINDOWWIDTH-2) / 5) && (times < num); times++) {
cout << '*';
}
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),
FOREGROUND_GREEN|FOREGROUND_INTENSITY);
for ( ; (times < 3*(Investigator_Base::WINDOWWIDTH-2) / 5) && (times < num); times++) {
cout << '*';
}
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),
FOREGROUND_GREEN|FOREGROUND_RED|FOREGROUND_INTENSITY);
for ( ; (times < 4*(Investigator_Base::WINDOWWIDTH-2) / 5)&& (times < num); times++) {
cout << '*';
}
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),
FOREGROUND_RED|FOREGROUND_INTENSITY);
for ( ; times < Investigator_Base::WINDOWWIDTH-3 && (times < num); times++) {
cout << '*';
}
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),
FOREGROUND_GREEN|FOREGROUND_RED|FOREGROUND_BLUE);
cout << '/n'
<< endl;
return true;
}
bool Investigator_Relative::InvtAndNoticeAll() {
/*
<-----------Old version code for ------------>
//排错
if (strRelativeItem.length() < 2 ) {
throw Command::m_comErr[Command::COM_ERR_ELEMENT_TOO_FEW];
}
else if (!strRelativeItem.IsSubCharSet(m_strCI)) {
throw Command::m_comErr[Command::COM_ERR_RELATIVE_ELEMENT_OUT_OF_RANGE];
}
cout << endl;
cout << '<' << strRelativeItem << "之间的关联次数>---> " << m_strData.FindInSubString(strRelativeItem, ' ') << endl;
cout << endl;
*/
return true;
}
bool Investigator_Relative::InvtAndDrawMastAll() {
return true;
}
bool Investigator_Relative::InvtAnd_N_DMAll() {
return true;
}
//---------------------------------->>
int Investigator_Relative::Command::GetParameter(const stringEx ¶meter) throw(char*){
//确定没有额外的字符
if (!parameter.IsSubCharSet(string("-pnal"))) {
throw errMsg[ERR_MSG_PARAMETER_ERROR];
}
//因为参数前有连接符,所以定义一个真实参数数目与检测所得数目的误差值
const short offset = 1;
//获得参数数目
int itemNum = parameter.GetSubStringNum(PARAMETER_DIVIDER);
int selection = 0; //保存选项的枚举类型
stringEx tempStr;
while (itemNum != offset) {
tempStr = parameter.GetSubString(itemNum, PARAMETER_DIVIDER);
if (tempStr == "n") {
selection |= NOTICE;
//item自减,用于标记已经读取一个命令,
//直到变为1(还有一个子串参数)
itemNum--;
}
else if (tempStr == "p") {
selection |= PICTURE;
itemNum--;
}
else if (tempStr == "all") {
selection |= ALL;
itemNum--;
}
else {
throw errMsg[ERR_MSG_PARAMETER_ERROR];
}
}
return selection;
}