CaseMatters.com
Solutions for IP Attorneys & Expert Witnesses

C++ Code Samples    CPlusCopy.cpp

Sample C++ source for code for CPlusCopy.cpp. Click here to download a copy of this file.

/*
*    CPlusCopy.cpp
* C++ Copy Routine
*    Copyright 2003, Good Guys, Inc. All rights reserved.
*/

#include

/*
*    copy - copy 'length' number of bytes from 'from' to 'to'
*
*    If the destination or length is zero, don't copy anything.
* Return the destination.
*/
void *copy(char *to, char *from, length_t length)
{
    char *p;

    if (to && length) {
        p = to;
        do {
            *p = *from;
            ++p;
            ++from;
            --length;
        } while (length);
    }

    return(to);
}

/*
*    constructObjects - set up array of objects
*
*    Call the constructor for each of 'numberOfObjects' in an array
* of objects that are 'sizeOfObjects' long.
*/
void *constructObjects(void *ptr, ConstructorDestructor constructor, length_t sizeOfObjects, length_t numberOfObjects)
{
    char *p;

    if ((p = (char *) ptr) != 0) {
        ((length_t *) p)[0] = sizeOfObjects;
        ((length_t *) p)[1] = numberOfObjects;
        p += 2 * sizeof(length_t);
        if (constructor) {
            for (; numberOfObjects--; p += sizeOfObjects)
                CTORCALL_COMPLETE(constructor, p);
        }
    }

    return(ptr);
}

Copyright 1999-, CaseMatters.com. All rights reserved. US Patents 8,433,708; 8,744,135; and patent pending.