Templatize PortLink & PortMessage

git-svn-id: file:///srv/svn/repos/haiku/trunk/current@3950 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
shadow303
2003-07-11 01:49:58 +00:00
parent 1268b04d96
commit d1acc68a9d
4 changed files with 11 additions and 303 deletions
+2 -171
View File
@@ -536,178 +536,9 @@ printf("\tAttach(): Couldn't assign data to PortLinkData object\n");
return B_OK;
}
// These functions were added for a major convenience in passing common types
// Eventually, I'd like to templatize these, but for now, this'll do
status_t PortLink::Attach(int32 data)
template <class Type> status_t PortLink::Attach(Type data)
{
#ifdef PLDEBUG
printf("Attach(%ld)\n",data);
#endif
int32 size=sizeof(int32);
#ifdef CAPACITY_CHECKING
if(bufferlength+size>capacity)
return B_NO_MEMORY;
#endif
// create a new storage object and stash the data
PortLinkData *pld=new PortLinkData;
if(pld->Set(&data,size)==B_OK)
{
attachlist->AddItem(pld);
bufferlength+=size;
}
else
{
delete pld;
return B_ERROR;
}
return B_OK;
}
status_t PortLink::Attach(int16 data)
{
#ifdef PLDEBUG
printf("Attach(%d)\n",data);
#endif
int32 size=sizeof(int16);
#ifdef CAPACITY_CHECKING
if(bufferlength+size>capacity)
return B_NO_MEMORY;
#endif
// create a new storage object and stash the data
PortLinkData *pld=new PortLinkData;
if(pld->Set(&data,size)==B_OK)
{
attachlist->AddItem(pld);
bufferlength+=size;
}
else
{
delete pld;
return B_ERROR;
}
return B_OK;
}
status_t PortLink::Attach(int8 data)
{
#ifdef PLDEBUG
printf("Attach(%d)\n",data);
#endif
int32 size=sizeof(int8);
#ifdef CAPACITY_CHECKING
if(bufferlength+size>capacity)
return B_NO_MEMORY;
#endif
// create a new storage object and stash the data
PortLinkData *pld=new PortLinkData;
if(pld->Set(&data,size)==B_OK)
{
attachlist->AddItem(pld);
bufferlength+=size;
}
else
{
delete pld;
return B_ERROR;
}
return B_OK;
}
status_t PortLink::Attach(float data)
{
#ifdef PLDEBUG
printf("Attach(%f)\n",data);
#endif
int32 size=sizeof(float);
#ifdef CAPACITY_CHECKING
if(bufferlength+size>capacity)
return B_NO_MEMORY;
#endif
// create a new storage object and stash the data
PortLinkData *pld=new PortLinkData;
if(pld->Set(&data,size)==B_OK)
{
attachlist->AddItem(pld);
bufferlength+=size;
}
else
{
delete pld;
return B_ERROR;
}
return B_OK;
}
status_t PortLink::Attach(bool data)
{
#ifdef PLDEBUG
printf("Attach(%s)\n",(data)?"true":"false");
#endif
int32 size=sizeof(bool);
#ifdef CAPACITY_CHECKING
if(bufferlength+size>capacity)
return B_NO_MEMORY;
#endif
// create a new storage object and stash the data
PortLinkData *pld=new PortLinkData;
if(pld->Set(&data,size)==B_OK)
{
attachlist->AddItem(pld);
bufferlength+=size;
}
else
{
delete pld;
return B_ERROR;
}
return B_OK;
}
status_t PortLink::Attach(BRect data)
{
#ifdef PLDEBUG
printf("Attach(BRect(%f,%f,%f,%f))\n",data.left,data.top,data.right,data.bottom);
#endif
int32 size=sizeof(BRect);
#ifdef CAPACITY_CHECKING
if(bufferlength+size>capacity)
return B_NO_MEMORY;
#endif
// create a new storage object and stash the data
PortLinkData *pld=new PortLinkData;
if(pld->Set(&data,size)==B_OK)
{
attachlist->AddItem(pld);
bufferlength+=size;
}
else
{
delete pld;
return B_ERROR;
}
return B_OK;
}
status_t PortLink::Attach(BPoint data)
{
#ifdef PLDEBUG
printf("Attach(BPoint(%f,%f))\n",data.x,data.y);
#endif
int32 size=sizeof(BPoint);
int32 size=sizeof(Type);
#ifdef CAPACITY_CHECKING
if(bufferlength+size>capacity)