21#ifndef _ALTIUM_BINARY_PARSER_H
22#define _ALTIUM_BINARY_PARSER_H
34#include <wx/mstream.h>
35#include <wx/zstream.h>
41class CompoundFileReader;
42struct COMPOUND_FILE_ENTRY;
50std::string
FormatPath(
const std::vector<std::string>& aVectorPath );
105 const CFB::COMPOUND_FILE_ENTRY*
FindStream(
const std::vector<std::string>& aStreamPath )
const;
107 const CFB::COMPOUND_FILE_ENTRY*
FindStream(
const CFB::COMPOUND_FILE_ENTRY* aStart,
108 const std::vector<std::string>& aStreamPath )
const;
111 const std::string aName,
112 const bool aIsStream )
const;
114 std::map<wxString, const CFB::COMPOUND_FILE_ENTRY*>
EnumDir(
const std::wstring& aDir )
const;
116 std::map<wxString, ALTIUM_SYMBOL_DATA>
GetLibSymbols(
const CFB::COMPOUND_FILE_ENTRY* aStart )
const;
129 const CFB::COMPOUND_FILE_ENTRY* aEntry );
133 template <
typename Type>
138 if( remainingBytes >=
sizeof( Type ) )
140 Type val = *(Type*) (
m_pos );
141 m_pos +=
sizeof( Type );
146 m_pos += remainingBytes;
152 template <
typename Type>
155 char*
const oldPos =
m_pos;
169 char* buf =
static_cast<char*
>( malloc( len ) );
170 memcpy( buf,
m_pos, len );
173 return wxScopedCharBuffer::CreateOwned( buf, len );
178 return wxScopedCharBuffer();
191 std::map<uint32_t, wxString>
table;
194 while( remaining >= 8 )
207 if( length > remaining )
210 str = wxString(
m_pos, wxMBConvUTF16LE(), length - 2 );
230 std::vector<char> data(
m_pos,
m_pos + aSize );
245 memcpy( aOut,
m_pos, aSize );
288 std::function<std::map<wxString, wxString>(
const std::string& )> handleBinaryData =
289 [](
const std::string& )
291 return std::map<wxString, wxString>();
353 throw std::out_of_range(
"ALTIUM_BINARY_READER: out of range" );
363 throw std::out_of_range(
"ALTIUM_BINARY_READER: out of range" );
373 throw std::out_of_range(
"ALTIUM_BINARY_READER: out of range" );
385 throw std::out_of_range(
"ALTIUM_BINARY_READER: out of range" );
397 throw std::out_of_range(
"ALTIUM_BINARY_READER: out of range" );
423 throw std::runtime_error(
"ALTIUM_COMPRESSED_READER: invalid compressed string" );
426 std::from_chars( str.data(), str.data() + str.size(),
id );
431 return std::make_pair(
id,
result );
440 wxMemoryInputStream memStream( (
void*) aData.data(), aData.length() );
443 wxZlibInputStream zStream( memStream );
446 while( !zStream.Eof() )
449 zStream.Read( buffer,
sizeof( buffer ) );
450 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
std::vector< std::vector< std::string > > table
wxString result
Test unit parsing edge cases and error handling.
VECTOR2< int32_t > VECTOR2I