25#ifndef ALTIUM_PARSER_H
26#define ALTIUM_PARSER_H
32#include <wx/mstream.h>
33#include <wx/zstream.h>
42class CompoundFileReader;
43struct COMPOUND_FILE_ENTRY;
51std::string
FormatPath(
const std::vector<std::string>& aVectorPath );
79 std::unique_ptr<ALTIUM_COMPOUND_FILE>
DecodeIntLibStream(
const CFB::COMPOUND_FILE_ENTRY& cfe );
83 std::tuple<wxString, const CFB::COMPOUND_FILE_ENTRY*>
FindLibFootprintDirName(
const wxString& aFpUnicodeName );
85 const CFB::COMPOUND_FILE_ENTRY*
FindStream(
const std::vector<std::string>& aStreamPath )
const;
87 const CFB::COMPOUND_FILE_ENTRY*
FindStream(
const CFB::COMPOUND_FILE_ENTRY* aStart,
const std::vector<std::string>& aStreamPath )
const;
90 const std::string aName,
91 const bool aIsStream )
const;
93 std::map<wxString, const CFB::COMPOUND_FILE_ENTRY*>
EnumDir(
const std::wstring& aDir )
const;
95 std::map<wxString, const CFB::COMPOUND_FILE_ENTRY*>
GetLibSymbols(
const CFB::COMPOUND_FILE_ENTRY* aStart )
const;
113 ALTIUM_PARSER( std::unique_ptr<
char[]>& aContent,
size_t aSize );
116 template <
typename Type>
120 if( remainingBytes >=
sizeof( Type ) )
122 Type val = *(Type*) (
m_pos );
123 m_pos +=
sizeof( Type );
128 m_pos += remainingBytes;
134 template <
typename Type>
137 char*
const oldPos =
m_pos;
139 Type result = Read<Type>();
147 uint8_t len = Read<uint8_t>();
150 char* buf =
new char[len];
151 memcpy( buf,
m_pos, len );
154 return wxScopedCharBuffer::CreateOwned( buf, len );
159 return wxScopedCharBuffer();
172 std::map<uint32_t, wxString> table;
175 while( remaining >= 8 )
177 uint32_t index = Read<uint32_t>();
178 uint32_t length = Read<uint32_t>();
186 if( length > remaining )
189 str = wxString(
m_pos, wxMBConvUTF16LE(), length - 2 );
192 table.emplace( index, str );
209 std::vector<char> data(
m_pos,
m_pos + aSize );
224 memcpy( aOut,
m_pos, aSize );
261 uint32_t length = Read<uint32_t>();
267 std::function<std::map<wxString, wxString>(
const std::string& )> handleBinaryData =
268 [](
const std::string& )
270 return std::map<wxString, wxString>();
275 static int ReadInt(
const std::map<wxString, wxString>& aProps,
276 const wxString& aKey,
int aDefault );
278 static double ReadDouble(
const std::map<wxString, wxString>& aProps,
279 const wxString& aKey,
double aDefault );
281 static bool ReadBool(
const std::map<wxString, wxString>& aProps,
282 const wxString& aKey,
bool aDefault );
284 static int32_t
ReadKicadUnit(
const std::map<wxString, wxString>& aProps,
285 const wxString& aKey,
const wxString& aDefault );
287 static wxString
ReadString(
const std::map<wxString, wxString>& aProps,
288 const wxString& aKey,
const wxString& aDefault );
291 const wxString& aKey,
const wxString& aDefault );
352 throw std::out_of_range(
"ALTIUM_BINARY_READER: out of range" );
362 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" );
411 throw std::runtime_error(
"ALTIUM_COMPRESSED_READER: invalid compressed string" );
415 id = std::stoi( str );
422 return std::make_pair(
id, result );
429 wxMemoryInputStream memStream( (
void*) aData.data(), aData.length() );
432 wxZlibInputStream zStream( memStream );
435 std::string decompressedData;
438 while( !zStream.Eof() )
441 zStream.Read( buffer,
sizeof( buffer ) );
442 size_t bytesRead = zStream.LastRead();
443 decompressedData.append( buffer, bytesRead );
446 return decompressedData;
std::string FormatPath(const std::vector< std::string > &aVectorPath)
Helper for debug logging (vector -> string)
const std::string & m_data
ALTIUM_BINARY_READER(const std::string &binaryData)
std::string ReadPascalString()
std::map< wxString, wxString > ListLibFootprints()
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, const CFB::COMPOUND_FILE_ENTRY * > GetLibSymbols(const CFB::COMPOUND_FILE_ENTRY *aStart) const
std::map< wxString, const CFB::COMPOUND_FILE_ENTRY * > m_libFootprintNameCache
std::tuple< wxString, const CFB::COMPOUND_FILE_ENTRY * > FindLibFootprintDirName(const wxString &aFpUnicodeName)
void cacheLibFootprintNames()
const CFB::COMPOUND_FILE_ENTRY * FindStream(const std::vector< std::string > &aStreamPath) const
std::map< wxString, wxString > m_libFootprintDirNameCache
ALTIUM_COMPOUND_FILE(const ALTIUM_COMPOUND_FILE &temp_obj)=delete
std::pair< int, std::string > ReadCompressedString()
ALTIUM_COMPRESSED_READER(const std::string &aData)
std::string decompressData(std::string &aData)
wxScopedCharBuffer ReadCharBuffer()
static int ReadInt(const std::map< wxString, wxString > &aProps, const wxString &aKey, int aDefault)
size_t GetRemainingBytes() const
size_t GetRemainingSubrecordBytes() const
static wxString ReadString(const std::map< wxString, wxString > &aProps, const wxString &aKey, const wxString &aDefault)
std::map< uint32_t, wxString > ReadWideStringTable()
std::map< wxString, wxString > ReadProperties(std::function< std::map< wxString, wxString >(const std::string &)> handleBinaryData=[](const std::string &) { return std::map< wxString, wxString >();})
std::unique_ptr< char[]> m_content
size_t ReadAndSetSubrecordLength()
std::vector< char > ReadVector(size_t aSize)
int ReadBytes(char *aOut, size_t aSize)
static double ReadDouble(const std::map< wxString, wxString > &aProps, const wxString &aKey, double aDefault)
VECTOR2I ReadVector2ISize()
static int32_t ConvertToKicadUnit(const double aValue)
static bool ReadBool(const std::map< wxString, wxString > &aProps, const wxString &aKey, bool aDefault)
VECTOR2I ReadVector2IPos()
void Skip(size_t aLength)
static wxString ReadUnicodeString(const std::map< wxString, wxString > &aProps, const wxString &aKey, const wxString &aDefault)