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
28
29
30namespace ALLEGRO
31{
32
33class BLOCK_BASE;
34
41class BRD_DB
42{
43public:
44 BRD_DB();
45
46 void AddString( uint32_t aKey, wxString&& aStr )
47 {
48 m_StringTable.emplace( aKey, std::move( aStr ) );
49 }
50
51 size_t GetObjectCount() const { return m_Blocks.size(); }
52
53 void InsertBlock( std::unique_ptr<BLOCK_BASE> aBlock );
54
63 void ReserveCapacity( size_t aObjectCount, size_t aStringCount, size_t aFileSize );
64
68 const BLOCK_BASE* GetObjectByKey( uint32_t aKey ) const
69 {
70 auto it = m_ObjectKeyMap.find( aKey );
71 return it != m_ObjectKeyMap.end() ? it->second : nullptr;
72 }
73
77 const wxString& GetString( uint32_t aKey ) const
78 {
79 static const wxString empty;
80 auto it = m_StringTable.find( aKey );
81 return it != m_StringTable.end() ? it->second : empty;
82 }
83
85 std::unique_ptr<FILE_HEADER> m_Header;
86
87 std::vector<std::unique_ptr<BLOCK_BASE>> m_Blocks;
88 std::unordered_map<uint32_t, BLOCK_BASE*> m_ObjectKeyMap;
89 std::unordered_map<uint32_t, wxString> m_StringTable;
90};
91
92} // namespace ALLEGRO
The base class for all blocks in the main body of an Allegro file.
void ReserveCapacity(size_t aObjectCount, size_t aStringCount, size_t aFileSize)
Pre-allocate storage for the expected number of objects and strings.
std::unordered_map< uint32_t, wxString > m_StringTable
Definition allegro_db.h:89
std::unordered_map< uint32_t, BLOCK_BASE * > m_ObjectKeyMap
Definition allegro_db.h:88
FMT_VER m_FmtVer
Definition allegro_db.h:84
std::unique_ptr< FILE_HEADER > m_Header
Definition allegro_db.h:85
std::vector< std::unique_ptr< BLOCK_BASE > > m_Blocks
Definition allegro_db.h:87
size_t GetObjectCount() const
Definition allegro_db.h:51
const wxString & GetString(uint32_t aKey) const
Get a string from the string table by key.
Definition allegro_db.h:77
void InsertBlock(std::unique_ptr< BLOCK_BASE > aBlock)
void AddString(uint32_t aKey, wxString &&aStr)
Definition allegro_db.h:46
const BLOCK_BASE * GetObjectByKey(uint32_t aKey) const
Get a block by its key.
Definition allegro_db.h:68
static bool empty(const wxTextEntryBase *aCtrl)
FMT_VER
The format of an Allegro file.