KiCad PCB EDA Suite
Loading...
Searching...
No Matches
allegro_db.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 Quilter
5 * Copyright The KiCad Developers, see AUTHORS.txt for contributors.
6 *
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation; either version 2
10 * of the License, or (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program. If not, see <https://www.gnu.org/licenses/>.
19 */
20
21#pragma once
22
23#include <cstdint>
24#include <memory>
25#include <unordered_map>
26#include <unordered_set>
27
29
30
31namespace ALLEGRO
32{
33
34class BLOCK_BASE;
35
42class BRD_DB
43{
44public:
45 BRD_DB();
46
47 void AddString( uint32_t aKey, wxString&& aStr )
48 {
49 m_StringTable.emplace( aKey, std::move( aStr ) );
50 }
51
52 size_t GetObjectCount() const { return m_Blocks.size(); }
53
54 bool IsSentinel( uint32_t aKey ) const
55 {
56 return m_SentinelKeys.count( aKey ) > 0;
57 }
58
59 void AddSentinelKey( uint32_t aKey )
60 {
61 if( aKey != 0 )
62 m_SentinelKeys.insert( aKey );
63 }
64
65 void InsertBlock( std::unique_ptr<BLOCK_BASE> aBlock );
66
71 void ReserveCapacity( size_t aObjectCount, size_t aStringCount );
72
76 bool ResolveAndValidate();
77
81 const BLOCK_BASE* GetObjectByKey( uint32_t aKey ) const
82 {
83 auto it = m_ObjectKeyMap.find( aKey );
84 return it != m_ObjectKeyMap.end() ? it->second : nullptr;
85 }
86
90 const wxString& GetString( uint32_t aKey ) const
91 {
92 static const wxString empty;
93 auto it = m_StringTable.find( aKey );
94 return it != m_StringTable.end() ? it->second : empty;
95 }
96
98 std::unique_ptr<FILE_HEADER> m_Header;
99
100 std::vector<std::unique_ptr<BLOCK_BASE>> m_Blocks;
101 std::unordered_map<uint32_t, BLOCK_BASE*> m_ObjectKeyMap;
102 std::unordered_map<uint32_t, wxString> m_StringTable;
103
104private:
105 // V18+ linked list sentinel keys. References to these are null (end-of-chain).
106 std::unordered_set<uint32_t> m_SentinelKeys;
107};
108
109} // namespace ALLEGRO
The base class for all blocks in the main body of an Allegro file.
std::unordered_map< uint32_t, wxString > m_StringTable
Definition allegro_db.h:102
std::unordered_map< uint32_t, BLOCK_BASE * > m_ObjectKeyMap
Definition allegro_db.h:101
FMT_VER m_FmtVer
Definition allegro_db.h:97
std::unique_ptr< FILE_HEADER > m_Header
Definition allegro_db.h:98
std::vector< std::unique_ptr< BLOCK_BASE > > m_Blocks
Definition allegro_db.h:100
size_t GetObjectCount() const
Definition allegro_db.h:52
const wxString & GetString(uint32_t aKey) const
Get a string from the string table by key.
Definition allegro_db.h:90
void ReserveCapacity(size_t aObjectCount, size_t aStringCount)
Pre-allocate storage for the expected number of objects and strings.
bool ResolveAndValidate()
Populate sentinel keys from the file header linked lists.
bool IsSentinel(uint32_t aKey) const
Definition allegro_db.h:54
void InsertBlock(std::unique_ptr< BLOCK_BASE > aBlock)
void AddString(uint32_t aKey, wxString &&aStr)
Definition allegro_db.h:47
const BLOCK_BASE * GetObjectByKey(uint32_t aKey) const
Get a block by its key.
Definition allegro_db.h:81
void AddSentinelKey(uint32_t aKey)
Definition allegro_db.h:59
std::unordered_set< uint32_t > m_SentinelKeys
Definition allegro_db.h:106
static bool empty(const wxTextEntryBase *aCtrl)
FMT_VER
The format of an Allegro file.