KiCad PCB EDA Suite
Loading...
Searching...
No Matches
pads_sch_sdb.h
Go to the documentation of this file.
1/*
2 * This program source code file is part of KiCad, a free EDA CAD application.
3 *
4 * Copyright The KiCad Developers, see AUTHORS.txt for contributors.
5 *
6 * This program is free software: you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License as published by the
8 * Free Software Foundation, either version 3 of the License, or (at your option)
9 * any later version.
10 *
11 * This program is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License along
17 * with this program. If not, see <http://www.gnu.org/licenses/>.
18 */
19
20#pragma once
21
22#include <array>
23#include <cstddef>
24#include <cstdint>
25#include <vector>
26
28
29namespace PADS_SCH_BINARY
30{
31
33{
34 uint32_t allocatedBytes = 0;
35 uint32_t count = 0;
36 uint32_t usedBytes = 0;
37 uint32_t handle = 0;
38};
39
40
49
50
52{
54 int controller = -1;
55 size_t offset = 0;
56 size_t bytes = 0;
57 uint32_t count = 0;
58 uint32_t stride = 0;
59
60 size_t End() const { return offset + bytes; }
61};
62
63
65{
67 std::array<int32_t, 4> extent{};
68 int32_t left = 0;
69 int32_t bottom = 0;
70 int32_t right = 0;
71 int32_t top = 0;
72 uint32_t sheetPlane = 0;
73 uint32_t flags = 0;
74 size_t trailerOffset = 0;
75 size_t extentOffset = 0;
76 size_t boxOffset = 0;
77};
78
79
81{
82public:
83 PADS_SCH_SDB() = default;
84
85 PADS_SCH_SDB( const PADS_SCH_SDB& ) = delete;
86 PADS_SCH_SDB& operator=( const PADS_SCH_SDB& ) = delete;
87
88 void Load( std::vector<uint8_t> aBytes );
89
90 static bool HasFamilyMagic( const std::vector<uint8_t>& aBytes );
91 static bool IsSupportedVersion( uint16_t aVersion );
92
93 uint16_t Version() const { return m_version; }
94 const std::array<SCH_SDB_POOL, 20>& Pools() const { return m_pools; }
95 const PADS_IO::BINARY_CURSOR& Cursor() const { return m_cursor; }
96 const std::vector<uint8_t>& Bytes() const { return m_data; }
97 const std::vector<SCH_SDB_BLOCK>& Blocks() const { return m_blocks; }
98 const std::vector<SCH_SDB_OLE_ITEM>& OleItems() const { return m_oleItems; }
99 size_t PayloadOffset() const { return m_payloadOffset; }
100 size_t FooterOffset() const { return m_footerOffset; }
101
102private:
103 void parseHeader();
104 void parseDirectory();
105 void verifyFooter();
106 void parseBlocks();
107 [[noreturn]] void throwAt( size_t aOffset, const wxString& aDetail ) const;
108
109 std::vector<uint8_t> m_data;
111 uint16_t m_version = 0;
112 std::array<SCH_SDB_POOL, 20> m_pools{};
113 std::vector<SCH_SDB_BLOCK> m_blocks;
114 std::vector<SCH_SDB_OLE_ITEM> m_oleItems;
115 size_t m_payloadOffset = 0;
116 size_t m_footerOffset = 0;
117};
118
119} // namespace PADS_SCH_BINARY
Bounds-checked little-endian read cursor over a PADS binary buffer.
void throwAt(size_t aOffset, const wxString &aDetail) const
const std::array< SCH_SDB_POOL, 20 > & Pools() const
std::vector< uint8_t > m_data
const PADS_IO::BINARY_CURSOR & Cursor() const
void Load(std::vector< uint8_t > aBytes)
std::array< SCH_SDB_POOL, 20 > m_pools
static bool IsSupportedVersion(uint16_t aVersion)
static bool HasFamilyMagic(const std::vector< uint8_t > &aBytes)
PADS_SCH_SDB & operator=(const PADS_SCH_SDB &)=delete
std::vector< SCH_SDB_OLE_ITEM > m_oleItems
const std::vector< uint8_t > & Bytes() const
const std::vector< SCH_SDB_BLOCK > & Blocks() const
PADS_IO::BINARY_CURSOR m_cursor
const std::vector< SCH_SDB_OLE_ITEM > & OleItems() const
std::vector< SCH_SDB_BLOCK > m_blocks
PADS_SCH_SDB(const PADS_SCH_SDB &)=delete
std::array< int32_t, 4 > extent