KiCad PCB EDA Suite
Loading...
Searching...
No Matches
symbol_async_loader.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 (C) 2021 Jon Evans <[email protected]>
5 * Copyright The KiCad Developers, see AUTHORS.txt for contributors.
6 *
7 * This program is free software: you can redistribute it and/or modify it
8 * under the terms of the GNU General Public License as published by the
9 * Free Software Foundation, either version 3 of the License, or (at your
10 * option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License along
18 * with this program. If not, see <http://www.gnu.org/licenses/>.
19 */
20
21#ifndef KICAD_SYMBOL_ASYNC_LOADER_H
22#define KICAD_SYMBOL_ASYNC_LOADER_H
23
24#include <atomic>
25#include <future>
26#include <mutex>
27#include <unordered_map>
28#include <vector>
29
30#include <wx/string.h>
31
32class LIB_SYMBOL;
35
36
38{
39public:
49 SYMBOL_ASYNC_LOADER( const std::vector<wxString>& aNicknames,
50 SYMBOL_LIB_TABLE* aTable, bool aOnlyPowerSymbols = false,
51 std::unordered_map<wxString, std::vector<LIB_SYMBOL*>>* aOutput = nullptr,
52 PROGRESS_REPORTER* aReporter = nullptr );
53
55
59 void Start();
60
64 bool Join();
65
67 bool Done();
68
70 const wxString& GetErrors() const { return m_errors; }
71
73 typedef std::pair<wxString, std::vector<LIB_SYMBOL*>> LOADED_PAIR;
74
75private:
77 std::vector<LOADED_PAIR> worker();
78
80 std::vector<wxString> m_nicknames;
81
84
87
89 std::unordered_map<wxString, std::vector<LIB_SYMBOL*>>* m_output;
90
93
95 std::atomic<size_t> m_nextLibrary;
96 wxString m_errors;
97 std::mutex m_errorMutex;
98
99 std::vector<std::future<std::vector<LOADED_PAIR>>> m_returns;
100};
101
102#endif
Define a library symbol object.
Definition: lib_symbol.h:85
A progress reporter interface for use in multi-threaded environments.
std::vector< LOADED_PAIR > worker()
Worker job that loads libraries and returns a list of pairs of <nickname, loaded parts>.
std::vector< std::future< std::vector< LOADED_PAIR > > > m_returns
const wxString & GetErrors() const
void Start()
Spin up threads to load all the libraries in m_nicknames.
std::unordered_map< wxString, std::vector< LIB_SYMBOL * > > * m_output
Handle to map that will be filled with the loaded parts per library.
bool m_onlyPowerSymbols
True if we are loading only power symbols.
bool Join()
Finalize the threads and combines the output into the target output map.
SYMBOL_LIB_TABLE * m_table
Handle to the symbol library table being loaded into.
PROGRESS_REPORTER * m_reporter
Progress reporter (may be null).
std::pair< wxString, std::vector< LIB_SYMBOL * > > LOADED_PAIR
Represent a pair of <nickname, loaded parts list>.
std::vector< wxString > m_nicknames
List of libraries to load.
std::atomic< size_t > m_nextLibrary