Defining CPad content
The first step in setting up a C++ program to use a CPad is to identify the types of data that the CPad is to store. If you plan to have several different types of data in the CPad, consider creating a structure type to define the content. The CPad examples shown here use a structure type called Root.
Each CPad provides access to a portion of memory that can be thought of as the root of a tree. The objects stored in the CPad can be reached only from the root object. In a root object, you can store a single object (such as int, double), an array (such as char*, int*), or a structure.
#include "udxinc.h"
#include <string.h>
using namespace nz::udx_ver2;
struct Root
{
char* data;
int size;
};
struct MyValue
{
char* name;
int value;
};
struct MyLookup
{
MyValue *values;
int numallocated;
int numused;
};
In this example, the root object is an instance of MyLookup, which can contain an arbitrary number of MyValue objects. All of the objects, plus the char* strings, are allocated through the CPad allocation mechanisms, but the only way to get to a value (or the name in a value) is through the MyLookup root object.
If several C++ files define UDXs that share the same CPad, make sure that you repeat your Root structure definition in each C++ file. If you define a number of common structures or definitions, you can create a single include file to define those objects in one location.