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,
const std::vector<std::string>& aStreamPath )
const;
102 const std::string aName,
103 const bool aIsStream )
const;
105 std::map<wxString, const CFB::COMPOUND_FILE_ENTRY*>
EnumDir(
const std::wstring& aDir )
const;
107 std::map<wxString, ALTIUM_SYMBOL_DATA>
GetLibSymbols(
const CFB::COMPOUND_FILE_ENTRY* aStart )
const;
123 template <
typename Type>
127 if( remainingBytes >=
sizeof( Type ) )
129 Type val = *(Type*) (
m_pos );
130 m_pos +=
sizeof( Type );
135 m_pos += remainingBytes;
141 template <
typename Type>
144 char*
const oldPos =
m_pos;
146 Type result = Read<Type>();
154 uint8_t len = Read<uint8_t>();
158 char* buf =
static_cast<char*
>( malloc( len ) );
159 memcpy( buf,
m_pos, len );
162 return wxScopedCharBuffer::CreateOwned( buf, len );
167 return wxScopedCharBuffer();
180 std::map<uint32_t, wxString> table;
183 while( remaining >= 8 )
185 uint32_t index = Read<uint32_t>();
186 uint32_t length = Read<uint32_t>();
194 if( length > remaining )
197 str = wxString(
m_pos, wxMBConvUTF16LE(), length - 2 );
200 table.emplace( index, str );
217 std::vector<char> data(
m_pos,
m_pos + aSize );
232 memcpy( aOut,
m_pos, aSize );
269 uint32_t length = Read<uint32_t>();
275 std::function<std::map<wxString, wxString>(
const std::string& )> handleBinaryData =
276 [](
const std::string& )
278 return std::map<wxString, wxString>();
340 throw std::out_of_range(
"ALTIUM_BINARY_READER: out of range" );
350 throw std::out_of_range(
"ALTIUM_BINARY_READER: out of range" );
360 throw std::out_of_range(
"ALTIUM_BINARY_READER: out of range" );
372 throw std::out_of_range(
"ALTIUM_BINARY_READER: out of range" );
384 throw std::out_of_range(
"ALTIUM_BINARY_READER: out of range" );
409 throw std::runtime_error(
"ALTIUM_COMPRESSED_READER: invalid compressed string" );
412 std::from_chars( str.data(), str.data() + str.size(),
id );
417 return std::make_pair(
id, result );
426 wxMemoryInputStream memStream( (
void*) aData.data(), aData.length() );
429 wxZlibInputStream zStream( memStream );
432 while( !zStream.Eof() )
435 zStream.Read( buffer,
sizeof( buffer ) );
436 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