//-------------------------------------------------------------------------------------------------------+ // Copyright (C), 1998-2007, SH Software Co. Ltd. // = FileName : RBList 类 // = Version : ver2.0 // = Author : zjq // = CreateDate : 2002-09-09 // = Description: RBList 定义 // = Maintainers: // //-------------------------------------------------------------------------------------------------------+ #include "StdAfx.h" #include "RBList.h" #include "XGlobalFunc.h" #include "XPrivateGlobalFunc.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 /* Entity 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 RBList::SizeOfType(int type)const { if(type >= 5011 || type <= 5000) { ads_abort(_T("Invalid RB type")); } return s_sizeOfType[type - RTNONE]; } RBList::RBList() : groups (0) { } RBList::RBList(const resbuf *rb) { groups = (PGroups)(rb); } RBList::RBList (const RBList & src) { ads_printf(_T("\nDangerous in RBList!")); } RBList::~RBList() { if (groups) { Release(groups); } } RBList::operator resbuf *() { return (resbuf *)groups; } RBList::operator void * () { return groups; } int RBList::operator !() const { return !groups; } void RBList::operator = (const RBList & src) { ads_printf(_T("\nDangerous in RBList=!")); } void RBList::Append(resbuf * lst) { groups = (Groups *)AT_link_list((resbuf *)groups, lst); } void RBList::FreeGroups() { if (groups) { Release(groups); groups = NULL; } } PGroups RBList::SearchNode(int code) const { Groups *pg; for (pg = groups; pg && (pg->code != code); pg = pg->next); return (pg); } int RBList::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 RBList::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; } RBList::RBList(int type,...) { groups = VBuildList(&type); } #ifdef _WIN64 // Only accept one arg int RBList::_SetData(int code, va_list buf) // to support Entity::GetData(); { PGroups pg=SearchNode(code); int type=TypeOfCode(code); if (type == RTNONE) { ApplicationError(_T("\nError in calling RBList::SetData.The type of this code is RTNONE.")); return RTERROR; }; // handle point data first; if (type==RTSTR) { if(pg) { free(pg->string); pg->string=_tcsdup(va_arg(buf, TCHAR *)); } else { pg=new Groups(*(TCHAR **)buf); pg->code=code; pg->next=groups; groups=pg; } }else if (type==RT3DPOINT || type ==RTPOINT) { if(pg) *(XPoint *)(pg->point)=*va_arg(buf, XPoint *); else { pg=new Groups(*va_arg(buf, XPoint*)); pg->code=code; pg->next=groups; groups=pg;} } else if (type==RTENAME || type==RTPICKS) { // Add RTPICKS, ZJQ, 96.3.15 if(pg) memcpy(pg->adsName,*(ads_name**)buf,sizeof(ads_name)); //*(ads_name *)(pg->adsName)=*va_arg(buf, ads_name*); else { pg=new Groups(); pg->code=code; pg->next=groups; groups=pg; //*(ads_name *)(pg->adsName)=*va_arg(buf, ads_name*); memcpy(pg->adsName,*(ads_name**)buf,sizeof(ads_name)); } }else if(type==RTSHORT) { if(pg) pg->shortInt = va_arg(buf, int); else { pg=new Groups(va_arg(buf, int));pg->code=code; pg->next=groups; groups=pg;} }else if(type==RTREAL || type==RTANG || type==RTORINT) { if(pg) pg->real = va_arg(buf, double); else { pg=new Groups(va_arg(buf, double)); pg->code=code; pg->next=groups; groups=pg;} }else if(type==RTLONG) { if(pg) pg->longInt = va_arg(buf, long); else { pg=new Groups(va_arg(buf, long)); pg->code=code; pg->next=groups; groups=pg;} } else if(type==RTLONG_PTR) { if(pg) pg->longPtr=va_arg(buf, LONG_PTR); else {pg=new Groups(va_arg(buf, LONG_PTR)); pg->code=code; pg->next=groups; groups=pg;} }else { ApplicationError(_T("Bad Type in RBList::SetData")); return RTERROR; }; return RTNORM; } #else int RBList::_SetData(int code,void *buf) { PGroups pg = SearchNode(code); int type = TypeOfCode(code); if (type == RTNONE) { ApplicationError(_T("\nError in calling RBList::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 Groups(*(TCHAR **)buf); pg->code = code; pg->next = groups; groups = pg; } } else if (type == RT3DPOINT || type == RTPOINT) { if(pg) { *(XPoint *)(pg->point) = **(XPoint **)(buf); } else { pg = new Groups(*(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 Groups(*(LONG_PTR **)buf); pg->code = code; pg->next = groups; groups = pg; } } else if(type == RTSHORT) { if(pg) { pg->shortInt = *(int*)buf; } else { pg = new Groups(*(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 Groups(*(ads_real *)buf); pg->code = code; pg->next = groups; groups = pg; } } else if(type == RTLONG) { if(pg) { pg->longInt = *(long *)buf; } else { pg = new Groups(*(long *)buf); pg->code = code; pg->next = groups; groups = pg; } } else { ads_abort(_T("Bad Type")); } return RTNORM; } #endif int RBList::SetData(int code,...) { #ifdef _WIN64 va_list args; va_start(args, code); int rc = _SetData(code, args); va_end(args); return rc; #else void *buf=(char *)&code+sizeof(int); return _SetData(code,buf); #endif //void *buf = (char *)&code+sizeof(int); //return _SetData(code,buf); }