KiCad PCB EDA Suite
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 (C) 2021-2022 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:
48 SYMBOL_ASYNC_LOADER( const std::vector<wxString>& aNicknames,
49 SYMBOL_LIB_TABLE* aTable, bool aOnlyPowerSymbols = false,
50 std::unordered_map<wxString, std::vector<LIB_SYMBOL*>>* aOutput = nullptr,
51 PROGRESS_REPORTER* aReporter = nullptr );
52
54
58 void Start();
59
63 bool Join();
64
66 bool Done();
67
69 const wxString& GetErrors() const { return m_errors; }
70
72 typedef std::pair<wxString, std::vector<LIB_SYMBOL*>> LOADED_PAIR;
73
74private:
76 std::vector<LOADED_PAIR> worker();
77
79 std::vector<wxString> m_nicknames;
80
83
86
88 std::unordered_map<wxString, std::vector<LIB_SYMBOL*>>* m_output;
89
92
94 std::atomic<size_t> m_nextLibrary;
95 wxString m_errors;
96 std::mutex m_errorMutex;
97
98 std::vector<std::future<std::vector<LOADED_PAIR>>> m_returns;
99};
100
101#endif
Define a library symbol object.
Definition: lib_symbol.h:98
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>
bool Done()
Returns a string containing any errors generated during the load.
std::vector< std::future< std::vector< LOADED_PAIR > > > m_returns
const wxString & GetErrors() const
Represents a pair of <nickname, loaded parts list>
void Start()
Spins up threads to load all the libraries in m_nicknames.
std::unordered_map< wxString, std::vector< LIB_SYMBOL * > > * m_output
Progress reporter (may be null)
bool m_onlyPowerSymbols
Handle to map that will be filled with the loaded parts per library.
bool Join()
Finalizes the threads and combines the output into the target output map.
SYMBOL_LIB_TABLE * m_table
True if we are loading only power symbols.
SYMBOL_ASYNC_LOADER(const std::vector< wxString > &aNicknames, SYMBOL_LIB_TABLE *aTable, bool aOnlyPowerSymbols=false, std::unordered_map< wxString, std::vector< LIB_SYMBOL * > > *aOutput=nullptr, PROGRESS_REPORTER *aReporter=nullptr)
Constructs a loader for symbol libraries.
PROGRESS_REPORTER * m_reporter
std::pair< wxString, std::vector< LIB_SYMBOL * > > LOADED_PAIR
std::vector< wxString > m_nicknames
Handle to the symbol library table being loaded into.
std::atomic< size_t > m_nextLibrary