KiCad PCB EDA Suite
Loading...
Searching...
No Matches
generated_table_refresh.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
7 * modify it under the terms of the GNU General Public License
8 * as published by the Free Software Foundation; either version 2
9 * of the License, or (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <https://www.gnu.org/licenses/>.
18 */
19
20#ifndef GENERATED_TABLE_REFRESH_H
21#define GENERATED_TABLE_REFRESH_H
22
23#include <memory>
24#include <type_traits>
25#include <typeindex>
26#include <typeinfo>
27#include <utility>
28#include <vector>
29
30class BOARD;
31
32
37{
38public:
39 virtual ~GENERATED_TABLE_PENDING() = default;
40
41 virtual void Commit( BOARD& aBoard ) = 0;
42};
43
44
52{
53public:
54 explicit GENERATED_TABLE_REFRESH( BOARD& aBoard );
55
58
62 template <typename T>
64 {
65 static_assert( std::is_base_of_v<GENERATED_TABLE_PENDING, T>,
66 "Pending state must derive from GENERATED_TABLE_PENDING" );
67
68 const std::type_index type( typeid( T ) );
69
70 for( auto& [pendingType, pending] : m_pending )
71 {
72 if( pendingType == type )
73 return static_cast<T&>( *pending );
74 }
75
76 m_pending.emplace_back( type, std::make_unique<T>( m_board ) );
77
78 return static_cast<T&>( *m_pending.back().second );
79 }
80
84 void Commit();
85
86private:
88
89 std::vector<std::pair<std::type_index, std::unique_ptr<GENERATED_TABLE_PENDING>>> m_pending;
90};
91
92
99int RefreshGeneratedTables( BOARD& aBoard );
100
101#endif // GENERATED_TABLE_REFRESH_H
Information pertinent to a Pcbnew printed circuit board.
Definition board.h:410
Board state a table rebuild wants to change, held back until the whole refresh has succeeded.
virtual void Commit(BOARD &aBoard)=0
virtual ~GENERATED_TABLE_PENDING()=default
void Commit()
Write every pending state back to the board, in the order it was first asked for.
T & Pending()
The pass's T, created from the board on first use.
std::vector< std::pair< std::type_index, std::unique_ptr< GENERATED_TABLE_PENDING > > > m_pending
GENERATED_TABLE_REFRESH(const GENERATED_TABLE_REFRESH &)=delete
GENERATED_TABLE_REFRESH & operator=(const GENERATED_TABLE_REFRESH &)=delete
int RefreshGeneratedTables(BOARD &aBoard)
Bring every generated table on the board up to date and return how many were rebuilt.