Product Documentation

c-treeDB API for C++ - Developers Guide

Previous Topic

Next Topic

Adding New Resources

When adding a Resource to a table, a special variable-length record is written to the table, containing the information from the Resource Data Block. This is done even if a data file uses fixed-length records. Every Resource is identified by a unique combination of a Resource Type and a Resource Number. The Resource Number can optionally be assigned by c-tree Plus during the call to CTResource::Add() method. In addition, each Resource can be identified by a Resource Name. The Resource Name is not guaranteed to be unique.

The following steps are required to add a new resource to a table:

  1. Instantiate a CTResource object by calling one of the CTResource constructors. You should pass at least the resource type and number. The resource name is optional. If you use a CTResource constructor that does not take the resource type and number, you need to call CTResource::SetType() and CTResource::SetNumber() to set the resource type and number before you add a new resource.
  2. Call CTResource::Add() method to add the new resource passing the resource data and the length of the data.
  3. Once the CTResource object is no longer needed, destroy the object to release any system resources.

To add a new resource you must call the following CTResource class method:

void CTResource::Add(pVOID data, VRLEN size);

data is any collection of data that you wish to store as a Resource. This can be a character string, a structure, or any variable type. size indicate the number of bytes occupied by data parameter value.

The Resource Type must be a value greater than 65536. 0 through 65536 are reserved for FairCom use. If the Resource Number is a value of CTDB_ASSIGN_RESOURCE_NUMBER (0xffffffff), c-tree Plus assigns this Resource the next available Resource Number for this Resource Type in the specified data file. The assigned number can be retrieved by calling CTResource::GetNumber() method before the resource object is destroyed. The Resource Name is optional. c-tree Plus does not guarantee unique Resource Names. Names starting with the character sequence "FC!" or "RD!", are reserved for FairCom use.

Example

void AddMyResource(const CTTable& hTable, ULONG type, const CTString& name, pVOID data, VRLEN size)

{

CTResource* hRes = new CTResource(hTable, type, CTDB_ASSIGN_RESOURCE_NUMBER, name);

try

{

hRes->Add(data, size)

printf("Resource added with number %u\n", hRes->GetNumber());

}

catch (CTException &err)

{

printf("Error %d - %s\n", err.GetErrorCode(), err.GetErrorMsg());

}

delete hRes;

}

TOCIndex