244 lines
4.4 KiB
C++
244 lines
4.4 KiB
C++
#include "StdAfx.h"
|
|
#include "RBList.h"
|
|
#include "globalDefine.h"
|
|
#include "globalfunc.h"
|
|
|
|
using namespace GlobalFunc;
|
|
|
|
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 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 = (RBGroups *)LinkResbufList((resbuf *)groups, lst);
|
|
}
|
|
|
|
void RBList::FreeGroups()
|
|
{
|
|
if (groups)
|
|
{
|
|
Release(groups);
|
|
groups = NULL;
|
|
}
|
|
}
|
|
|
|
PGroups RBList::SearchNode(int code) const
|
|
{
|
|
RBGroups *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);
|
|
}
|
|
|
|
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 RBGroups(*(TCHAR **)buf);
|
|
pg->code = code;
|
|
pg->next = groups;
|
|
groups = pg;
|
|
}
|
|
}
|
|
else if (type == RT3DPOINT || type == RTPOINT)
|
|
{
|
|
if(pg)
|
|
{
|
|
*(ADSGePoint3d *)(pg->point) = **(ADSGePoint3d **)(buf);
|
|
}
|
|
else
|
|
{
|
|
pg = new RBGroups(*(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 RBGroups(*(TLong_ptr **)buf);
|
|
pg->code = code;
|
|
pg->next = groups;
|
|
groups = pg;
|
|
}
|
|
}
|
|
else if(type == RTSHORT)
|
|
{
|
|
if(pg)
|
|
{
|
|
pg->shortInt = *(int*)buf;
|
|
}
|
|
else
|
|
{
|
|
pg = new RBGroups(*(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 RBGroups(*(ads_real *)buf);
|
|
pg->code = code;
|
|
pg->next = groups;
|
|
groups = pg;
|
|
}
|
|
}
|
|
else if(type == RTLONG)
|
|
{
|
|
if(pg)
|
|
{
|
|
pg->longInt = *(long *)buf;
|
|
}
|
|
else
|
|
{
|
|
pg = new RBGroups(*(long *)buf);
|
|
pg->code = code;
|
|
pg->next = groups;
|
|
groups = pg;
|
|
}
|
|
}
|
|
else
|
|
{
|
|
ads_abort(_T("Bad Type"));
|
|
}
|
|
return RTNORM;
|
|
}
|
|
|
|
int RBList::SetData(int code,...)
|
|
{
|
|
void *buf = (char *)&code+sizeof(int*);
|
|
return _SetData(code,buf);
|
|
}
|
|
|