KiCad PCB EDA Suite
Loading...
Searching...
No Matches
ORCAD_STREAM Class Reference

The caller owns the buffer. More...

#include <orcad_stream.h>

Classes

class  LIMIT_GUARD
 Limit reads to one record so a malformed body cannot consume the next record. More...
 
class  NEST_GUARD
 Bound shared parser recursion; entering a level above MAX_NESTING throws IO_ERROR. More...
 

Public Member Functions

 ORCAD_STREAM (const void *aData, size_t aLength)
 
 ORCAD_STREAM (const std::vector< char > &aData)
 
uint8_t ReadU8 ()
 – scalars (little-endian, bounds-checked, throw IO_ERROR on overrun) ----—
 
int8_t ReadI8 ()
 
uint16_t ReadU16 ()
 
int16_t ReadI16 ()
 
uint32_t ReadU32 ()
 
int32_t ReadI32 ()
 
std::string ReadLzt ()
 – strings ----------------------------------------------------------------—
 
std::string ReadZt ()
 Consumes the NUL; throws IO_ERROR if no terminator remains.
 
std::vector< uint8_t > ReadBytes (size_t aCount)
 – buffers / cursor ---------------------------------------------------------—
 
void Skip (size_t aCount)
 Advance the cursor; throws IO_ERROR when aCount exceeds the remaining bytes.
 
void Seek (size_t aOffset)
 Set the absolute cursor position; throws IO_ERROR when aOffset exceeds Size().
 
size_t GetOffset () const
 
size_t Size () const
 
size_t Remaining () const
 Bytes left; 0 when the cursor is at or past the end.
 
bool AtEnd () const
 
const uint8_t * Data () const
 Raw buffer access for bounded lexical lookahead and payload extraction.
 
int PeekU8 (size_t aAhead=0) const
 – non-throwing lookahead ---------------------------------------------------—
 
bool PeekMatches (const uint8_t *aBytes, size_t aCount, size_t aAhead=0) const
 Returns false if fewer than aCount bytes remain; does not advance the cursor.
 
bool AtPreamble (size_t aAhead=0) const
 True when the 4 preamble bytes FF E4 5C 39 sit at cursor + aAhead.
 
void Expect (const uint8_t *aBytes, size_t aCount, const wxString &aWhat)
 – validated reads ------------------------------------------------------------—
 
void ExpectByte (uint8_t aValue, const wxString &aWhat)
 Consume one byte and require the given value.
 
void ExpectPreamble (const wxString &aWhat)
 Consume the 4 preamble bytes; throws IO_ERROR naming aWhat when absent.
 
void SkipOptionalPreambleBlock ()
 Legacy primitives have no trailing preamble.
 

Static Public Attributes

static constexpr uint8_t PREAMBLE [4] = { 0xFF, 0xE4, 0x5C, 0x39 }
 Magic preceding every framed structure body: FF E4 5C 39.
 
static constexpr size_t npos = static_cast<size_t>( -1 )
 Generic invalid offset sentinel.
 
static constexpr int MAX_NESTING = 64
 Nesting limit of the recursive readers; real files stay far below it.
 

Private Member Functions

void requireBytes (size_t aCount) const
 Throw IO_ERROR unless aCount bytes remain at the cursor.
 

Private Attributes

const uint8_t * m_data
 
size_t m_size
 
size_t m_offset
 
int m_nesting
 

Detailed Description

The caller owns the buffer.

Reads and cursor moves throw IO_ERROR on overrun. Strings retain raw Windows-1252 bytes until conversion with FromOrcadString.

Definition at line 35 of file orcad_stream.h.

Constructor & Destructor Documentation

◆ ORCAD_STREAM() [1/2]

ORCAD_STREAM::ORCAD_STREAM ( const void * aData,
size_t aLength )

◆ ORCAD_STREAM() [2/2]

ORCAD_STREAM::ORCAD_STREAM ( const std::vector< char > & aData)
explicit

Definition at line 51 of file orcad_stream.cpp.

References ORCAD_STREAM().

Member Function Documentation

◆ AtEnd()

bool ORCAD_STREAM::AtEnd ( ) const
inline

◆ AtPreamble()

bool ORCAD_STREAM::AtPreamble ( size_t aAhead = 0) const

True when the 4 preamble bytes FF E4 5C 39 sit at cursor + aAhead.

Definition at line 242 of file orcad_stream.cpp.

References PeekMatches(), and PREAMBLE.

Referenced by readOccScope(), and SkipOptionalPreambleBlock().

◆ Data()

const uint8_t * ORCAD_STREAM::Data ( ) const
inline

Raw buffer access for bounded lexical lookahead and payload extraction.

Definition at line 116 of file orcad_stream.h.

References m_data.

◆ Expect()

void ORCAD_STREAM::Expect ( const uint8_t * aBytes,
size_t aCount,
const wxString & aWhat )

– validated reads ------------------------------------------------------------—

Consumes the bytes before checking them. A mismatch throws IO_ERROR with expected and actual bytes.

Definition at line 248 of file orcad_stream.cpp.

References hexOf(), m_offset, ReadBytes(), and THROW_IO_ERRORF.

Referenced by ExpectByte(), and ExpectPreamble().

◆ ExpectByte()

