示例#1
0
/* parse_cvt_fnc_t cvt_rcc8000 */
static u_long
cvt_rcc8000(
	    unsigned char *buffer,
	    int            size,
	    struct format *format,
	    clocktime_t   *clock_time,
	    void          *local
	    )
{
	if (!Strok(buffer, format->fixed_string)) return CVT_NONE;
#define	OFFS(x) format->field_offsets[(x)].offset
#define STOI(x, y) Stoi(&buffer[OFFS(x)], y, format->field_offsets[(x)].length)
	if (	STOI(O_DAY,	&clock_time->day)	||
		STOI(O_MONTH,	&clock_time->month)	||
		STOI(O_YEAR,	&clock_time->year)	||
		STOI(O_HOUR,	&clock_time->hour)	||
		STOI(O_MIN,	&clock_time->minute)	||
		STOI(O_SEC,	&clock_time->second)	||
		STOI(O_USEC,	&clock_time->usecond)
		) return CVT_FAIL|CVT_BADFMT;
	clock_time->usecond *= 1000;

	clock_time->utcoffset = 0;

#define RCCP buffer[28]
	/*
	 * buffer[28] is the ASCII representation of a hex character ( 0 through F )
	 *      The four bits correspond to:
	 *      8 - Valid Time
	 *      4 - Reject Code
	 *      2 - British Summer Time (receiver set to emit GMT all year.)
	 *      1 - Leap year
	 */
#define RCC8000_VALID  0x8
#define RCC8000_REJECT 0x4
#define RCC8000_BST    0x2
#define RCC8000_LEAPY  0x1

	clock_time->flags = 0;

	if ( (RCCP >= '0' && RCCP <= '9') || (RCCP >= 'A' && RCCP <= 'F') )
	{
		register int flag;

		flag = (RCCP >= '0' && RCCP <= '9' ) ?  RCCP - '0' : RCCP - 'A' + 10;

		if (!(flag & RCC8000_VALID))
		    clock_time->flags |= PARSEB_POWERUP;

		clock_time->flags |= PARSEB_UTC; /* British special - guess why 8-) */

		/* other flags not used */
	}
	return CVT_OK;
}
示例#2
0
文件: Database.cpp 项目: wkcn/HR
void Database::Load(){ 
	fstream fin("staff.dat");
	if(fin.fail())return;
	string temp;
	getline(fin,temp);	//Read Form Header
	while(!fin.eof()){
		getline(fin,temp);
		vector<string> data;
		StrSplit(temp,data,'#');//根据#号分割字符串

		if (data.size() != 8)break;//数据有误
		int id = STOI(data[0]);
		string name = data[1];
		STAFF_KIND kind = STAFF_KIND(STOI(data[2]));
		int age = STOI(data[3]);
		STAFF_STATE state = STAFF_STATE(STOI(data[4]));
		int manager_id = STOI(data[5]);
		int sales = STOI(data[6]);
		int events = STOI(data[7]);

		Staff *p;
		SalesMan *psalesman;
		Manager *pmanager;
		SalesManager *psalesManager;
		switch (kind){
			case SALESMAN:
				psalesman = new SalesMan(id,name,age,state);
				psalesman -> SetManagerID(manager_id);
				ChangeManagerID(id,manager_id);
				psalesman -> SetSales(sales);
				p = dynamic_cast<Staff*>(psalesman);
				break;
			case MANAGER:
				pmanager = new Manager(id,name,age,state);
				pmanager -> SetEvents(events);
				p = dynamic_cast<Staff*>(pmanager);
				break;
			case SALESMANAGER:
				psalesManager = new SalesManager(id,name,age,state);
				//p = dynamic_cast<Staff*>(dynamic_cast<Manager*>(psalesManager));
				//使用虚继承后,不会出现二义性了(有两基类)
				p = dynamic_cast<Staff*>(psalesManager);
				break;
			default:
				throw "读取数据出错!";
	 	}
		
		staffs[id] = p;
	} 
	fin.close();
	Update();
}
示例#3
0
/* parse_cvt_fnc_t cvt_trimtaip */
static u_long
cvt_trimtaip(
	     unsigned char *buffer,
	     int            size,
	     struct format *format,
	     clocktime_t   *clock_time,
	     void          *local
	     )
{
	long gpsfix;
	u_char calc_csum = 0;
	long   recv_csum;
	int	 i;

	if (!Strok(buffer, format->fixed_string)) return CVT_NONE;
#define	OFFS(x) format->field_offsets[(x)].offset
#define	STOI(x, y) \
	Stoi(&buffer[OFFS(x)], y, \
	     format->field_offsets[(x)].length)
		if (	STOI(O_DAY,	&clock_time->day)	||
			STOI(O_MONTH,	&clock_time->month)	||
			STOI(O_YEAR,	&clock_time->year)	||
			STOI(O_HOUR,	&clock_time->hour)	||
			STOI(O_MIN,	&clock_time->minute)	||
			STOI(O_SEC,	&clock_time->second)	||
			STOI(O_USEC,	&clock_time->usecond)||
			STOI(O_GPSFIX,	&gpsfix)
			) return CVT_FAIL|CVT_BADFMT;

	clock_time->usecond *= 1000;
	/* Check that the checksum is right */
	for (i=OFFS(O_CHKSUM)-1; i >= 0; i--) calc_csum ^= buffer[i];
	recv_csum =	(hexval(buffer[OFFS(O_CHKSUM)]) << 4) |
		hexval(buffer[OFFS(O_CHKSUM)+1]);
	if (recv_csum < 0) return CVT_FAIL|CVT_BADTIME;
	if (((u_char) recv_csum) != calc_csum) return CVT_FAIL|CVT_BADTIME;

	clock_time->utcoffset = 0;

	/* What should flags be set to ? */
	clock_time->flags = PARSEB_UTC;

	/* if the current GPS fix is 9 (unknown), reject */
	if (0 > gpsfix || gpsfix > 9) clock_time->flags |= PARSEB_POWERUP;

	return CVT_OK;
}
示例#4
0
文件: Database.cpp 项目: wkcn/HR
bool Database::isTruth(Staff *st,Exp *filter){
	try{
		if (filter -> kind != EXP_OP)return true;
		//根据C++特性,能够自动短路的
		if (filter -> name == "and")
			return isTruth(st,filter->lv) && isTruth(st,filter->rv);
		if (filter -> name == "or")
			return isTruth(st,filter->lv) || isTruth(st,filter->rv);
		//剩下的是=,>,<,<>,!=,<=,>=
		Exp *lv = filter -> lv;
		Exp *rv = filter -> rv;	
		if (rv->kind == EXP_STR){
			//名字,字符串比较
			string name = st -> GetName();
			if (filter->name[0] == '='){
				//防止出现==输入
				return MatchStr(name,rv->name);
			}else if (filter->name == "!=" || filter -> name == "<>"){
				return !MatchStr(name,rv->name);
			}
			if (filter->name == "<")return name < rv->name;
			if (filter->name == ">")return name > rv->name;
			if (filter->name == "<=")return name <= rv->name;
			if (filter->name == ">=")return name >= rv->name;
		}else{
			int num = GetStaffValue(st,lv->name);
			int vn = STOI(rv->name);
			if (filter -> name[0] == '=')return num == vn;
			if (filter -> name == "!=" || filter -> name == "<>")return num != vn;
			if (filter -> name == "<")return num < vn;
			if (filter -> name == ">")return num > vn;
			if (filter -> name == "<=")return num <= vn;
			if (filter -> name == ">=")return num >= vn;
		}
	}catch(...){
		return false;
	}
	return true;//出现异常,暂时不处理
}
示例#5
0
/* parse_cvt_fnc_t cvt_hopf6021 */
static u_long
cvt_hopf6021(
	     unsigned char *buffer,
	     int            size,
	     struct format *format,
	     clocktime_t   *clock_time,
	     void          *local
	     )
{
	unsigned char status,weekday;

	if (!Strok(buffer, format->fixed_string))
	{
		return CVT_NONE;
	}

	if (  STOI(O_DAY,   &clock_time->day)    ||
	      STOI(O_MONTH, &clock_time->month)  ||
	      STOI(O_YEAR,  &clock_time->year)   ||
	      STOI(O_HOUR,  &clock_time->hour)   ||
	      STOI(O_MIN,   &clock_time->minute) ||
	      STOI(O_SEC,   &clock_time->second)
	      )
	{
		return CVT_FAIL|CVT_BADFMT;
	}

	clock_time->usecond   = 0;
	clock_time->utcoffset = 0;

	status = (u_char) hexval(buffer[OFFS(O_FLAGS)]);
	weekday= (u_char) hexval(buffer[OFFS(O_WDAY)]);

	if ((status == 0xFF) || (weekday == 0xFF))
	{
		return CVT_FAIL|CVT_BADFMT;
	}

	clock_time->flags  = 0;

	if (weekday & HOPF_UTC)
	{
		clock_time->flags |= PARSEB_UTC;
	}
	else
	{
		if (status & HOPF_DST)
		{
			clock_time->flags     |= PARSEB_DST;
			clock_time->utcoffset  = -2*60*60; /* MET DST */
		}
		else
		{
			clock_time->utcoffset  = -1*60*60; /* MET */
		}
	}

	clock_time->flags |= (status & HOPF_DSTWARN)  ? PARSEB_ANNOUNCE : 0;

	switch (status & HOPF_MODE)
	{
	    case HOPF_INVALID:  /* Time/Date invalid */
		clock_time->flags |= PARSEB_POWERUP;
		break;

	    case HOPF_INTERNAL: /* internal clock */
		clock_time->flags |= PARSEB_NOSYNC;
		break;

	    case HOPF_RADIO:    /* Radio clock */
	    case HOPF_RADIOHP:  /* Radio clock high precision */
		break;

	    default:
		return CVT_FAIL|CVT_BADFMT;
	}

	return CVT_OK;
}
示例#6
0
int64_t CTrans::STOI(const std::string& sValue)
{
	return STOI(sValue.c_str());
}