📄 ser_iter_el.cpp
字号:
/*
** PQDIFIterator class. Implements iteration through a set of PQDIF elements
** (stored in a collection) in order to reconstitute them from a buffer.
** Used in conjunction with the PQController class.
** --------------------------------------------------------------------------
**
** File name: $Workfile: ser_iter_el.cpp $
** Last modified: $Modtime: 12/30/98 15:19 $
** Last modified by: $Author: Bill $
**
** VCS archive path: $Archive: /Hank/DMM/FirmWare/Level3/ObDatMgr/ser_iter_el.cpp $
** VCS revision: $Revision: 5 $
*/
#include "PQDIF_classes.h"
// Construction
// ============
PQDIFIterator::PQDIFIterator
(
PQController * pcont,
BYTE * buffer,
SIZE4 size,
long pos,
int level
)
{
m_pcont = pcont;
m_buffer = buffer;
m_size = size;
m_pos = pos;
m_level = level;
}
PQDIFIterator::~PQDIFIterator()
{
}
bool PQDIFIterator::ParseCollection( void )
{
INT4 idx;
bool accepted;
bool stop = FALSE;
c_collection collection;
//c_scalar scalar;
c_vector vector;
long size;
BYTE * pdata;
c_collection_element * arrayElements;
// Get collection header
collection = *( (c_collection*) ( m_buffer + m_pos ) );
m_pos += sizeof( collection );
ASSERT( m_pos < m_size );
ASSERT( m_pos >= 0 );
// Get collection element array
arrayElements = (c_collection_element *) ( m_buffer + m_pos );
for( idx = 0; idx < collection.count; idx++ )
{
// See what type it is, and see if it can be accepted
switch( arrayElements[ idx ].typeElement )
{
case ID_ELEMENT_TYPE_COLLECTION:
accepted = m_pcont->acceptCollection(
idx,
arrayElements[ idx ].tagElement,
m_level + 1 );
if( accepted )
{
// Seek to the link (to the container header)
m_pos = arrayElements[ idx ].link.linkElement;
ASSERT( m_pos < m_size );
ASSERT( m_pos > 0 );
ASSERT( m_level < 32 );
if( m_pos >= m_size || m_pos < 0 || m_level >= 32 )
{
goto PQITPC_Abort;
}
// Should be at the right file position for this collection
PQDIFIterator * piter = new PQDIFIterator(
m_pcont,
m_buffer,
m_size,
m_pos,
m_level + 1 );
// Recursively parse the new collection
accepted = piter->ParseCollection();
// End of the collection
m_pcont->endOfCollection( m_level + 1 );
// Delete the iterator we just used
delete piter;
}
break;
case ID_ELEMENT_TYPE_SCALAR :
// Read in the scalar header
size = theInfo.GetNumBytesOfType( arrayElements[ idx ].typePhysical );
// Alloc & read data
if( arrayElements[ idx ].isEmbedded )
{
// Pull the data from the embedded value
pdata = (BYTE *) arrayElements[ idx ].valueEmbedded;
}
else
{
// Seek to the link
m_pos = arrayElements[ idx ].link.linkElement;
ASSERT( m_pos < m_size );
ASSERT( m_pos > 0 );
if( m_pos >= m_size || m_pos < 0 )
{
goto PQITPC_Abort;
}
pdata = (BYTE *) ( m_buffer + m_pos );
}
// Accept data?
accepted = m_pcont->acceptScalar(
idx,
arrayElements[ idx ].tagElement,
arrayElements[ idx ].typePhysical,
//&scalar,
(void *) pdata);
break;
case ID_ELEMENT_TYPE_VECTOR :
// Seek to the link (to the vector header)
m_pos = arrayElements[ idx ].link.linkElement;
ASSERT( m_pos < m_size );
ASSERT( m_pos > 0 );
if( m_pos >= m_size || m_pos < 0 )
{
goto PQITPC_Abort;
}
// Grab vector header
vector = *( (c_vector *) ( m_buffer + m_pos ) );
m_pos += sizeof( vector );
// It is possible that this points off the end,
// if vector.count == 0.
ASSERT( m_pos < m_size || vector.count == 0 );
ASSERT( m_pos > 0 );
// Grab pointer to data
pdata = (BYTE *) ( m_buffer + m_pos );
// Accept data? (The acceptVector() function
// must be careful not to go off the end if
// vector.count == 0.
accepted = m_pcont->acceptVector(
idx,
arrayElements[ idx ].tagElement,
arrayElements[ idx ].typePhysical,
&vector,
(void *) pdata);
break;
} // switch()
} // for ()
PQITPC_Abort:
return accepted;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -