To verify a data type using a group code, use casting codes. In the following examples, the pRb variable stores a pointer to the resbuf-object.
The OdDxfCode class declares the Type enumerator that defines the symbolic notations for predefined data types to which a data value may be cast. This class has a single static _getType() method that requires a dxf-code or group code and returns the identifier of the predefined type to which the data value associated with the dxf-code or group code may be cast as a value of the OdDxfCode::Type enumerator. The Type enumerator defines the following:
Unknown = 0, // Unknown
Name = 1, // Name (string)
String = 2, // Arbitrary string
Bool = 3, // Boolean
Integer8 = 4, // 8-bit integer
Integer16 = 5, // 16-bit integer
Integer32 = 6, // 32-bit integer
Double = 7, // Double
Angle = 8, // Double
Point = 9, // 3D Point (OdGePoint3d)
BinaryChunk = 10, // Binary chunk (Array of bytes)
LayerName = 11, // Name (string)
Handle = 12, // Handle (OdDbHandle)
ObjectId = 13, // ID (OdDbObjectId)
SoftPointerId = 14, // Handle (OdDbHandle)
HardPointerId = 15, // Handle (OdDbHandle)
SoftOwnershipId = 16, // Handle (OdDbHandle)
HardOwnershipId = 17, // Handle (OdDbHandle)
Integer64 = 18, // 64-bit integer
To use casting codes, pass the group code to the _getType() method and compare the returned code with the allowable values using the switch-case statement. For example:
OdString WhatIsCodeType(OdResBuf* pRb)
{
OdString sInfo;
OdGePoint3d point;
OdInt16 type = pRb->restype();
switch( OdDxfCode::_getType(type) )
{
case OdDxfCode::Bool:
sInfo.format(L"%d,Bool = %s", type, ((pRb->getBool()) ? L"true" : L"false"));
break;
case OdDxfCode::Name:
case OdDxfCode::String:
case OdDxfCode::LayerName:
sInfo.format(L"%d,String = \"%s\"", type, pRb->getString().c_str());
break;
case OdDxfCode::Integer8:
sInfo.format(L"%d,Byte = %x", type, pRb->getInt8());
break;
case OdDxfCode::Integer16:
sInfo.format(L"%d,Short = %d", type, pRb->getInt16());
break;
case OdDxfCode::Integer32:
sInfo.format(L"%d,Long = %ld", type, pRb->getInt32());
break;
case OdDxfCode::Integer64:
sInfo.format(L"%d,Int = %ld", type, pRb->getInt64());
break;
case OdDxfCode::Angle:
case OdDxfCode::Double:
sInfo.format(L"%d,Double = %g", type, pRb->getDouble());
break;
case OdDxfCode::Point:
point = pRb->getPoint3d();
sInfo.format(L"%d,3DPoint = (%g,%g,%g)", type, point.x, point.y, point.z);
break;
case OdDxfCode::Handle:
case OdDxfCode::SoftPointerId:
case OdDxfCode::HardPointerId:
case OdDxfCode::SoftOwnershipId:
case OdDxfCode::HardOwnershipId:
sInfo.format(L"%d,Handle = %s", type, pRb->getHandle().ascii().c_str());
break;
default:
if(type == OdResBuf::kRtColor)
sInfo.format(L"%d,Color = %s", type, pRb->getColor().colorNameForDisplay().c_str());
else if(type == OdResBuf::kRtEntName)
sInfo.format(L"%d,ID = %s", type, pRb->getEntName().getHandle().ascii().c_str());
else
sInfo = L"Unknown";
}
return sInfo;
}
Getting and Setting Tagged Data
Example of Entering and Displaying Tagged Data
Copyright © 2002 – 2020. Open Design Alliance. All rights reserved.
|