CTResource Class

class CTResource

Description

The CTResource class deals with c-tree resource concepts.

See also

CTBase

Preconditions

Resources must be defined, which is the default for FairCom DB API tables.

 

CTResource Methods

 

CTResource::CTResource

CTResource constructor.

Declaration

CTResource(const CTTable& hTable);
CTResource(const CTTable& hTable, ULONG type, ULONG number);
CTResource(const CTTable& hTable, ULONG type, ULONG number, const CTString& name);

Description

CTResource constructor. The first constructor instantiate a resource object with the resource type and number set to zero and the resource name set to NULL. Set second overloaded constructor instantiate a resource object with a resource type and number, but the resource name set to NULL. The last overloaded constructor instantiate a resource object setting the resource type, number and name.

Return

None

Example


void DisplayAllResources(const CTTable& hTable)
{
    CTResource* hRes  = new CTResource(hTable);

    try
    {
        // get the first resource
        if (hRes->First())
        {
            do
            {
                // display resource type, number and name
                printf("Resource type: %u, number: %u",
                    hRes->GetType(), hRes->GetNumber());
            }
            while (hRes->Next());
        }
    }
    catch (CTException &err)
    {
        printf("Error %d - %s\n", err.GetErrorCode(), err.GetErrorMsg());
    }
    delete hRes;
}
 

See Also

CTResource::Add(), CTResource::Delete(), CTResource::Update(), CTResource::First(), CTResource::Next(), CTResource::Find(), CTResource::GetType(), CTResource::SetType(), CTResource::GetNumber(), CTResource::SetNumber(), CTResource::GetName(), CTResource::SetName(), CTResource::GetDataLength(), CTResource::GetData(), CTResource::SetData(), CTResource::Unlock(), CTResource::IsLocked()

 

CTResource::Add

Add a new resource to a table.

Declaration

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

Description

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

Adds a new resource to a table. 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(). In addition, each Resource can be identified by a Resource Name. The Resource Name is not guaranteed to be unique.

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 ctdbGetResourceNumber before the resource handle is released. The Resource Name is optional. Names starting with "FC!" or "RD!", are reserved for FairCom use.

Return

None

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

See Also

CTResource::Delete(), CTResource::Update(), CTResource::First(), CTResource::Next(), CTResource::Find(), CTResource::GetType(), CTResource::SetType(), CTResource::GetNumber(), CTResource::SetNumber(), CTResource::GetName(), CTResource::SetName(), CTResource::GetDataLength(), CTResource::GetData(), CTResource::SetData(), CTResource::Unlock(), CTResource::IsLocked()

 

CTResource::Delete

Delete a resource.

Declaration

void CTResource::Delete();

Description

Deletes a resource from a table. Before a resource can be deleted, the table must be opened exclusive. The resource type and resource number that identify this resource must be passed to one of the CTResource constructors.

Return

None

Example


void DelMyResource(const CTTable& hTable, ULONG type, ULONG number)
{
    CTResource* hRes = new CTResource(hTable, type, number);
   
    try
    {
        hRes->Delete();
    }
    catch (CTException &err)
    {
        printf("Error %d - %s\n", err.GetErrorCode(), err.GetErrorMsg());
    }
    delete hRes;
}
 

See Also

CTResource::Add(), CTResource::Update(), CTResource::First(), CTResource::Next(), CTResource::Find(), CTResource::GetType(), CTResource::SetType(), CTResource::GetNumber(), CTResource::SetNumber(), CTResource::GetName(), CTResource::SetName(), CTResource::GetDataLength(), CTResource::GetData(), CTResource::SetData(), CTResource::Unlock(), CTResource::IsLocked()

 

CTResource::Find

Find a resource by type and number of by name.

Declaration

CTBOOL CTResource::Find(ULONG type, ULONG number, CTBOOL lock) const;
CTBOOL CTResource::Find(const CTString& name, CTBOOL lock) const;

Description

The first overloaded method locates and retrieves a resource in a table based on type and number. Parameters type and number are values that should uniquely identify the resource and lock is used to indicate if the resource should be locked, if it is found.

The second overloaded method locates and retrieves a resource by name. c-tree Plus cannot guarantee unique resource names. Parameter name is the resource name and lock is used to indicate if the resource should be locked, if it is found.

Return

CTResource::Find() return YES if the resource was located and retrieved or NO if the resource could not be found. In case of error, a CTException is thrown.

Example


