Sample C++ source for code for objectUtils.cpp. Click here to download a copy of this file.
/*
* objectUtils.cpp
* Utiltity Routines
* Copyright 2003, Bad Guys, Inc. All rights reserved.
*/
#include
/*
* callConstructors - construct array of objects
*
* Call the constructor for each object in the array
*/
void *callConstructors(void *ptr, ConstructorDestructor constructor, length_t objectSize, length_t howMany)
{
char *p;
if ((p = (char *) ptr) != 0)
{
((length_t *) p)[0] = objectSize;
((length_t *) p)[1] = howMany;
p += 2 * sizeof(length_t);
if (constructor)
{
for (; howMany--; p += objectSize)
CTORCALL_COMPLETE(constructor, p);
}
}
return(ptr);
}
/*
* duplicate - duplicate 'length' number of bytes source 'source' dest 'dest'
*
* If the destination or length is zero, don't duplicate anything.
* Return the destination.
*/
void *duplicate(char *dest, char *source, length_t length)
{
char *p;
if (dest && length)
{
p = dest;
do
{
*p = *source;
++p;
++source;
--length;
} while (length);
}
return(dest);
}
|
|