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 );
95 std::unique_ptr<ALTIUM_COMPOUND_FILE>
DecodeIntLibStream(
const CFB::COMPOUND_FILE_ENTRY& cfe );
97 const CFB::COMPOUND_FILE_ENTRY*
FindStream(
const std::vector<std::string>& aStreamPath )
const;
99 const CFB::COMPOUND_FILE_ENTRY*
FindStream(
const CFB::COMPOUND_FILE_ENTRY* aStart,
100 const std::vector<std::string>& aStreamPath )
const;
103 const std::string aName,
104 const bool aIsStream )
const;
106 std::map<wxString, const CFB::COMPOUND_FILE_ENTRY*>
EnumDir(
const std::wstring& aDir )
const;
108 std::map<wxString, ALTIUM_SYMBOL_DATA>
GetLibSymbols(
const CFB::COMPOUND_FILE_ENTRY* aStart )
const;
121 const CFB::COMPOUND_FILE_ENTRY* aEntry );
125 template <
typename Type>
130 if( remainingBytes >=
sizeof( Type ) )
132 Type val = *(Type*) (
m_pos );
133 m_pos +=
sizeof( Type );
138 m_pos += remainingBytes;
144 template <
typename Type>
147 char*
const oldPos =
m_pos;
149 Type result = Read<Type>();
157 uint8_t len = Read<uint8_t>();
161 char* buf =
static_cast<char*
>( malloc( len ) );
162 memcpy( buf,
m_pos, len );
165 return wxScopedCharBuffer::CreateOwned( buf, len );
170 return wxScopedCharBuffer();
183 std::map<uint32_t, wxString> table;
186 while( remaining >= 8 )
188 uint32_t index = Read<uint32_t>();
189 uint32_t length = Read<uint32_t>();
199 if( length > remaining )
202 str = wxString(
m_pos, wxMBConvUTF16LE(), length - 2 );
205 table.emplace( index, str );
222 std::vector<char> data(
m_pos,
m_pos + aSize );
237 memcpy( aOut,
m_pos, aSize );
274 uint32_t length = Read<uint32_t>();
280 std::function<std::map<wxString, wxString>(
const std::string& )> handleBinaryData =
281 [](
const std::string& )
283 return std::map<wxString, wxString>();
345 throw std::out_of_range(
"ALTIUM_BINARY_READER: out of range" );
355 throw std::out_of_range(
"ALTIUM_BINARY_READER: out of range" );
365 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" );
415 throw std::runtime_error(
"ALTIUM_COMPRESSED_READER: invalid compressed string" );
418 std::from_chars( str.data(), str.data() + str.size(),
id );
423 return std::make_pair(
id, result );
432 wxMemoryInputStream memStream( (
void*) aData.data(), aData.length() );
435 wxZlibInputStream zStream( memStream );
438 while( !zStream.Eof() )
441 zStream.Read( buffer,
sizeof( buffer ) );
442 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()
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)
const CFB::CompoundFileReader & GetCompoundFileReader() const
std::unique_ptr< ALTIUM_COMPOUND_FILE > DecodeIntLibStream(const CFB::COMPOUND_FILE_ENTRY &cfe)
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
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
const CFB::COMPOUND_FILE_ENTRY * FindStream(const std::vector< std::string > &aStreamPath) const
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