//-------------------------------------------------------------------------------------------------------+ // Copyright (C), 1998-2007, Beijing Tangent Software Co. Ltd. // = FileName : TRBList 类 // = Version : ver2.0 // = Author : wlw // = CreateDate : 2002-09-09 // = Description: TRBList 定义 // = Maintainers: // //-------------------------------------------------------------------------------------------------------+ #include "StdAfx.h" #include "TRBList.h" #include "TchGlobalFunc.h" #include "TchPrivateGlobalFunc.h" static const signed char s_sizeOfType[] = { 0, //RTNONE 5000 /* No result */ sizeof(ads_real), //RTREAL 5001 /* Real number */ sizeof(ads_point), //RTPOINT 5002 /* 2D point X and Y only */ sizeof(short ), //RTSHORT 5003 /* Short integer */ sizeof(ads_real), //RTANG 5004 /* Angle */ sizeof(TCHAR *), //RTSTR 5005 /* String */ !!Bugs may occure sizeof(ads_name), //RTENAME 5006 /* TEntitySet name */ sizeof(ads_name), //RTPICKS 5007 /* Pick set */ sizeof(ads_real), //RTORINT 5008 /* Orientation */ sizeof(ads_point), //RT3DPOINT 5009 /* 3D point - X, Y, and Z*/ sizeof(long), //RTLONG 5010 /* Long integer */ 0, //RTSTRUCT 5011 // Bug may exist }; int TRBList::SizeOfType(int type)const { if(type >= 5011 || type <= 5000) { ads_abort(_T("Invalid RB type")); } return s_sizeOfType[type - RTNONE]; } TRBList::TRBList() : groups (0) { } TRBList::TRBList(const resbuf *rb) { groups = (PGroups)(rb); } TRBList::TRBList (const TRBList & src) { ads_printf(_T("\nDangerous in TRBList!")); } TRBList::~TRBList() { if (groups) { Release(groups); } } TRBList::operator resbuf *() { return (resbuf *)groups; } TRBList::operator void * () { return groups; } int TRBList::operator !() const { return !groups; } void TRBList::operator = (const TRBList & src) { ads_printf(_T("\nDangerous in TRBList=!")); } void TRBList::Append(resbuf * lst) { groups = (TGroups *)LinkResbufList((resbuf *)groups, lst); } void TRBList::FreeGroups() { if (groups) { Release(groups); groups = NULL; } } PGroups TRBList::SearchNode(int code) const { TGroups *pg; for (pg = groups; pg && (pg->code != code); pg = pg->next); return (pg); } int TRBList::GetData(int code,void *buff) const { TCHAR *buf = (TCHAR *)buff; PGroups pg = SearchNode(code); if (!pg) { return RTERROR; } int type = TypeOfCode(code); if (type == RTNONE) { ApplicationError(_T("\nError in calling TRBList::GetData.") _T("The type of this code is RTNONE.")); return RTERROR; } if (type == RTSTR) { _tcscpy(buf,pg->string); } else if(type == RTSHORT) { *(int *)buf = pg->shortInt; } else { int typeLen = SizeOfType(type); memcpy(buf, &pg->shortInt, typeLen); } return RTNORM; } TRBList::TRBList(int type,...) { groups = VBuildList(&type); } int TRBList::_SetData(int code,void *buf) { PGroups pg = SearchNode(code); int type = TypeOfCode(code); if (type == RTNONE) { ApplicationError(_T("\nError in calling TRBList::SetData.The type of this code is RTNONE.")); return RTERROR; } if (type == RTSTR) { if(pg) { free(pg->string); pg->string=_tcsdup(*(TCHAR **)buf); } else { pg = new TGroups(*(TCHAR **)buf); pg->code = code; pg->next = groups; groups = pg; } } else if (type == RT3DPOINT || type == RTPOINT) { if(pg) { *(TADSGePoint3d *)(pg->point) = **(TADSGePoint3d **)(buf); } else { pg = new TGroups(*(double **)buf); pg->code = code; pg->next = groups; groups = pg; } } else if (type == RTENAME || type == RTPICKS) { if(pg) { memcpy(pg->adsName,*(ads_name**)buf,sizeof(ads_name)); //*(ADSName *)(pg->adsName) = **(ADSName **)(buf); } else { pg = new TGroups(*(TLong_ptr **)buf); pg->code = code; pg->next = groups; groups = pg; } } else if(type == RTSHORT) { if(pg) { pg->shortInt = *(int*)buf; } else { pg = new TGroups(*(int *)buf); pg->code = code; pg->next = groups; groups = pg; } } else if(type == RTREAL || type == RTANG || type == RTORINT) { if(pg) { pg->real = *(ads_real *)buf; } else { pg = new TGroups(*(ads_real *)buf); pg->code = code; pg->next = groups; groups = pg; } } else if(type == RTLONG) { if(pg) { pg->longInt = *(long *)buf; } else { pg = new TGroups(*(long *)buf); pg->code = code; pg->next = groups; groups = pg; } } else { ads_abort(_T("Bad Type")); } return RTNORM; } int TRBList::SetData(int code,...) { void *buf = (char *)&code+sizeof(int*); return _SetData(code,buf); }