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, you may find one here:
19 * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
20 * or you may search the http://www.gnu.org website for the version 2 license,
21 * or you may write to the Free Software Foundation, Inc.,
22 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
23 */
24
25#pragma once
26
27#include <cstdint>
28#include <memory>
29#include <unordered_map>
30#include <unordered_set>
31
33
34
35namespace ALLEGRO
36{
37
38class BLOCK_BASE;
39
46class BRD_DB
47{
48public:
49 BRD_DB();
50
51 void AddString( uint32_t aKey, wxString&& aStr )
52 {
53 m_StringTable.emplace( aKey, std::move( aStr ) );
54 }
55
56 size_t GetObjectCount() const { return m_Blocks.size(); }
57
58 bool IsSentinel( uint32_t aKey ) const
59 {
60 return m_SentinelKeys.count( aKey ) > 0;
61 }
62
63 void AddSentinelKey( uint32_t aKey )
64 {
65 if( aKey != 0 )
66 m_SentinelKeys.insert( aKey );
67 }
68
69 void InsertBlock( std::unique_ptr<BLOCK_BASE> aBlock );
70
75 void ReserveCapacity( size_t aObjectCount, size_t aStringCount );
76
80 bool ResolveAndValidate();
81
85 const BLOCK_BASE* GetObjectByKey( uint32_t aKey ) const
86 {
87 auto it = m_ObjectKeyMap.find( aKey );
88 return it != m_ObjectKeyMap.end() ? it->second : nullptr;
89 }
90
94 const wxString& GetString( uint32_t aKey ) const
95 {
96 static const wxString empty;
97 auto it = m_StringTable.find( aKey );
98 return it != m_StringTable.end() ? it->second : empty;
99 }
100
102 std::unique_ptr<FILE_HEADER> m_Header;
103
104 std::vector<std::unique_ptr<BLOCK_BASE>> m_Blocks;
105 std::unordered_map<uint32_t, BLOCK_BASE*> m_ObjectKeyMap;
106 std::unordered_map<uint32_t, wxString> m_StringTable;
107
108private:
109 // V18+ linked list sentinel keys. References to these are null (end-of-chain).
110 std::unordered_set<uint32_t> m_SentinelKeys;
111};
112
113} // 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:106
std::unordered_map< uint32_t, BLOCK_BASE * > m_ObjectKeyMap
Definition allegro_db.h:105
std::unique_ptr< FILE_HEADER > m_Header
Definition allegro_db.h:102
std::vector< std::unique_ptr< BLOCK_BASE > > m_Blocks
Definition allegro_db.h:104
size_t GetObjectCount() const
Definition allegro_db.h:56
const wxString & GetString(uint32_t aKey) const
Get a string from the string table by key.
Definition allegro_db.h:94
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:58
void InsertBlock(std::unique_ptr< BLOCK_BASE > aBlock)
void AddString(uint32_t aKey, wxString &&aStr)
Definition allegro_db.h:51
const BLOCK_BASE * GetObjectByKey(uint32_t aKey) const
Get a block by its key.
Definition allegro_db.h:85
void AddSentinelKey(uint32_t aKey)
Definition allegro_db.h:63
std::unordered_set< uint32_t > m_SentinelKeys
Definition allegro_db.h:110
static bool empty(const wxTextEntryBase *aCtrl)
FMT_VER
The format of an Allegro file.