// display a particular resource
void DisplayResource(const CTTable& hTable, ULONG type, ULONG number)
{
	CTResource* hRes = new CTResource(hTable);

	try
	{
		if (hRes->Find(type, number))
		{
			printf("Resource type: %u, number: %u, name: %s\n",
				hRes->GetType(), hRes->GetNumber(),
                           hRes->GetName().c_str());
		}
		else
			printf("Resource %d,%d not found\n", type, number);
	}
    catch (CTException &err)
    {
        printf("Error %d - %s\n", err.GetErrorCode(), err.GetErrorMsg());
    }
    delete hRes;
}
 

See Also

CTResource::Add(), CTResource::Delete(), CTResource::Update(), CTResource::First(), CTResource::Next(), CTResource::GetType(), CTResource::SetType(), CTResource::GetNumber(), CTResource::SetNumber(), CTResource::GetName(), CTResource::SetName(), CTResource::GetDataLength(), CTResource::GetData(), CTResource::SetData(), CTResource::Unlock(), CTResource::IsLocked()

 

CTResource::First

Retrieve the first resource stored in a table.

Declaration

CTBOOL CTResource::First(CTBOOL lock) const;

Description

Retrieves the first resource stored in a table. lock is used to indicate if the resource should be locked, if it is found.

Return

CTResource::First() returns YES if the first resource was retrieved or NO if first resource does not exist. In case of error, a CTException is thrown.

Example


void DisplayAllResources(const CTTable& hTable)
{
    CTResource* hRes  = new CTResource(hTable);

    try
    {
        // get the first resource
        if (hRes->First())
        {
            do
            {
                // display resource type, number and name
                printf("Resource type: %u, number: %u",
                    hRes->GetType(), hRes->GetNumber());
            }
            while (hRes->Next());
        }
    }
    catch (CTException &err)
    {
        printf("Error %d - %s\n", err.GetErrorCode(), err.GetErrorMsg());
    }
    delete hRes;
}
 

See Also

CTResource::Add(), CTResource::Delete(), CTResource::Update(), CTResource::Next(), CTResource::Find(), CTResource::GetType(), CTResource::SetType(), CTResource::GetNumber(), CTResource::SetNumber(), CTResource::GetName(), CTResource::SetName(), CTResource::GetDataLength(), CTResource::GetData(), CTResource::SetData(), CTResource::Unlock(), CTResource::IsLocked()

 

CTResource::GetData

Retrieve the resource data.

Declaration

pVOID CTResource::GetData() const;

Description

Retrieves the resource data

Return

Returns a pointer to the resource data.

Example


CTDBRET ReadMyResource(CTHANDLE Handle, ULONG type, ULONG number, pTEXT& data, VRLEN& size)
{
	CTResource* hRes = new CTResource(Handle, type, number, NULL);
 
	try
	{
		if (hRes->Find(type, number))
		{
			size = hRes->GetDataLength();
			if (size > 0)
			{
				data = new TEXT[size];
				memcpy(data, hRes->GetData(), size);
			}
		}
	}
	catch (CTException &err)
	{
		printf("Error %d - %s\n", err.GetErrorCode(), err.GetErrorMsg());
	}
	delete hRes;
}
 

See Also

CTResource::Add(), CTResource::Delete(), CTResource::Update(), CTResource::First(), CTResource::Next(), CTResource::Find(), CTResource::GetType(), CTResource::SetType(), CTResource::GetNumber(), CTResource::SetNumber(), CTResource::GetName(), CTResource::SetName(), CTResource::GetDataLength(), CTResource::SetData(), CTResource::Unlock(), CTResource::IsLocked()

 

CTResource::GetDataLength

Retrieve the resource data length.

Declaration

VRLEN CTResource::GetDataLength() const;

Description

Retrieves the resource data length in bytes.

Return

Returns the resource data length.

Example


CTDBRET ReadMyResource(CTHANDLE Handle, ULONG type, ULONG number, pTEXT& data, VRLEN& size)
{
	CTResource* hRes = new CTResource(Handle, type, number, NULL);
 
	try
	{
		if (hRes->Find(type, number))
		{
			size = hRes->GetDataLength();
			if (size > 0)
			{
				data = new TEXT[size];
				memcpy(data, hRes->GetData(), size);
			}
		}
	}
	catch (CTException &err)
	{
		printf("Error %d - %s\n", err.GetErrorCode(), err.GetErrorMsg());
	}
	delete hRes;
}
 

See Also

CTResource::Add(), CTResource::Delete(), CTResource::Update(), CTResource::First(), CTResource::Next(), CTResource::Find(), CTResource::GetType(), CTResource::SetType(), CTResource::GetNumber(), CTResource::SetNumber(), CTResource::GetName(), CTResource::SetName(), CTResource::GetData(), CTResource::SetData(), CTResource::Unlock(), CTResource::IsLocked()

 

