33#include <wx/mstream.h>
34#include <wx/zstream.h>
40 class CompoundFileReader;
41 struct COMPOUND_FILE_ENTRY;
49std::string
FormatPath(
const std::vector<std::string>& aVectorPath );
104 const CFB::COMPOUND_FILE_ENTRY*
FindStream(
const std::vector<std::string>& aStreamPath )
const;
106 const CFB::COMPOUND_FILE_ENTRY*
FindStream(
const CFB::COMPOUND_FILE_ENTRY* aStart,
107 const std::vector<std::string>& aStreamPath )
const;
110 const std::string aName,
111 const bool aIsStream )
const;
113 std::map<wxString, const CFB::COMPOUND_FILE_ENTRY*>
EnumDir(
const std::wstring& aDir )
const;
115 std::map<wxString, ALTIUM_SYMBOL_DATA>
GetLibSymbols(
const CFB::COMPOUND_FILE_ENTRY* aStart )
const;
131 template <
typename Type>
136 if( remainingBytes >=
sizeof( Type ) )
138 Type val = *(Type*) (
m_pos );
139 m_pos +=
sizeof( Type );
144 m_pos += remainingBytes;
150 template <
typename Type>
153 char*
const oldPos =
m_pos;
167 char* buf =
static_cast<char*
>( malloc( len ) );
168 memcpy( buf,
m_pos, len );
171 return wxScopedCharBuffer::CreateOwned( buf, len );
176 return wxScopedCharBuffer();
189 std::map<uint32_t, wxString>
table;
192 while( remaining >= 8 )
205 if( length > remaining )
208 str = wxString(
m_pos, wxMBConvUTF16LE(), length - 2 );
228 std::vector<char> data(
m_pos,
m_pos + aSize );
243 memcpy( aOut,
m_pos, aSize );
286 std::function<std::map<wxString, wxString>(
const std::string& )> handleBinaryData =
287 [](
const std::string& )
289 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" );
424 throw std::runtime_error(
"ALTIUM_COMPRESSED_READER: invalid compressed string" );
427 std::from_chars( str.data(), str.data() + str.size(),
id );
432 return std::make_pair(
id,
result );
441 wxMemoryInputStream memStream( (
void*) aData.data(), aData.length() );
444 wxZlibInputStream zStream( memStream );
447 while( !zStream.Eof() )
450 zStream.Read( buffer,
sizeof( buffer ) );
451 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, bool *aOutOfRange=nullptr)
Convert a value in Altium's internal unit (0.1 uinch) to KiCad IU, clamped to the representable range...
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