Copy.h

Classes

Global Functions -- Copy objects from one C-style array to another. (full description)
Global Functions -- Test routines (full description)
Global Functions -- Copy methods (full description)

Copy objects from one C-style array to another. (source)

Interface

void objthrowmv1(const void *to, const void *from, const uInt n)
void objthrowmv2(const void *to, const void *from, const uInt n, const uInt toStride, const uInt fromStride)
void objthrowcp1(const void *to, const void *from, const uInt n)
void objthrowcp2(const void *to, const void *from, const uInt n, const uInt toStride, const uInt fromStride)
void objthrowfl1(const void *to, const uInt n)
void objthrowfl2(const void *to, const uInt n, const uInt toStride)

Description

Review Status

Reviewed By:
Friso Olnon
Date Reviewed:
1995/03/14
Programs:
Tests:

Synopsis

Objset is used to fill a C-style array of objects.

Objcopy and objmove are used to copy objects from one place to another. Optionally a stride can be supplied.

The functions are equivalent to C's memcpy and memmove. When possible C++ standard library functions are used to implement them

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.

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));
    

Setting and copying arrays of a randomly chosen type:

    // 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 objthrowmv1(const void *to, const void *from, const uInt n)

Throw the various AipsErrors when incorrect arguments used

void objthrowmv2(const void *to, const void *from, const uInt n, const uInt toStride, const uInt fromStride)

void objthrowcp1(const void *to, const void *from, const uInt n)

void objthrowcp2(const void *to, const void *from, const uInt n, const uInt toStride, const uInt fromStride)

void objthrowfl1(const void *to, const uInt n)

void objthrowfl2(const void *to, const uInt n, const uInt toStride)


Test routines (source)

Interface

void objtestmv(uInt &nLeft, uInt &startLeft, uInt &startRight, const void *to, const void *from, const uInt n, const uInt toStride, const uInt fromStride, const void *toPn, const void *fromPn, const uInt fromMto, const uInt toMfrom)

Description

Member Description

void objtestmv(uInt &nLeft, uInt &startLeft, uInt &startRight, const void *to, const void *from, const uInt n, const uInt toStride, const uInt fromStride, const void *toPn, const void *fromPn, const uInt fromMto, const uInt toMfrom)

Test on how to handle the overlap in move

Copy methods (source)

Interface

void objmove(T* to, const T* from, uInt n)
void objmove(T* to, const T* from, uInt n, uInt toStride, uInt fromStride)
void objcopy(T* to, const T* from, uInt n)
void objcopy(T* to, const T* from, uInt n, uInt toStride, uInt fromStride)
void objset(T* to, const T fillValue, uInt n)
void objset(T* to, const T fillValue, uInt n, uInt toStride)

Description

Member Description

void objmove(T* to, const T* from, uInt n)
void objmove(T* to, const T* from, uInt n, uInt toStride, uInt fromStride)

The general function to copy n objects from one place to another if overlap between to and from fields is possible. Strides may be specified, i.e. you may copy from every fromStride-th position into every toStride-th one.

The function will call std::copy() 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 (and n is non-zero) or if the strides are non-positive.

Thrown Exceptions

void objcopy(T* to, const T* from, uInt n)
void objcopy(T* to, const T* from, uInt n, uInt toStride, uInt fromStride)

/ inline void objmove(const void** to, const void*const *from, uInt n) / { memmove(to, from, n*sizeof(void*)); } / inline void objmove(const char** to, const char*const *from, uInt n) / { memmove(to, from, n*sizeof(char*)); }

/ inline void objmove(void** to, void*const *from, uInt n) / { memmove(to, from, n*sizeof(void*)); } / inline void objmove(char** to, char*const *from, uInt n) / { memmove(to, from, n*sizeof(char*)); }

The non-general 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.

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.

Thrown Exceptions

void objset(T* to, const T fillValue, uInt n)
void objset(T* to, const T fillValue, uInt n, uInt toStride)

/ inline void objcopy(const void** to, const void*const *from, uInt n) / { memcpy(to, from, n*sizeof(void*)); } / inline void objcopy(const char** to, const char*const *from, uInt n) / { memcpy(to, from, n*sizeof(char*)); }

/ inline void objcopy(void** to, void*const *from, uInt n) / { memcpy(to, from, n*sizeof(void*)); } / inline void objcopy(char** to, char*const *from, uInt n) / { memcpy(to, from, n*sizeof(char*)); }

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.

Thrown Exceptions