How would you name this class ?
-
Hi, I have written a nice class (well, I think it's nice... may be other don't ;)) I have called it
class Stream
but I think it's a wrong name for that, but how do I name it ?! What the class do:Stream.begin();
void * Stream.end();
Stream.clear();
Stream.add(void * data, int size);example on how to use it:
Stream myStream;
// Data for testing:
void * t1 = allocateMem(11); // 11 Bytes
void * t2 = allocateMem(21); // 21 Bytes
void * t3 = allocateMem(31); // 31 Bytes
// void * allocateMem(int size) is my function for allocating Memory... you can use memalloc as well
// strings as Data -> don't for get the ending Zero pointer ('\0')
memmove(t1,"1________x\0",11);
memmove(t2,"2________xa________x\0",21);
memmove(t3,"3________x_________xb________x\0",31);
// 1234567890123456789012345678901
/////////////////////1/////////2/////////3////////////////////////////myStream.begin(); // tell the class to clear old stream and prepare for new
printf(" fill stream:\n"); myStream.add(t1,11); // adding data to stream
printf(" fill stream:\n"); myStream.add(t2,21);
printf(" fill stream:\n"); myStream.add(t3,31);
printf(" --- stream completed ---\n");// end stream and return the resolving data with header and block information:
char * myData = (char *) myStream.end();/////////////////////////////////////////////////////////////////////
// rebuild data from stream:
//// get header information:
tStreamheader * pStreamheader = (tStreamheader *)myData;// how many blocks ?
printf(" num of blocks: %i\n",pStreamheader->numblocks);// first block size?
unsigned long * pBlocksize;
char * pBlockdata = NULL;// offset to step throu stream
unsigned long myoffset = sizeof(tStreamheader); // we want the data, so skip the header// loop to print out the data of the block
for (int i = 0; i< (int) pStreamheader->numblocks; i++) // all blocks
{
pBlocksize = (unsigned long *) (myData + myoffset); // blocksize
myoffset+=sizeof(unsigned long); // skip blocksize to get blockinfo
pBlockdata = (char *)allocateMem(*pBlocksize); // make room for block data
memmove(pBlockdata, myData + myoffset,*pBlocksize); // copy block data
myoffset+=*pBlocksize; // skip block data to get next block lenght// print out what we got:
printf(" Stream Block %i size = %u\n", i, *pBlocksize);
printf(" Stream Block data = %s\n",pBlockdata);pBlockdata = freeMem(pBlockdata); // delete blockdata
}t1 = freeMem(t1);
t2 = freeMem(t2) -
Hi, I have written a nice class (well, I think it's nice... may be other don't ;)) I have called it
class Stream
but I think it's a wrong name for that, but how do I name it ?! What the class do:Stream.begin();
void * Stream.end();
Stream.clear();
Stream.add(void * data, int size);example on how to use it:
Stream myStream;
// Data for testing:
void * t1 = allocateMem(11); // 11 Bytes
void * t2 = allocateMem(21); // 21 Bytes
void * t3 = allocateMem(31); // 31 Bytes
// void * allocateMem(int size) is my function for allocating Memory... you can use memalloc as well
// strings as Data -> don't for get the ending Zero pointer ('\0')
memmove(t1,"1________x\0",11);
memmove(t2,"2________xa________x\0",21);
memmove(t3,"3________x_________xb________x\0",31);
// 1234567890123456789012345678901
/////////////////////1/////////2/////////3////////////////////////////myStream.begin(); // tell the class to clear old stream and prepare for new
printf(" fill stream:\n"); myStream.add(t1,11); // adding data to stream
printf(" fill stream:\n"); myStream.add(t2,21);
printf(" fill stream:\n"); myStream.add(t3,31);
printf(" --- stream completed ---\n");// end stream and return the resolving data with header and block information:
char * myData = (char *) myStream.end();/////////////////////////////////////////////////////////////////////
// rebuild data from stream:
//// get header information:
tStreamheader * pStreamheader = (tStreamheader *)myData;// how many blocks ?
printf(" num of blocks: %i\n",pStreamheader->numblocks);// first block size?
unsigned long * pBlocksize;
char * pBlockdata = NULL;// offset to step throu stream
unsigned long myoffset = sizeof(tStreamheader); // we want the data, so skip the header// loop to print out the data of the block
for (int i = 0; i< (int) pStreamheader->numblocks; i++) // all blocks
{
pBlocksize = (unsigned long *) (myData + myoffset); // blocksize
myoffset+=sizeof(unsigned long); // skip blocksize to get blockinfo
pBlockdata = (char *)allocateMem(*pBlocksize); // make room for block data
memmove(pBlockdata, myData + myoffset,*pBlocksize); // copy block data
myoffset+=*pBlocksize; // skip block data to get next block lenght// print out what we got:
printf(" Stream Block %i size = %u\n", i, *pBlocksize);
printf(" Stream Block data = %s\n",pBlockdata);pBlockdata = freeMem(pBlockdata); // delete blockdata
}t1 = freeMem(t1);
t2 = freeMem(t2)if you wanna be an MFC junkie (hungarian strain) you put a "C" in front of it (for "Class"), and then maybe camelize and call it something like: CMyCoolStream - Nitron
"Those that say a task is impossible shouldn't interrupt the ones who are doing it." - Chinese Proverb
-
if you wanna be an MFC junkie (hungarian strain) you put a "C" in front of it (for "Class"), and then maybe camelize and call it something like: CMyCoolStream - Nitron
"Those that say a task is impossible shouldn't interrupt the ones who are doing it." - Chinese Proverb
Strange :omg:, I always thought that "C" stands for MFC (Microsoft Foundation Class) so if you call your classes like "CMyClass" you say that your class is only for MFC. So I won't put any "C" before my class name ;P but anyway: My class isn't a real stream class, so I thought that "Stream" is not the right name for it: neither CMyVeryCoolAbsoluteUnbelivableWorkingBuglessSpiritRichMasterlyWorkOf ArtStream will do... I thought about packing names because it is packing data to one big block. Also DataCollector, BufferPacker, DataPatcher, DataConnector, DataWeld, DataSoupPot or DataMashCollectingTank...:wtf::laugh::omg::eek::laugh:;P So I am not sure what it really is... may be I have to expand it a littlebit more so it would be really a stream class: i have to overload the << and >> operators etc. in that way that you can use it as follows:
network_in<>MyStream>>MyClass;
but I don't think that it is possible to create such an intelligent class :| but any way: I will use this class to prepare Data to be send over network and also to be reconverted back to its old structure after receiving it on the second pc.
datastructure -> Stream -> sending -> receiving -> Stream -> datastructure
Thank you :rose:Sendel
PS: I will release this code here for free anyway: if you want or if you don't!;P The only place for millions of bugs is the Rainforest