This example demonstrates working with tagged data implemented using a resbuf-instance for displaying and modifying its group code, data type, and data value. This example implements two functions: AboutRbData() — Displays the properties of the resbuf-instance, and EntryRbData() — Enters the group code and data value for the resbuf-instance.
The example uses the OdDxfCode object for verifying the data type to which the data value can be converted. This object has the _getType() static method that requires the code of the data type as an argument and returns the integer number which defines the actual type of the stored data value corresponding to the data type as a value of OdDxfCode::Type enumerator. The example uses the following header file:
#include "OdaCommon.h"
#include "OdToolKit.h"
#include "DbFiler.h"
#include "Ge\GePoint3d.h"
#include <iostream>
using namespace std;
The AboutRbData() function displays information about the group code, data type, and data value of the passed resbuf-instance. The function requires a pointer to an existing resbuf-instance as the first argument of the OdResBuf type, the sign which defines whether the information is whole (True) or short (False) as the second argument of a Boolean type, and returns information about the specified resbuf-instance as a value of the OdString type. The function gets the group code using the restype() method, checks its data type using the _getType() method, and uses the switch statement to select the variant of the information string and conversion of the data value. The function does the following depending on the data type:
The function concatenates the information string, the obtained code, and converted data value in the resulting string. If the data type is undefined, the function returns a "[None]" string.
The AboutRbData() function has the following implementation:
OdString AboutRbData(OdResBuf* pRb, bool isWhole)
{
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:
sInfo.format(L"[%d,Name] = \"%s\"", type, pRb->getString().c_str());
break;
case OdDxfCode::String:
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:
sInfo = L"[None]";
}
return sInfo;
}
The EntryRbData() function selects a group code and sets a data value for the specified resbuf-instance. The function requires a pointer to an existing resbuf-instance as an argument of the OdResBuf type, a sign which defines whether the function enters a group code and data value (True) or only a data value (False) as the second argument of a Boolean type, and returns True when the resbuf-instance is changed or False when the user cancels entry. The function organizes the loop for selecting a group code and entering a data value. If an entered group code or data value is incorrect or inadmissible, the function displays an error message and repeats the request for entry. If the entered group code and data value are correct, the function sets the group code using the setRestype() method, sets the data value using the corresponding method, and returns True. If the entered code is zero or if the user cancels entry, the function returns False for the current group code and data value for the specified resbuf-instance.
The function does the following for various data types:
The EntryRbData() function has the following implementation:
bool EntryRbData(OdResBuf* pRb, bool isWhole)
{
wchar_t buffer[64],ch;
OdInt16 codetype;
bool flag;
double value;
OdInt16 int16;
OdInt32 int32;
OdUInt64 int64;
OdGePoint3d point;
do {
if(isWhole)
{
wcout << L"\nEntry group code [or 0-Quit]:>";
wcin >> codetype;
if(wcin.fail() || wcin.peek() != 10)
{
wcin.sync();
wcin.clear();
wcout << L"Error: Incorrect entered code";
continue;
}
if(codetype == 0) return false;
}
else codetype = pRb->restype();
switch( OdDxfCode::_getType(codetype) )
{
case OdDxfCode::Name:
wcout << L"Name:>";
goto buffer_entry;
case OdDxfCode::String:
wcout << L"String:>";
buffer_entry:
wcin.sync();
wcin.getline(buffer, 64, 10);
pRb->setRestype(codetype);
pRb->setString(buffer);
return true;
case OdDxfCode::Bool:
wcout << L"Entry [T]-true or [F]-false:>";
wcin >> ch;
if(ch == L'T' || ch == 't') flag = true;
else if(ch == L'F' || ch == 'f') flag = false;
else break;
pRb->setRestype(codetype);
pRb->setBool(flag);
return true;
case OdDxfCode::Handle:
wcout << L"Handle:>";
wcin >> hex >> int64 >> dec;
if(!wcin.fail() && wcin.peek() == 10)
{
pRb->setRestype(codetype);
pRb->setHandle(int64);
return true;
}
break;
case OdDxfCode::Integer32:
wcout << L"32-bit integer value:>";
wcin >> int32;
if(!wcin.fail() && wcin.peek() == 10)
{
pRb->setRestype(codetype);
pRb->setInt32(int32);
return true;
}
break;
case OdDxfCode::Integer16:
wcout << L"16-bit integer value:>";
wcin >> int16;
if(!wcin.fail() && wcin.peek() == 10)
{
pRb->setRestype(codetype);
pRb->setInt16(int16);
return true;
}
break;
case OdDxfCode::Integer8:
wcout << L"8-bit integer value:>";
wcin >> int16;
if(!wcin.fail() && wcin.peek() == 10)
{
pRb->setRestype(codetype);
pRb->setInt8((OdInt8) int16);
return true;
}
break;
case OdDxfCode::Angle:
wcout << L"Angle value:>";
goto real_entry;
case OdDxfCode::Double:
wcout << L"Double value:>";
real_entry:
wcin >> value;
if(!wcin.fail() && wcin.peek() == 10)
{
pRb->setRestype(codetype);
pRb->setDouble(value);
return true;
}
break;
case OdDxfCode::Point:
wcout << L"Entry X-coordinate:>";
wcin >> point.x;
if(!wcin.fail() && wcin.peek() == 10)
{
wcout << L"Entry Y-coordinate:>";
wcin >> point.y;
if(!wcin.fail() && wcin.peek() == 10)
{
wcout << L"Entry Z-coordinate:>";
wcin >> point.z;
if(!wcin.fail() && wcin.peek() == 10)
{
pRb->setRestype(codetype);
pRb->setPoint3d(point);
return true;
}
}
}
break;
default:
wcout << L"Error: Unknown code";
continue;
}
wcin.sync();
wcin.clear();
wcout << L"Error: Invalid entered value\n";
}
while(1);
}
The IsRbMarker() function checks whether a group code of the specified resbuf-instance is the specific marker. The function requires a pointer to an existing resbuf-instance as the first argument of the OdResBuf type and returns True when the group code is a marker or False when the group code is not.
The IsRbMarker() function has the following implementation:
bool IsRbMarker(OdResBuf* pRb)
{
switch( pRb->restype() )
{
case OdResBuf::kDxfEnd:
case OdResBuf::kDxfStart:
case OdResBuf::kDxfXDataStart:
case OdResBuf::kDxfXDictionary:
return true;
}
return false;
}
Example of Working with the Sequence of Tagged Data
Copyright © 2002 – 2020. Open Design Alliance. All rights reserved.
|