void ORCAD_STREAM::ExpectByte ( uint8_t aValue,
const wxString & aWhat )

Consume one byte and require the given value.

Definition at line 264 of file orcad_stream.cpp.

References Expect().

Referenced by OrcadParseCache(), OrcadParseCacheV2(), OrcadReadDisplayProp(), OrcadReadSymbolPin(), readOccurrence(), v2DisplayProp(), v2DrawnInstance(), v2PrimBody(), and v2SymbolPin().

◆ ExpectPreamble()

void ORCAD_STREAM::ExpectPreamble ( const wxString & aWhat)

Consume the 4 preamble bytes; throws IO_ERROR naming aWhat when absent.

Definition at line 270 of file orcad_stream.cpp.

References Expect(), and PREAMBLE.

◆ GetOffset()

◆ PeekMatches()

bool ORCAD_STREAM::PeekMatches ( const uint8_t * aBytes,
size_t aCount,
size_t aAhead = 0 ) const

Returns false if fewer than aCount bytes remain; does not advance the cursor.

Definition at line 231 of file orcad_stream.cpp.

References m_data, m_offset, and m_size.

Referenced by AtPreamble(), OrcadReadDevice(), OrcadReadSymbolDef(), and v2Device().

◆ PeekU8()

int ORCAD_STREAM::PeekU8 ( size_t aAhead = 0) const

– non-throwing lookahead ---------------------------------------------------—

Returns -1 when cursor + aAhead is outside the stream.

Definition at line 220 of file orcad_stream.cpp.

References m_data, m_offset, and m_size.

Referenced by OrcadParsePageV2(), OrcadReadSymbolPin(), v2Structure(), and v2SymbolPin().

◆ ReadBytes()

std::vector< uint8_t > ORCAD_STREAM::ReadBytes ( size_t aCount)

– buffers / cursor ---------------------------------------------------------—

Read exactly aCount bytes; throws IO_ERROR on overrun.

Definition at line 188 of file orcad_stream.cpp.

References m_data, m_offset, and requireBytes().

Referenced by Expect(), OrcadParseLibrary(), and v2PrimBody().

◆ ReadI16()

◆ ReadI32()

int32_t ORCAD_STREAM::ReadI32 ( )

◆ ReadI8()

int8_t ORCAD_STREAM::ReadI8 ( )

Definition at line 112 of file orcad_stream.cpp.

References ReadU8().

◆ ReadLzt()

◆ ReadU16()

◆ ReadU32()

◆ ReadU8()

◆ ReadZt()

std::string ORCAD_STREAM::ReadZt ( )

Consumes the NUL; throws IO_ERROR if no terminator remains.

Definition at line 171 of file orcad_stream.cpp.

References end, m_data, m_offset, m_size, and THROW_IO_ERRORF.

Referenced by OrcadParseLibrary().

◆ Remaining()

size_t ORCAD_STREAM::Remaining ( ) const
inline

◆ requireBytes()

void ORCAD_STREAM::requireBytes ( size_t aCount) const
private

Throw IO_ERROR unless aCount bytes remain at the cursor.

Definition at line 93 of file orcad_stream.cpp.

References m_offset, m_size, and THROW_IO_ERRORF.

Referenced by ReadBytes(), ReadU16(), ReadU32(), and ReadU8().

◆ Seek()

void ORCAD_STREAM::Seek ( size_t aOffset)

◆ Size()

size_t ORCAD_STREAM::Size ( ) const
inline

Definition at line 108 of file orcad_stream.h.

References m_size.

Referenced by OrcadParseCache().

◆ Skip()

◆ SkipOptionalPreambleBlock()

void ORCAD_STREAM::SkipOptionalPreambleBlock ( )

Legacy primitives have no trailing preamble.

Skip one only when it is present.

Definition at line 276 of file orcad_stream.cpp.

References AtPreamble(), ReadU32(), and Skip().

Member Data Documentation

◆ m_data

const uint8_t* ORCAD_STREAM::m_data
private

◆ m_nesting

int ORCAD_STREAM::m_nesting
private

Definition at line 150 of file orcad_stream.h.

Referenced by ORCAD_STREAM().

◆ m_offset

◆ m_size

size_t ORCAD_STREAM::m_size
private

◆ MAX_NESTING

int ORCAD_STREAM::MAX_NESTING = 64
staticconstexpr

Nesting limit of the recursive readers; real files stay far below it.

Definition at line 45 of file orcad_stream.h.

Referenced by ORCAD_STREAM::NEST_GUARD::NEST_GUARD().

◆ npos

size_t ORCAD_STREAM::npos = static_cast<size_t>( -1 )
staticconstexpr

Generic invalid offset sentinel.

Definition at line 42 of file orcad_stream.h.

Referenced by readOccHeader(), and ORCAD_STRUCT_READER::ReadPrefixes().

◆ PREAMBLE

uint8_t ORCAD_STREAM::PREAMBLE[4] = { 0xFF, 0xE4, 0x5C, 0x39 }
staticconstexpr

Magic preceding every framed structure body: FF E4 5C 39.

Definition at line 39 of file orcad_stream.h.

Referenced by AtPreamble(), BOOST_AUTO_TEST_CASE(), and ExpectPreamble().


The documentation for this class was generated from the following files: