📄 pcn_flat.cpp
字号:
}
// Replace the old stream & processors
if( m_pstream )
delete m_pstream;
if( m_pprocHeader )
delete m_pprocHeader;
if( m_pprocBody )
delete m_pprocBody;
m_pstream = pstrmWrite;
m_pprocHeader = pprocWriteHeader;
m_pprocBody = pprocWriteBody;
// Don't keep this one around
if( pprocWriteBodyFirstRecord )
delete pprocWriteBodyFirstRecord;
return status;
}
bool CPQDIF_PC_FlatFile::WriteIncremental( void )
{
bool status = TRUE;
if( !m_pstream->CanWriteIncremental() )
status = FALSE;
// Write the file out
if( status )
{
long countRecords;
long idxRecord;
LINKABS4 posCurrentRecord;
LINKABS4 posCurrentRecordBody;
LINKABS4 posCurrentRecordEnd;
LINKABS4 posNextNewRecord;
SIZE4 sizeHeader;
SIZE4 sizeBody;
CPQDIFRecord * precord;
CPQDIFRecord * precordPrevious;
// Init
countRecords = m_arrayRecords.GetSize();
posCurrentRecord = 0;
// Find the end of the file
posNextNewRecord = 0;
for( idxRecord = 1; idxRecord < countRecords; idxRecord++ )
{
precord = (CPQDIFRecord *) m_arrayRecords[ idxRecord ];
if( precord )
{
// Find the end of this record
precord->HeaderGetPos( posCurrentRecord );
precord->HeaderGetSize( sizeHeader, sizeBody );
posCurrentRecordEnd = posCurrentRecord + sizeHeader + sizeBody;
// Is this the max so far?
if( posNextNewRecord < posCurrentRecordEnd )
{
posNextNewRecord = posCurrentRecordEnd;
}
}
}
// Don't even bother with record 0
for( idxRecord = 1; idxRecord < countRecords; idxRecord++ )
{
precord = (CPQDIFRecord *) m_arrayRecords[ idxRecord ];
precordPrevious = (CPQDIFRecord *) m_arrayRecords[ idxRecord - 1 ];
if( !precord || !precordPrevious )
break;
// Has this record changed?
// If not, don't do anything.
if( !precord->GetChanged() )
continue;
// This record now requires a new location --
// we'll position it at posNextNewRecord.
// GET HEADER INFO
// The sizeBody is NOT necessarily correct.
posCurrentRecord = posNextNewRecord;
precord->HeaderGetSize( sizeHeader, sizeBody );
posCurrentRecordBody = posCurrentRecord + sizeHeader;
// WRITE THE BODY
// Connect the appropriate body processor
m_pstream->ConnectProcessor( m_pprocBody );
status = precord->WriteBody( m_pstream );
// This determines where any more new records go
// (a new posNextNewRecord).
m_pstream->GetPos( posNextNewRecord );
// UPDATE THE HEADER INFO
if( idxRecord == (countRecords - 1) )
{
// Last record!
precord->HeaderSetPosNextRecord( 0 );
}
precord->HeaderSetPos( posCurrentRecord );
sizeBody = (SIZE4) ( posNextNewRecord - posCurrentRecordBody );
precord->HeaderSetSize( sizeHeader, sizeBody );
// We don't need to change this, since the next record
// has probably not changed. If it has, this header will be modified
// again anyway.
// precord->HeaderSetPosNextRecord( posNextRecord );
// WRITE THE HEADER
m_pstream->ConnectProcessor( m_pprocHeader );
status = precord->WriteHeader( m_pstream );
// UPDATE & WRITE THE HEADER FOR THE PREVIOUS RECORD
precordPrevious->HeaderSetPosNextRecord( posCurrentRecord );
status = precordPrevious->WriteHeader( m_pstream );
}
}
return status;
}
long CPQDIF_PC_FlatFile::GetCompressionAlgorithm()
{
long algReturn = 0;
CPQDIF_Element * pel;
long typePhysical;
PQDIFValue value;
CPQDIFRecord * precord;
CPQDIF_E_Collection * pcollFirst;
if( GetRecordCount() > 0 )
{
// Get the main collection of the first record
precord = GetRecord( 0 );
// ASSERT( precord );
pcollFirst = precord->GetMainCollection();
// Add it to this collection
if( pcollFirst )
{
pel = pcollFirst->GetElement( tagCompressionAlgorithmID );
if( pel )
{
if( pel->GetElementType() == ID_ELEMENT_TYPE_SCALAR )
{
CPQDIF_E_Scalar * psc = (CPQDIF_E_Scalar *) pel;
ASSERT_VALID( psc );
psc->GetValue( typePhysical, value );
if( typePhysical == ID_PHYS_TYPE_UNS_INTEGER4 )
{
algReturn = value.uint4;
}
}
}
}
} // Enough records
return algReturn;
}
void CPQDIF_PC_FlatFile::SetCompressionAlgorithm( long algNew )
{
CPQDIF_E_Scalar * psc = (CPQDIF_E_Scalar *) theFactory.NewElement( ID_ELEMENT_TYPE_SCALAR );
if( psc )
{
PQDIFValue value;
CPQDIFRecord * precord;
CPQDIF_E_Collection * pcollFirst;
// Specify it...
value.uint4 = algNew;
psc->SetValue( ID_PHYS_TYPE_UNS_INTEGER4, value );
psc->SetTag( tagCompressionAlgorithmID );
// Get the main collection of the first record
precord = GetRecord( 0 );
pcollFirst = precord->GetMainCollection();
// Add it to this collection
if( pcollFirst )
{
pcollFirst->AddOrReplace( psc );
//m_canWriteIncremental = FALSE; // need to fix
}
}
}
long CPQDIF_PC_FlatFile::GetCompressionStyle()
{
long styleReturn = 0;
CPQDIF_Element * pel;
long typePhysical;
PQDIFValue value;
CPQDIFRecord * precord;
CPQDIF_E_Collection * pcollFirst;
if( GetRecordCount() > 0 )
{
// Get the main collection of the first record
precord = GetRecord( 0 );
// ASSERT( precord );
pcollFirst = precord->GetMainCollection();
// Add it to this collection
if( pcollFirst )
{
pel = pcollFirst->GetElement( tagCompressionStyleID );
if( pel )
{
if( pel->GetElementType() == ID_ELEMENT_TYPE_SCALAR )
{
CPQDIF_E_Scalar * psc = (CPQDIF_E_Scalar *) pel;
ASSERT_VALID( psc );
psc->GetValue( typePhysical, value );
if( typePhysical == ID_PHYS_TYPE_UNS_INTEGER4 )
{
styleReturn = value.uint4;
}
}
}
}
}
return styleReturn;
}
void CPQDIF_PC_FlatFile::SetCompressionStyle( long styleNew )
{
CPQDIF_E_Scalar * psc = (CPQDIF_E_Scalar *) theFactory.NewElement( ID_ELEMENT_TYPE_SCALAR );
if( psc )
{
PQDIFValue value;
CPQDIFRecord * precord;
CPQDIF_E_Collection * pcollFirst;
// Specify it...
value.uint4 = styleNew;
psc->SetValue( ID_PHYS_TYPE_UNS_INTEGER4, value );
psc->SetTag( tagCompressionStyleID );
// Get the main collection of the first record
precord = GetRecord( 0 );
pcollFirst = precord->GetMainCollection();
// Add it to this collection
if( pcollFirst )
{
pcollFirst->AddOrReplace( psc );
//m_canWriteIncremental = FALSE; // need to fix
}
}
}
void CPQDIF_PC_FlatFile::UpdateInformation( void )
{
CPQDIFRecord * precord;
bool m_canWriteIncremental = false; // need to fix
// See if this flag needs to be deactivated...
if( m_canWriteIncremental )
{
precord = GetRecord( 0 );
if( !precord )
{
m_canWriteIncremental = FALSE;
}
else
{
// The first record must not be changed.
// Otherwise, we cannot write incremental.
if( precord->GetChanged() )
{
m_canWriteIncremental = FALSE;
}
}
}
}
void CPQDIF_PC_FlatFile::SetChunkInput( BYTE * chunk, long size )
{
if( chunk && size > 0 )
{
m_chunk = chunk;
m_sizeChunk = size;
}
else
{
m_chunk = NULL;
m_sizeChunk = 0;
}
}
bool CPQDIF_PC_FlatFile::GetChunkOutputSize( long& size )
{
bool status = FALSE;
// If it's a chunk, then pull out all the data
if( m_whichStream == PSIO_Chunk )
{
status = ((CPQDIF_S_Chunk *) m_pstream)->GetOutputSize( size );
}
return status;
}
bool CPQDIF_PC_FlatFile::GetChunkOutput( BYTE * chunk, long size )
{
bool status = FALSE;
// If it's a chunk, then pull out all the data
if( m_whichStream == PSIO_Chunk )
{
status = ((CPQDIF_S_Chunk *) m_pstream)->GetOutput( chunk, size );
}
return status;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -