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 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#pragma once
22
23#include <jobs/job.h>
24#include <kiway.h>
25
27{
28public:
30 std::function<JOB*()> createFunc;
31 wxString title;
32 bool deprecated = false;
33};
34
36{
37public:
38 typedef std::unordered_map<wxString, JOB_REGISTRY_ENTRY> REGISTRY_MAP_T;
39
40 static bool Add( const wxString& aName, JOB_REGISTRY_ENTRY entry, bool aDeprecated = false );
41
42 static KIWAY::FACE_T GetKifaceType( const wxString& aName );
43
44 template <typename T>
45 static T* CreateInstance( const wxString& aName )
46 {
47 REGISTRY_MAP_T& registry = getRegistry();
48
49 if( registry.find( aName ) == registry.end() )
50 return nullptr;
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
71
72#define REGISTER_DEPRECATED_JOB( job_name, title, face, T ) bool job_name##_entry = JOB_REGISTRY::Add( #job_name, \
73 { face, []() \
74 { \
75 return new T(); \
76 }, \
77 title }, true )
78// newline required to appease warning for REGISTER_DEPRECATED_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:38
static T * CreateInstance(const wxString &aName)
Definition: job_registry.h:45
An simple container class that lets us dispatch output jobs to kifaces.
Definition: job.h:183
FACE_T
Known KIFACE implementations.
Definition: kiway.h:292
#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