To create a new resbuf-instance, declare a variable of the OdResBufPtr type and use the newRb() method which is the pseudo-constructor of the resbuf-object. This pseudo-constructor is the static method that creates a new dynamic instance and returns a smart pointer to it. For example:
OdResBufPtr pRb = OdResBuf::newRb();
The created instance gets the kRtNone data type by default. The data value is undefined. The stored smart pointer is NULL by default. To set the data type, use the setRestype() method. To set the data value, use the specific methods of the OdResBuf class for the corresponding data type.
Instances of the resbuf-object must be connected in a dynamically linked sequence, to be applied according to its corresponding technology (XData, XRecord, DXF) when a program works with the database. The last instance in the sequence must be NULL, which signifies the end. To create a dynamically linked sequence of resbuf-instances, declare a variable of the OdResBufPtr type and save the smart pointer of the first instance in it. This variable is the head of the dynamically linked sequence and the program must not change it.
Each resbuf-instance stores a smart pointer to the next resbuf-instance in the sequence. To get the next instance, use the next() method which does not have arguments and returns a smart pointer to the next linked instance in the sequence. To get the last instance, use the last() method which does not have arguments and returns a smart pointer to the last instance in the sequence. To set the smart pointer of the current instance, use the setNext() method which requires the pointer to the instance that is next in the sequence.
To build the sequence by adding to the end, create a new instance using the pseudo-constructor of the resbuf-object, initialize the instance, move to the end of the sequence using the last() method for the head instance, and set the smart pointer of the last instance to the new instance using the setNext() method. Repeat these actions for each new tagged data added in the sequence. For example:
OdResBufPtr pData = OdResBuf::newRb(); // first
pRb = OdResBuf::newRb(); // second
pData->last()->setNext(pRb);
pRb = OdResBuf::newRb(); // third
pData->last()->setNext(pRb);
To build the sequence by adding the next instance, create a new instance using the pseudo-constructor of the resbuf-object, initialize the instance, set the smart pointer of the current instance to the new instance using the setNext() method, and move to the next instance using the next() method. Repeat these actions for each new tagged data added in the sequence. For example:
OdResBufPtr pData = OdResBuf::newRb(); // first
pRb = pData;
pRb->setNext(OdResBuf::newRb()); // second
pRb = pRb->next();
pRb->setNext(OdResBuf::newRb()); // third
pRb = pRb->next();
To build the sequence by adding to the beginning, create a new instance using the pseudo-constructor of the resbuf-object, initialize the instance, set the smart pointer of the new instance to the head instance using the setNext() method, and set the new instance as the head instance. Repeat these actions for each new tagged data added in the sequence. The sequence is built in reverse order. For example:
OdResBufPtr pData = OdResBuf::newRb(); // last
pRb = OdResBuf::newRb(); // ...
pRb->setNext(pData);
pData = pRb;
pRb = OdResBuf::newRb(); // first
pRb->setNext(pData);
pData = pRb;
To insert a new instance in an existing sequence, use the insert() method which requires the pointer to the instance to be inserted in the sequence as an argument and inserts it before the next instance after the current instance that calls this method. The insert() method sets the smart pointer of the new instance to the next instance after the current instance that calls this method and sets the smart pointer of the current instance to the new instance which is inserted. For example:
OdResBufPtr pData = OdResBuf::newRb(); // first
pData->last()->setNext(OdResBuf::newRb()); // ...
pData->last()->setNext(OdResBuf::newRb()); // last
pRb = OdResBuf::newRb(); // second
pData->insert(pRb);
pRb->insert(OdResBuf::newRb()); // third
To print an existing sequence, declare a variable of the OdResBuf type that is used as an iterator of the loop, initialize this variable to the beginning of the sequence, move to the next instance of the sequence using the next() method until the variable is set to NULL. For example:
OdResBufPtr pRb = pData;
while(!pRb.isNull())
{
odPrintConsoleString(L"%d, ", pRb->restype());
pRb = pRb->next();
}
An existing instance is deleted automatically when its reference counter becomes zero. The release() method destroys the instance when the last smart pointer loses the address to this instance.
Determining the Data Type by Group Code
Example of Working with the Sequence of Tagged Data
Copyright © 2002 – 2020. Open Design Alliance. All rights reserved.
|