📄 rec_general.cpp
字号:
/*
** CPQDIF_R_General class. The base class for a PQDIF record.
** --------------------------------------------------------------------------
**
** File name: $Workfile: rec_general.cpp $
** Last modified: $Modtime: 9/03/98 9:10a $
** Last modified by: $Author: Rob $
**
** VCS archive path: $Archive: /Hank/DMM/FirmWare/Level3/ObDatMgr/rec_general.cpp $
** VCS revision: $Revision: 7 $
*/
#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
}
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;
long sizeActual;
long 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 )
{
// 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 )
{
long 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;
}
return status;
}
bool CPQDIF_R_General::GetChanged( void )
{
// ASSERT( m_pcollMain );
if( m_pcollMain )
return m_pcollMain->GetChanged();
else
return false;
}
void CPQDIF_R_General::SetChanged( bool changed )
{
// ASSERT( m_pcollMain );
if( m_pcollMain )
m_pcollMain->SetChanged( changed );
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -