KiCad PCB EDA Suite
Loading...
Searching...
No Matches
job_registry.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) 2024 Mark Roszko <[email protected]>
5 * Copyright (C) 2024 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#pragma once
22
23#include <jobs/job.h>
24#include <kiway.h>
25
27{
28public:
30 std::function<JOB*()> createFunc;
31 wxString title;
32};
33
35{
36public:
37 typedef std::unordered_map<wxString, JOB_REGISTRY_ENTRY> REGISTRY_MAP_T;
38
39 static bool Add( const wxString& aName, JOB_REGISTRY_ENTRY entry );
40
41 static KIWAY::FACE_T GetKifaceType( const wxString& aName );
42
43 template <typename T>
44 static T* CreateInstance( const wxString& aName )
45 {
46 REGISTRY_MAP_T& registry = getRegistry();
47 if( registry.find( aName ) == registry.end() )
48 {
49 return nullptr;
50 }
51
52 return registry[aName].createFunc();
53 }
54
55 static const REGISTRY_MAP_T& GetRegistry() {
56 return getRegistry();
57 }
58
59private:
60 // Use Meyer's singleton to prevent SIOF
61 static REGISTRY_MAP_T& getRegistry();
62};
63
64#define REGISTER_JOB( job_name, title, face, T ) bool job_name##_entry = JOB_REGISTRY::Add( #job_name, \
65 { face, []() \
66 { \
67 return new T(); \
68 }, \
69 title } )
70// newline required to appease warning for REGISTER_JOB macro
static const REGISTRY_MAP_T & GetRegistry()
Definition: job_registry.h:55
std::unordered_map< wxString, JOB_REGISTRY_ENTRY > REGISTRY_MAP_T
Definition: job_registry.h:37
static T * CreateInstance(const wxString &aName)
Definition: job_registry.h:44
An simple container class that lets us dispatch output jobs to kifaces.
Definition: job.h:79
FACE_T
Known KIFACE implementations.
Definition: kiway.h:290
#define KICOMMON_API
Definition: kicommon.h:28
Definition: job_registry.h:27
KIWAY::FACE_T kifaceType
Definition: job_registry.h:29
wxString title
Definition: job_registry.h:31