25#ifndef _ALTIUM_BINARY_PARSER_H 
   26#define _ALTIUM_BINARY_PARSER_H 
   38#include <wx/mstream.h> 
   39#include <wx/zstream.h> 
   45class CompoundFileReader;
 
   46struct COMPOUND_FILE_ENTRY;
 
 
   54std::string 
FormatPath( 
const std::vector<std::string>& aVectorPath );
 
  109    const CFB::COMPOUND_FILE_ENTRY* 
FindStream( 
const std::vector<std::string>& aStreamPath ) 
const;
 
  111    const CFB::COMPOUND_FILE_ENTRY* 
FindStream( 
const CFB::COMPOUND_FILE_ENTRY* aStart,
 
  112                                                const std::vector<std::string>& aStreamPath ) 
const;
 
  115                                                           const std::string               aName,
 
  116                                                           const bool aIsStream ) 
const;
 
  118    std::map<wxString, const CFB::COMPOUND_FILE_ENTRY*> 
EnumDir( 
const std::wstring& aDir ) 
const;
 
  120    std::map<wxString, ALTIUM_SYMBOL_DATA> 
GetLibSymbols( 
const CFB::COMPOUND_FILE_ENTRY* aStart ) 
const;
 
 
  133                          const CFB::COMPOUND_FILE_ENTRY* aEntry );
 
  137    template <
typename Type>
 
  142        if( remainingBytes >= 
sizeof( Type ) )
 
  144            Type val = *(Type*) ( 
m_pos );
 
  145            m_pos += 
sizeof( Type );
 
  150            m_pos += remainingBytes; 
 
 
  156    template <
typename Type>
 
  159        char* 
const oldPos = 
m_pos;
 
 
  173            char* buf = 
static_cast<char*
>( malloc( len ) );
 
  174            memcpy( buf, 
m_pos, len );
 
  177            return wxScopedCharBuffer::CreateOwned( buf, len );
 
  182            return wxScopedCharBuffer();
 
 
  195        std::map<uint32_t, wxString> 
table;
 
  198        while( remaining >= 8 )
 
  211                if( length > remaining )
 
  214                str = wxString( 
m_pos, wxMBConvUTF16LE(), length - 2 );
 
  217            table.emplace( index, str );
 
 
  234            std::vector<char> data( 
m_pos, 
m_pos + aSize );
 
 
  249            memcpy( aOut, 
m_pos, aSize );
 
 
  292            std::function<std::map<wxString, wxString>( 
const std::string& )> handleBinaryData =
 
  293                    []( 
const std::string& )
 
  295                return std::map<wxString, wxString>();
 
 
  357            throw std::out_of_range( 
"ALTIUM_BINARY_READER: out of range" );
 
 
  367            throw std::out_of_range( 
"ALTIUM_BINARY_READER: out of range" );
 
 
  377            throw std::out_of_range( 
"ALTIUM_BINARY_READER: out of range" );
 
 
  389            throw std::out_of_range( 
"ALTIUM_BINARY_READER: out of range" );
 
 
  401            throw std::out_of_range( 
"ALTIUM_BINARY_READER: out of range" );
 
 
 
  427            throw std::runtime_error( 
"ALTIUM_COMPRESSED_READER: invalid compressed string" );
 
  430        std::from_chars( str.data(), str.data() + str.size(), 
id );
 
  435        return std::make_pair( 
id, 
result );
 
 
  444        wxMemoryInputStream memStream( (
void*) aData.data(), aData.length() );
 
  447        wxZlibInputStream zStream( memStream );
 
  450        while( !zStream.Eof() )
 
  453            zStream.Read( buffer, 
sizeof( buffer ) );
 
  454            size_t bytesRead = zStream.LastRead();
 
 
 
std::string FormatPath(const std::vector< std::string > &aVectorPath)
Helper for debug logging (vector -> string)
 
size_t GetRemainingBytes() const
 
~ALTIUM_BINARY_PARSER()=default
 
void Skip(size_t aLength)
 
std::vector< char > ReadVector(size_t aSize)
 
std::unique_ptr< char[]> m_content
 
wxScopedCharBuffer ReadCharBuffer()
 
std::map< uint32_t, wxString > ReadWideStringTable()
 
ALTIUM_BINARY_PARSER(const ALTIUM_COMPOUND_FILE &aFile, const CFB::COMPOUND_FILE_ENTRY *aEntry)
 
size_t ReadAndSetSubrecordLength()
 
VECTOR2I ReadVector2ISize()
 
VECTOR2I ReadVector2IPos()
 
size_t GetRemainingSubrecordBytes() const
 
std::map< wxString, wxString > ReadProperties(std::function< std::map< wxString, wxString >(const std::string &)> handleBinaryData=[](const std::string &) { return std::map< wxString, wxString >();})
 
int ReadBytes(char *aOut, size_t aSize)
 
std::string ReadShortPascalString()
 
std::string ReadFullPascalString()
 
const std::string & m_data
 
ALTIUM_BINARY_READER(const std::string &binaryData)
 
ALTIUM_COMPOUND_FILE()
Create an uninitialized file for two-step initialization (e.g. with InitFromBuffer)
 
const CFB::CompoundFileReader & GetCompoundFileReader() const
 
const CFB::COMPOUND_FILE_ENTRY * FindStreamSingleLevel(const CFB::COMPOUND_FILE_ENTRY *aEntry, const std::string aName, const bool aIsStream) const
 
~ALTIUM_COMPOUND_FILE()=default
 
std::map< wxString, const CFB::COMPOUND_FILE_ENTRY * > EnumDir(const std::wstring &aDir) const
 
void InitFromBuffer(const void *aBuffer, size_t aLen)
Load a CFB file from memory; may throw an IO_ERROR.
 
ALTIUM_COMPOUND_FILE & operator=(const ALTIUM_COMPOUND_FILE &temp_obj)=delete
 
std::vector< char > m_buffer
 
std::unique_ptr< CFB::CompoundFileReader > m_reader
 
std::map< wxString, ALTIUM_SYMBOL_DATA > GetLibSymbols(const CFB::COMPOUND_FILE_ENTRY *aStart) const
 
bool DecodeIntLibStream(const CFB::COMPOUND_FILE_ENTRY &cfe, ALTIUM_COMPOUND_FILE *aOutput)
 
const CFB::COMPOUND_FILE_ENTRY * FindStream(const std::vector< std::string > &aStreamPath) const
 
friend class ALTIUM_PCB_COMPOUND_FILE
 
ALTIUM_COMPOUND_FILE(const ALTIUM_COMPOUND_FILE &temp_obj)=delete
 
std::string * decompressData(std::string &aData)
 
ALTIUM_COMPRESSED_READER(const std::string &aData)
 
std::string decompressedData
 
std::pair< int, std::string * > ReadCompressedString()
 
static int32_t ConvertToKicadUnit(const double aValue)
 
const CFB::COMPOUND_FILE_ENTRY * m_pinsSymbolLineWidth
 
const CFB::COMPOUND_FILE_ENTRY * m_symbol
 
const CFB::COMPOUND_FILE_ENTRY * m_pinsFrac
 
const CFB::COMPOUND_FILE_ENTRY * m_pinsWideText
 
const CFB::COMPOUND_FILE_ENTRY * m_pinsTextData
 
wxString result
Test unit parsing edge cases and error handling.
 
VECTOR2< int32_t > VECTOR2I