CTResource::GetName

Retrieve the resource name.

Declaration

CTString CTResource::GetName() const;

Description

Retrieves the resource name.

Return

Returns the resource name.

Example


if (hRes->GetName() != "MyResource")
    hRes->SetName("MyResource");
 

See Also

CTResource::Add(), CTResource::Delete(), CTResource::Update(), CTResource::First(), CTResource::Next(), CTResource::Find(), CTResource::GetType(), CTResource::SetType(), CTResource::GetNumber(), CTResource::SetNumber(), CTResource::SetName(), CTResource::GetDataLength(), CTResource::GetData(), CTResource::SetData(), CTResource::Unlock(), CTResource::IsLocked()

 

CTResource::GetNumber

Retrieve the resource number.

Declaration

ULONG CTResource::GetNumber() const;

Description

Retrieves the resource number.

Return

Returns the resource number.

Example


if (hRes->GetNumber() != number)
    hRes->SetNumber(number);
 

See Also

CTResource::Add(), CTResource::Delete(), CTResource::Update(), CTResource::First(), CTResource::Next(), CTResource::Find(), CTResource::GetType(), CTResource::SetType(), CTResource::SetNumber(), CTResource::GetName(), CTResource::SetName(), CTResource::GetDataLength(), CTResource::GetData(), CTResource::SetData(), CTResource::Unlock(), CTResource::IsLocked()

 

CTResource::GetType

Retrieve the resource type.

Declaration

LONG CTResource::GetType() const;

Description

Retrieves the resource type.

Return

Returns the resource type.

Example


if (hRes->GetType() != type)
    hRes->SetType(type);
 

See Also

CTResource::Add(), CTResource::Delete(), CTResource::Update(), CTResource::First(), CTResource::Next(), CTResource::Find(), CTResource::SetType(), CTResource::GetNumber(), CTResource::SetNumber(), CTResource::GetName(), CTResource::SetName(), CTResource::GetDataLength(), CTResource::GetData(), CTResource::SetData(), CTResource::Unlock(), CTResource::IsLocked()

 

CTResource::IsLocked

Check if resource is locked.

Declaration

CTBOOL CTResource::IsLocked() const;

Description

Check if a resource is locked.

Return

Returns YES is a resource is locked or NO is a resource is not locked.

Example


if (hRes->IsLocked())
    hRes->Unlock();
 

See Also

CTResource::Add(), CTResource::Delete(), CTResource::Update(), CTResource::First(), CTResource::Next(), CTResource::Find(), CTResource::GetType(), CTResource::SetType(), CTResource::GetNumber(), CTResource::SetNumber(), CTResource::GetName(), CTResource::SetName(), CTResource::GetDataLength(), CTResource::GetData(), CTResource::SetData(), CTResource::Unlock()

 

CTResource::Next

Retrieve the next resource stored in a table.

Declaration

CTBOOL CTResource::Next(CTBOOL lock) const;

Description

Retrieves the next resource stored in a table. lock is used to indicate if the resource should be locked, if it is found.

Return

CTResource::Next() returns YES if the first resource was retrieved or NO if first resource does not exist. In case of error, a CTException is thrown.

Example


// read resources with type >= type and number > 0
void DisplayResources(const CTTable& hTable, ULONG type)
{
	CTResource* hRes = new CTResource(hTable, type, 0);

	try
	{
		while (hRes->Next())
		{
			printf("Resource type: %u, number: %u",
				hRes->GetType(), hRes->GetNumber());
		}
	}
    catch (CTException &err)
    {
        printf("Error %d - %s\n", err.GetErrorCode(), err.GetErrorMsg());
    }
    delete hRes;
}
 

See Also

CTResource::Add(), CTResource::Delete(), CTResource::Update(), CTResource::First(), CTResource::Find(), CTResource::GetType(), CTResource::SetType(), CTResource::GetNumber(), CTResource::SetNumber(), CTResource::GetName(), CTResource::SetName(), CTResource::GetDataLength(), CTResource::GetData(), CTResource::SetData(), CTResource::Unlock(), CTResource::IsLocked()

 

CTResource::SetData

Set the resource data.

Declaration

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

Description

Sets the resource data.

Return

None

Example


CTDBRET ReadMyResource(CTHANDLE Handle, ULONG type, ULONG number, pTEXT& data, VRLEN& size)
{
	CTResource* hRes = new CTResource(Handle, type, number, NULL);
 
	try
	{
		if (hRes->Find(type, number))
		{
			size = hRes->GetDataLength();
			if (size > 0)
			{
				data = new TEXT[size];
				memcpy(data, hRes->GetData(), size);
			}
		}
	}
	catch (CTException &err)
	{
		printf("Error %d - %s\n", err.GetErrorCode(), err.GetErrorMsg());
	}
	delete hRes;
}
 

See Also

CTResource::Add(), CTResource::Delete(), CTResource::Update(), CTResource::First(), CTResource::Next(), CTResource::Find(), CTResource::GetType(), CTResource::SetType(), CTResource::GetNumber(), CTResource::SetNumber(), CTResource::GetName(), CTResource::SetName(), CTResource::GetDataLength(), CTResource::GetData(), CTResource::Unlock(), CTResource::IsLocked()

 

CTResource::SetName

Declaration

void CTResource::SetName(const CTString& name);

Description

Sets the resource name.

Return

None.

Example


if (hRes->GetName() != "MyResource")
    hRes->SetName("MyResource");
 

See Also

CTResource::Add(), CTResource::Delete(), CTResource::Update(), CTResource::First(), CTResource::Next(), CTResource::Find(), CTResource::GetType(), CTResource::SetType(), CTResource::GetNumber(), CTResource::SetNumber(), CTResource::GetName(), CTResource::GetDataLength(), CTResource::GetData(), CTResource::SetData(), CTResource::Unlock(), CTResource::IsLocked()

 

CTResource::SetNumber

Set the resource number.

Declaration

void CTResource::SetNumber(ULONG number);

Description

Sets the resource number.

Return

None.

Example


if (hRes->GetNumber() != number)
    hRes->SetNumber(number);
 

See Also

CTResource::Add(), CTResource::Delete(), CTResource::Update(), CTResource::First(), CTResource::Next(), CTResource::Find(), CTResource::GetType(), CTResource::SetType(), CTResource::GetNumber(), CTResource::GetName(), CTResource::SetName(), CTResource::GetDataLength(), CTResource::GetData(), CTResource::SetData(), CTResource::Unlock(), CTResource::IsLocked()

 

CTResource::SetType

Set the resource type.

Declaration

void CTResource::SetType(ULONG type);

Description

Sets the resource type.

Return

None

Example


if (hRes->GetType() != type)
    hRes->SetType(type);
 

See Also

CTResource::Add(), CTResource::Delete(), CTResource::Update(), CTResource::First(), CTResource::Next(), CTResource::Find(), CTResource::GetType(), CTResource::GetNumber(), CTResource::SetNumber(), CTResource::GetName(), CTResource::SetName(), CTResource::GetDataLength(), CTResource::GetData(), CTResource::SetData(), CTResource::Unlock(), CTResource::IsLocked()

 

CTResource::Unlock

Unlock a resource..

Declaration

void CTResource::Unlock();

Description

Unlocks a resource. The resource is only unlocked if it was previously locked by First(), Next() or Find().

Return

None

Example


if (hRes->IsLocked())
    hRes->Unlock();
 

See Also

CTResource::Add(), CTResource::Delete(), CTResource::Update(), CTResource::First(), CTResource::Next(), CTResource::Find(), CTResource::GetType(), CTResource::SetType(), CTResource::GetNumber(), CTResource::SetNumber(), CTResource::GetName(), CTResource::SetName(), CTResource::GetDataLength(), CTResource::GetData(), CTResource::SetData(), CTResource::Unlock(), CTResource::IsLocked(), Locking

 

CTResource::Update

Update an existing resource.

Declaration

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

Description

Updates an existing resource. You must instantiate the resource object with the specific resource type and number that will uniquely identify the resource being updated. The resource data is any collection of data that you wish to store as a Resource. It can be a character string, a structure, or any variable type. size indicates the number of bytes occupied by data.

Return

None

Example


void UpdateMyResource(const CTTable& hTable, ULONG type, ULONG number, pVOID data, VRLEN size)
{
    CTResource* hRes = new CTResource(hTable, type, number);
   
    try
    {
        hRes->Update(data, size);
    }
    catch (CTException &err)
    {
        printf("Error %d - %s\n", err.GetErrorCode(), err.GetErrorMsg());
    }
    delete hRes;
}
 

See Also

CTResource::Add(), CTResource::Delete(), CTResource::First(), CTResource::Next(), CTResource::Find(), CTResource::GetType(), CTResource::SetType(), CTResource::GetNumber(), CTResource::SetNumber(), CTResource::GetName(), CTResource::SetName(), CTResource::GetDataLength(), CTResource::GetData(), CTResource::SetData(), CTResource::Unlock(), CTResource::IsLocked()