Objcopy and objmove are used to copy objects from one place to another. Optionally a stride can be supplied. The C++ standard library will have functions much like these. The functions are equivalent to C's memcpy and memmove. In fact, when possible memcpy and memmove will be used.
Similar to memcpy and memmove, the difference between objcopy
and objmove is that objmove takes account of an overlap of source and
destination. In general, objcopy is slighty (but only slighty) faster.
Only when memcpy can be used for overlapping source and destination,
objcopy is much faster (but that is in fact an error).
Setting and copying arrays of a randomly chosen type:
The preferred function to copy n objects from one place
to another. Strides may be specified, i.e. you may copy from every
fromStride-th position into every toStride-th
one.
For built-in types the function will call memmove when possible.
Objmove works correctly if the source and destination overlap in any way.
An exception will be thrown if the source or the destination does not
exist or if the strides are non-positive.
The non-preferred function to copy n objects from one place
to another. Strides may be specified, i.e. you may copy from every
fromStride-th position into every toStride-th
one.
For built-in types the function will call memcpy when possible.
Objcopy does not take an overlap of source and destination into account.
Objmove should be used if that is an issue.
An exception will be thrown if the source or the destination does not
exist or if the strides are non-positive.
On the HP g++ is unhappy with these specializations (only!) for some reason
Fill n elements of an array of objects with the given
value, optionally with a stride. Note that the fillValue is passed
by value.
An exception will be thrown if the destination array does not exist
or if the stride is non-positive.
Example
Setting and copying arrays of built-in types:
// Create uInt array of 4 elements
uInt size=4;
int* ia = new int[size];
// Initialize all elements to value 99
objset(ia, 99, size);
// Change all odd elements to 66 -> [99 66 99 66]
objset(ia+1,66, uInt(5), uInt(2));
// Create another 4-element uInt array
int* ia2 = new int[size];
// Copy array ia into array ia2 -> [99 66 99 66]
objmove(ia2, ia, size);
// Copy the even elements of ia to the odd elements of ia2
// -> [99 99 99 99]
objcopy(ia2+1, ia, uInt(size/2), uInt(2), uInt(2));
// Create 4-element array of 3-element Block<int> objects
uInt size=4;
Block<int>* ta = new Block<int>[size];
Block<int> set(3);
// Initialize the array -> [[123][123][123][123]]
set[0] = 1; set[1] = 2; set[2] = 3;
objset(ta, set, size);
// Change odd Blocks to [777]-> [[123][777][123][777]]
set[0] = set[1] = set[2] = 7;
objset(ta + 1, set, uInt(size/2), uInt(2));
// Create another Block<int> array
Block<int>* ta2 = new Block<int>[size];
// Copy the even elements of ta to the first elements of ta2
// -> [[123][123]...]
objcopy(ta2, ta, uInt(size/2), uInt(1), uInt(2));
Member Description
void objmove (T* to, const T* from, uInt n)
void objmove (T* to, const T* from, uInt n, uInt toStride, uInt fromStride)
Thrown Exceptions
inline void objmove (Bool* to, const Bool* from, uInt n)
inline void objmove (Char* to, const Char* from, uInt n)
inline void objmove (uChar* to, const uChar* from, uInt n)
inline void objmove (Short* to, const Short* from, uInt n)
inline void objmove (uShort* to, const uShort* from, uInt n)
inline void objmove (Int* to, const Int* from, uInt n)
inline void objmove (uInt* to, const uInt* from, uInt n)
inline void objmove (float* to, const float* from, uInt n)
inline void objmove (double* to, const double* from, uInt n)
inline void objmove (Complex* to, const Complex* from, uInt n)
inline void objmove (DComplex* to, const DComplex* from, uInt n)
inline void objmove (const void** to, const void*const *from, uInt n)
inline void objmove (const char** to, const char*const *from, uInt n)
inline void objmove (void** to, void*const *from, uInt n)
inline void objmove (char** to, char*const *from, uInt n)
void objcopy (T* to, const T* from, uInt n)
void objcopy (T* to, const T* from, uInt n, uInt toStride, uInt fromStride)
Thrown Exceptions
inline void objcopy (Bool* to, const Bool* from, uInt n)
inline void objcopy (Char* to, const Char* from, uInt n)
inline void objcopy (uChar* to, const uChar* from, uInt n)
inline void objcopy (Short* to, const Short* from, uInt n)
inline void objcopy (uShort* to, const uShort* from, uInt n)
inline void objcopy (Int* to, const Int* from, uInt n)
inline void objcopy (uInt* to, const uInt* from, uInt n)
inline void objcopy (float* to, const float* from, uInt n)
inline void objcopy (double* to, const double* from, uInt n)
inline void objcopy (Complex* to, const Complex* from, uInt n)
inline void objcopy (DComplex* to, const DComplex* from, uInt n)
inline void objcopy (const void** to, const void*const *from, uInt n)
inline void objcopy (const char** to, const char*const *from, uInt n)
inline void objcopy (void** to, void*const *from, uInt n)
inline void objcopy (char** to, char*const *from, uInt n)
void objset (T* to, T fillValue, uInt n)
void objset (T* to, T fillValue, uInt n, uInt toStride)
Thrown Exceptions