414 lines
10 KiB
C++
414 lines
10 KiB
C++
|
|
/*
|
||
|
|
** CPQDIF_R_General class. The base class for a PQDIF record.
|
||
|
|
** --------------------------------------------------------------------------
|
||
|
|
**
|
||
|
|
** File name: $Workfile: rec_general.cpp $
|
||
|
|
** Last modified: $Modtime: 11/14/00 8:41a $
|
||
|
|
** Last modified by: $Author: Bill $
|
||
|
|
**
|
||
|
|
** VCS archive path: $Archive: /Hank/DMM/FirmWare/Level3/ObDatMgr/rec_general.cpp $
|
||
|
|
** VCS revision: $Revision: 11 $
|
||
|
|
*/
|
||
|
|
#include "PQDIF_classes.h"
|
||
|
|
|
||
|
|
|
||
|
|
|
||
|
|
// Construction
|
||
|
|
// ============
|
||
|
|
|
||
|
|
CPQDIF_R_General::CPQDIF_R_General()
|
||
|
|
{
|
||
|
|
// Init header structure
|
||
|
|
memset( &m_headerRecord, 0, sizeof( m_headerRecord ) );
|
||
|
|
m_headerRecord.guidRecordSignature = guidRecordSignaturePQDIF;
|
||
|
|
m_headerRecord.tagRecordType = tagBlank;
|
||
|
|
m_headerRecord.sizeHeader = sizeof( m_headerRecord );
|
||
|
|
// sizeData;
|
||
|
|
// linkNextRecord;
|
||
|
|
// checksum;
|
||
|
|
// auiReserved[ 4 ];
|
||
|
|
|
||
|
|
m_posThisRecord = 0;
|
||
|
|
m_pcollMain = NULL; // Body not read
|
||
|
|
|
||
|
|
m_changed = false;
|
||
|
|
}
|
||
|
|
|
||
|
|
|
||
|
|
CPQDIF_R_General::~CPQDIF_R_General()
|
||
|
|
{
|
||
|
|
if( m_pcollMain )
|
||
|
|
delete m_pcollMain;
|
||
|
|
}
|
||
|
|
|
||
|
|
|
||
|
|
bool CPQDIF_R_General::ReadHeader( CPQDIF_StreamIO * pstream )
|
||
|
|
{
|
||
|
|
bool status = false;
|
||
|
|
BYTE * buffer = NULL;
|
||
|
|
int sizeActual;
|
||
|
|
int pos;
|
||
|
|
|
||
|
|
// Init header structure
|
||
|
|
memset( &m_headerRecord, 0, sizeof( m_headerRecord ) );
|
||
|
|
|
||
|
|
status = pstream->GetPos( pos );
|
||
|
|
if( status )
|
||
|
|
{
|
||
|
|
m_posThisRecord = (LINKABS4) pos;
|
||
|
|
buffer = pstream->ReadBlock( sizeof( m_headerRecord ), sizeActual );
|
||
|
|
//ASSERT( sizeActual == sizeof( m_headerRecord ) );
|
||
|
|
}
|
||
|
|
|
||
|
|
if( status && buffer)
|
||
|
|
{
|
||
|
|
m_headerRecord = *( (c_record_mainheader *) buffer );
|
||
|
|
|
||
|
|
// Validate the signature
|
||
|
|
if( !PQDIF_IsEqualGUID( m_headerRecord.guidRecordSignature, guidRecordSignaturePQDIF ) )
|
||
|
|
{
|
||
|
|
status = FALSE;
|
||
|
|
}
|
||
|
|
}
|
||
|
|
return status;
|
||
|
|
}
|
||
|
|
|
||
|
|
|
||
|
|
bool CPQDIF_R_General::ReadBody( CPQDIF_StreamIO * pstream )
|
||
|
|
{
|
||
|
|
bool status = false;
|
||
|
|
PQController controller;
|
||
|
|
|
||
|
|
// Have we already read it?
|
||
|
|
if( m_pcollMain )
|
||
|
|
{
|
||
|
|
status = true;
|
||
|
|
}
|
||
|
|
else
|
||
|
|
{
|
||
|
|
// Nope -- create the top-level collection
|
||
|
|
m_pcollMain = (CPQDIF_E_Collection *) theFactory.NewElement( ID_ELEMENT_TYPE_COLLECTION );
|
||
|
|
//ASSERT( m_pcollMain );
|
||
|
|
if( m_pcollMain )
|
||
|
|
{
|
||
|
|
// Link the collection to the record.
|
||
|
|
m_pcollMain->SetRecord( this );
|
||
|
|
|
||
|
|
// Attach the record tag to the main collection
|
||
|
|
m_pcollMain->SetTag( m_headerRecord.tagRecordType );
|
||
|
|
|
||
|
|
// Position us to the right place
|
||
|
|
status = pstream->SeekPos( m_posThisRecord + m_headerRecord.sizeHeader );
|
||
|
|
if( status )
|
||
|
|
{
|
||
|
|
int sizeActual;
|
||
|
|
BYTE * buffer;
|
||
|
|
|
||
|
|
buffer = pstream->ReadBlock( m_headerRecord.sizeData, sizeActual );
|
||
|
|
if( buffer && sizeActual > 0 )
|
||
|
|
{
|
||
|
|
// Do it!
|
||
|
|
controller.ParseRecord( buffer, sizeActual, m_pcollMain );
|
||
|
|
status = TRUE;
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
return status;
|
||
|
|
}
|
||
|
|
|
||
|
|
|
||
|
|
bool CPQDIF_R_General::WriteHeader( CPQDIF_StreamIO * pstream )
|
||
|
|
{
|
||
|
|
bool status = FALSE;
|
||
|
|
SIZE4 sizeActual;
|
||
|
|
|
||
|
|
// Just write the dern block out!
|
||
|
|
// Position us to the right place
|
||
|
|
status = pstream->SeekPos( m_posThisRecord );
|
||
|
|
status = pstream->BeginBlock();
|
||
|
|
if( status )
|
||
|
|
{
|
||
|
|
status = pstream->AppendBlock(
|
||
|
|
(BYTE *) &m_headerRecord,
|
||
|
|
sizeof( m_headerRecord ) );
|
||
|
|
status = pstream->WriteBlock( sizeActual );
|
||
|
|
}
|
||
|
|
|
||
|
|
return status;
|
||
|
|
}
|
||
|
|
|
||
|
|
|
||
|
|
bool CPQDIF_R_General::WriteBody( CPQDIF_StreamIO * pstream )
|
||
|
|
{
|
||
|
|
bool status = FALSE;
|
||
|
|
PQAlloc allocPQ;
|
||
|
|
long sizeTotal;
|
||
|
|
c_collection_element * aem;
|
||
|
|
|
||
|
|
// Use the allocPQ to write out the main collection
|
||
|
|
if( m_pcollMain )
|
||
|
|
{
|
||
|
|
long idx;
|
||
|
|
SIZE4 size;
|
||
|
|
|
||
|
|
// Prepare
|
||
|
|
pstream->ResetChecksum();
|
||
|
|
|
||
|
|
// Position us to the right place
|
||
|
|
status = pstream->SeekPos( m_posThisRecord + m_headerRecord.sizeHeader );
|
||
|
|
|
||
|
|
aem = allocPQ.addCollection( m_pcollMain->GetCount(), idx, size );
|
||
|
|
if( aem )
|
||
|
|
{
|
||
|
|
status = BufferUpCollection( pstream, allocPQ, m_pcollMain, aem );
|
||
|
|
if( status )
|
||
|
|
{
|
||
|
|
sizeTotal = allocPQ.WriteListToStream( pstream );
|
||
|
|
if( sizeTotal == 0 )
|
||
|
|
status = false;
|
||
|
|
else
|
||
|
|
{
|
||
|
|
// Update header with data
|
||
|
|
m_headerRecord.sizeData = sizeTotal;
|
||
|
|
m_headerRecord.linkNextRecord = m_posThisRecord + m_headerRecord.sizeHeader + m_headerRecord.sizeData;
|
||
|
|
m_headerRecord.checksum = pstream->GetChecksum();
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
return status;
|
||
|
|
}
|
||
|
|
|
||
|
|
|
||
|
|
bool CPQDIF_R_General::BufferUpCollection
|
||
|
|
(
|
||
|
|
CPQDIF_StreamIO * pstream,
|
||
|
|
PQAlloc& allocPQ,
|
||
|
|
CPQDIF_E_Collection * pcoll,
|
||
|
|
c_collection_element * aem
|
||
|
|
)
|
||
|
|
{
|
||
|
|
bool status = TRUE;
|
||
|
|
long idxElement;
|
||
|
|
long countElements = pcoll->GetCount();
|
||
|
|
CPQDIF_Element * pel;
|
||
|
|
|
||
|
|
c_collection_element * aemNew;
|
||
|
|
long typePhysical;
|
||
|
|
PQDIFValue value;
|
||
|
|
|
||
|
|
long idx;
|
||
|
|
SIZE4 size;
|
||
|
|
|
||
|
|
for( idxElement = 0; idxElement < countElements; idxElement++ )
|
||
|
|
{
|
||
|
|
pel = pcoll->GetElement( idxElement );
|
||
|
|
if( pel )
|
||
|
|
{
|
||
|
|
switch( pel->GetElementType() )
|
||
|
|
{
|
||
|
|
case ID_ELEMENT_TYPE_COLLECTION:
|
||
|
|
{
|
||
|
|
CPQDIF_E_Collection * pcollNext = (CPQDIF_E_Collection *) pel;
|
||
|
|
|
||
|
|
aemNew = allocPQ.addCollection(
|
||
|
|
pcollNext->GetCount(),
|
||
|
|
idx, size,
|
||
|
|
pel->GetTag(),
|
||
|
|
aem[ idxElement ] );
|
||
|
|
if( aemNew )
|
||
|
|
{
|
||
|
|
status = BufferUpCollection(
|
||
|
|
pstream,
|
||
|
|
allocPQ,
|
||
|
|
pcollNext,
|
||
|
|
aemNew );
|
||
|
|
}
|
||
|
|
}
|
||
|
|
break;
|
||
|
|
|
||
|
|
case ID_ELEMENT_TYPE_SCALAR :
|
||
|
|
{
|
||
|
|
CPQDIF_E_Scalar * pscalar = (CPQDIF_E_Scalar *) pel;
|
||
|
|
|
||
|
|
pscalar->GetValue( typePhysical, value );
|
||
|
|
status = allocPQ.addScalarValue(
|
||
|
|
typePhysical,
|
||
|
|
value,
|
||
|
|
idx, size,
|
||
|
|
pscalar->GetTag(),
|
||
|
|
aem[ idxElement ] );
|
||
|
|
}
|
||
|
|
break;
|
||
|
|
|
||
|
|
case ID_ELEMENT_TYPE_VECTOR :
|
||
|
|
{
|
||
|
|
CPQDIF_E_Vector * pvector = (CPQDIF_E_Vector *) pel;
|
||
|
|
long count;
|
||
|
|
|
||
|
|
pvector->GetCount( count );
|
||
|
|
typePhysical = pvector->GetPhysicalType();
|
||
|
|
|
||
|
|
status = allocPQ.addVectorValue(
|
||
|
|
typePhysical,
|
||
|
|
count,
|
||
|
|
pvector->GetRawData(),
|
||
|
|
idx, size,
|
||
|
|
pvector->GetTag(),
|
||
|
|
aem[ idxElement ] );
|
||
|
|
}
|
||
|
|
break;
|
||
|
|
|
||
|
|
default:
|
||
|
|
break;
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
return status;
|
||
|
|
}
|
||
|
|
|
||
|
|
|
||
|
|
bool CPQDIF_R_General::SetMainCollection( CPQDIF_E_Collection * collMain )
|
||
|
|
{
|
||
|
|
bool status = true;
|
||
|
|
|
||
|
|
// Clear out old collection?
|
||
|
|
if( m_pcollMain )
|
||
|
|
{
|
||
|
|
delete m_pcollMain;
|
||
|
|
m_pcollMain = NULL;
|
||
|
|
}
|
||
|
|
|
||
|
|
if( collMain )
|
||
|
|
{
|
||
|
|
m_pcollMain = collMain;
|
||
|
|
collMain->SetRecord( this );
|
||
|
|
}
|
||
|
|
|
||
|
|
return status;
|
||
|
|
}
|
||
|
|
|
||
|
|
|
||
|
|
bool CPQDIF_R_General::GetTimeInMainCollection (const GUID &tag, TIMESTAMPPQDIF& timeTime)
|
||
|
|
{
|
||
|
|
// Initialize
|
||
|
|
bool foundItem = false;
|
||
|
|
|
||
|
|
memset( &timeTime, 0, sizeof( timeTime ) );
|
||
|
|
//
|
||
|
|
//
|
||
|
|
// See if we can find the item
|
||
|
|
//
|
||
|
|
CPQDIF_E_Scalar * psc = FindScalarInCollection( m_pcollMain, tag );
|
||
|
|
if( psc )
|
||
|
|
{
|
||
|
|
foundItem = psc->GetValueTimeStamp( timeTime );
|
||
|
|
}
|
||
|
|
return foundItem;
|
||
|
|
}
|
||
|
|
|
||
|
|
bool CPQDIF_R_General::GetREAL8InMainCollection (const GUID &tag, REAL8 & dVal)
|
||
|
|
{
|
||
|
|
// Initialize
|
||
|
|
bool foundItem = false;
|
||
|
|
|
||
|
|
dVal = 0.0;
|
||
|
|
//
|
||
|
|
//
|
||
|
|
// See if we can find the item
|
||
|
|
//
|
||
|
|
CPQDIF_E_Scalar * psc = FindScalarInCollection( m_pcollMain, tag );
|
||
|
|
if( psc )
|
||
|
|
{
|
||
|
|
foundItem = psc->GetValueREAL8( dVal );
|
||
|
|
}
|
||
|
|
return foundItem;
|
||
|
|
}
|
||
|
|
|
||
|
|
|
||
|
|
bool CPQDIF_R_General::GetBOOL4InMainCollection (const GUID &tag, BOOL4 & bVal)
|
||
|
|
{
|
||
|
|
// Initialize
|
||
|
|
bool foundItem = false;
|
||
|
|
|
||
|
|
bVal = false;
|
||
|
|
//
|
||
|
|
//
|
||
|
|
// See if we can find the item
|
||
|
|
//
|
||
|
|
CPQDIF_E_Scalar * psc = FindScalarInCollection( m_pcollMain, tag );
|
||
|
|
if( psc )
|
||
|
|
{
|
||
|
|
bool val;
|
||
|
|
foundItem = psc->GetValueBOOL4( val );
|
||
|
|
bVal = val;
|
||
|
|
}
|
||
|
|
return foundItem;
|
||
|
|
}
|
||
|
|
|
||
|
|
bool CPQDIF_R_General::SetTimeInMainCollection (const GUID &tag, const TIMESTAMPPQDIF& timeTime)
|
||
|
|
{
|
||
|
|
bool status = false;
|
||
|
|
|
||
|
|
CPQDIF_E_Scalar * psc = FindOrCreateScalarInCollection( m_pcollMain,
|
||
|
|
tag, ID_PHYS_TYPE_TIMESTAMPPQDIF );
|
||
|
|
|
||
|
|
// Set value
|
||
|
|
PQDIFValue value;
|
||
|
|
|
||
|
|
if( psc )
|
||
|
|
{
|
||
|
|
value.ts = timeTime;
|
||
|
|
status = psc->SetValue( ID_PHYS_TYPE_TIMESTAMPPQDIF, value );
|
||
|
|
}
|
||
|
|
|
||
|
|
return status;
|
||
|
|
}
|
||
|
|
|
||
|
|
bool CPQDIF_R_General::SetREAL8InMainCollection (const GUID &tag, const REAL8 dVal)
|
||
|
|
{
|
||
|
|
bool status = false;
|
||
|
|
|
||
|
|
CPQDIF_E_Scalar * psc = FindOrCreateScalarInCollection( m_pcollMain,
|
||
|
|
tag, ID_PHYS_TYPE_REAL8 );
|
||
|
|
|
||
|
|
// Set value
|
||
|
|
PQDIFValue value;
|
||
|
|
|
||
|
|
if( psc )
|
||
|
|
{
|
||
|
|
value.real8 = dVal;
|
||
|
|
status = psc->SetValue( ID_PHYS_TYPE_REAL8, value );
|
||
|
|
}
|
||
|
|
|
||
|
|
return status;
|
||
|
|
}
|
||
|
|
|
||
|
|
bool CPQDIF_R_General::SetBOOL4InMainCollection (const GUID &tag, const BOOL4 bVal)
|
||
|
|
{
|
||
|
|
bool status = false;
|
||
|
|
|
||
|
|
CPQDIF_E_Scalar * psc = FindOrCreateScalarInCollection( m_pcollMain,
|
||
|
|
tag, ID_PHYS_TYPE_BOOLEAN4 );
|
||
|
|
|
||
|
|
// Set value
|
||
|
|
PQDIFValue value;
|
||
|
|
|
||
|
|
if( psc )
|
||
|
|
{
|
||
|
|
value.bool4 = bVal;
|
||
|
|
status = psc->SetValue( ID_PHYS_TYPE_BOOLEAN4, value );
|
||
|
|
}
|
||
|
|
|
||
|
|
return status;
|
||
|
|
}
|
||
|
|
|
||
|
|
|
||
|
|
|
||
|
|
|
||
|
|
|