Close

Relief for ODA Team in Ukraine

Learn more
ODA Drawings SDK
Getting and Setting Tagged Data

A group code defines the data type. A value defines the stored data. The group code either can be set by the newRb() pseudo-constructor of the resbuf-object when an instance is created or the setRestype() method of the resbuf-object when an instance exists. In the following examples, the pRb variable stores a pointer to the resbuf-object, and the pDb variable stores a pointer to the database object.

Getting the Group Code

To get the group code, use the restype() method that does not have arguments and returns an integer value. For example:


odPrintConsoleString(L"\nGroup code = %d", pRb->restype());

The OdResBuf class declares the ValueType enumerator that defines the symbolic notes for predefined group codes. All group codes are divided into ranges subject to the its related technology (XData, XRecord, DXF). A program can use these enumerators for checking the group code before getting and setting a data value. For example:


OdInt16 code = pRb->restype();

if(code == OdResBuf::kRtBool)
  odPrintConsoleString(L"\nCode: [%d,bool] = %s", code, ((pRb->getBool()) ? L"true" : L"false"));

if(code == OdResBuf::kRtString)
  pRb->setString(L"New Value");

Note: To check the data type, the program can use the static _getType() method of the OdDxfCode class that requires the group code and returns an identifier of the predefined type to which the data value can be cast as a value of the OdDxfCode::Type enumerator.

Setting the Group Code

To set the group code when a resbuf-instance exists, use the setRestype() method that requires an integer value as an argument and does not return a value. This method changes the existing data type and reinitializes the data value in the resbuf-instance. The setRestype() method can be used for modifying an existing resbuf-instance before setting data of another type. For example:


pRb->setRestype(OdResBuf::kDxfBool);
pRb->setDouble(true);

pRb->setRestype(OdResBuf::kDxfXTextString);
pRb->setString(L"User Data");

pRb->setRestype(OdResBuf::kDxfInt16);
pRb->setInt16(12600);

pRb->setRestype(OdResBuf::kDxfReal);
pRb->setDouble(1.2);

Note: The passed data value must correspond to the data type of the specified group code.

Setting the Group Code and Data Value through a Pseudo-Constructor

To set the tagged data when a new resbuf-instance is created, use a static pseudo-constructor that requires the group code as the first argument of an integer type and the data value as the second argument of a corresponding type. The pseudo-constructor creates a new instance of the resbuf-object, sets the specified group code, initializes the instance using the specified data value, and returns the smart pointer to the created resbuf-instance.

The newRb() method is the static pseudo-constructor that is overdriven and has an implementation for each supported data type. Therefore, the second argument does not require conversion of data or the corresponding type of data. The group code and data value can be passed directly when the constructor is called. The pseudo-constructor also implements the pure virtual methods inherited from the base class. The OdResBuf class has overdriven pseudo-constructors for the following data types: Boolean, double, ascii-string, wide-string, 8-bit integer, 16-bit integer, 32-bit integer, 64-bit integer, two-dimensional point, three-dimensional point, two-dimensional vector, three-dimensional vector, color, object ID, selection set, and nested resbuf-instances. For example:


OdResBufPtr pData;

pRb = OdResBuf::newRb(OdResBuf::kRtBool, true);
pData = pRb

pRb = OdResBuf::newRb(OdResBuf::kRtString, L"Attached Data");
pData->last()->setNext(pRb);

pRb = OdResBuf::newRb(OdResBuf::kRtInt8, (OdInt8) 15);
pData->last()->setNext(pRb);

pRb = OdResBuf::newRb(OdResBuf::kRtInt16, (OdInt16) 12600);
pData->last()->setNext(pRb);

pRb = OdResBuf::newRb(OdResBuf::kRtInt32, (OdInt32) 126347800);
pData->last()->setNext(pRb);

pRb = OdResBuf::newRb(OdResBuf::kDxfInt64, (OdInt64) 9073012068045000);
pData->last()->setNext(pRb);

pRb = OdResBuf::newRb(OdResBuf::kRtDouble, 34.567E12);
pData->last()->setNext(pRb);

pRb = OdResBuf::newRb(OdResBuf::kRtPoint2d, OdGePoint2d(5.2, 4.3));
pData->last()->setNext(pRb);

pRb = OdResBuf::newRb(OdResBuf::kRtPoint3d, OdGePoint3d(3.2, 1.3, 6.5));
pData->last()->setNext(pRb);

pRb = OdResBuf::newRb(OdResBuf::kRtVector2d, OdGeVector2d(0.2, 0.3));
pData->last()->setNext(pRb);

pRb = OdResBuf::newRb(OdResBuf::kRtVector3d, OdGeVector3d(0.2, 0.3, 0.5));
pData->last()->setNext(pRb);

pRb = OdResBuf::newRb(OdResBuf::kRtColor, OdCmColor(OdCmEntityColor::kByACI));
pData->last()->setNext(pRb);

pRb = OdResBuf::newRb(OdResBuf::kRtObjectId, pDb->getLayerZeroId());
pData->last()->setNext(pRb);

OdResBufPtr pNest = OdResBuf::newRb(OdResBuf::kRtString, OdString(L"Nested"));

pRb = OdResBuf::newRb(OdResBuf::kRtResBuf, pNest.get());
pData->last()->setNext(pRb);

Additionally, the pseudo-constructor has an implementation with one argument that requires only a group code as an integer value and initializes the created resbuf-instance by the default data value for the corresponding data type. The program must additionally set the data value after creation. For example:


pRb = OdResBuf::newRb(OdResBuf::kRtBool);
pRb->setBool(true);
pData->last()->setNext(pRb);

pRb = OdResBuf::newRb(OdResBuf::kDxfXdAsciiString);
pRb->setString(L"User Data");
pData->last()->setNext(pRb);

pRb = OdResBuf::newRb(OdResBuf::kDxfXdInteger16);
pRb->setInt16(12600);
pData->last()->setNext(pRb);

pRb = OdResBuf::newRb(OdResBuf::kDxfXdScale);
pRb->setDouble(1.2);
pData->last()->setNext(pRb);

pRb = OdResBuf::newRb(OdResBuf::kDxfXdXCoord);
pRb->setPoint3d(OdGePoint3d(3.2, 1.3, 6.5));
pData->last()->setNext(pRb);

The first argument of the pseudo-constructor is optional and gets the value kRtNone by default. The kRtNone group code indicates undefined data. In this case, the program must set the tagged data after creation. For example:


pRb = OdResBuf::newRb();
pRb->setRestype(OdResBuf::kRtAngle);
pRb->setDouble(1.57);
pData->last()->setNext(pRb);

pRb = OdResBuf::newRb();
pRb->setRestype(OdResBuf::kRtEntName);
pRb->setObjectId(pDb->getLayerZeroId());
pData->last()->setNext(pRb);

Note: The pseudo-constructor without arguments is useful when a program must first add the specified number of resbuf-instances and then initialize them.

See Also

Working with Tagged Data

Determining the Data Type by Group Code

Example of Entering and Displaying Tagged Data

Copyright © 2002 – 2022. Open Design Alliance. All rights reserved.