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
26
struct
KICOMMON_API
JOB_REGISTRY_ENTRY
27
{
28
public
:
29
KIWAY::FACE_T
kifaceType
;
30
std::function<
JOB
*()>
createFunc
;
31
wxString
title
;
32
bool
deprecated
=
false
;
33
};
34
35
class
KICOMMON_API
JOB_REGISTRY
36
{
37
public
:
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
59
private
:
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
JOB_REGISTRY
Definition
job_registry.h:36
JOB_REGISTRY::GetRegistry
static const REGISTRY_MAP_T & GetRegistry()
Definition
job_registry.h:55
JOB_REGISTRY::REGISTRY_MAP_T
std::unordered_map< wxString, JOB_REGISTRY_ENTRY > REGISTRY_MAP_T
Definition
job_registry.h:38
JOB_REGISTRY::CreateInstance
static T * CreateInstance(const wxString &aName)
Definition
job_registry.h:45
JOB_REGISTRY::getRegistry
static REGISTRY_MAP_T & getRegistry()
Definition
job_registry.cpp:49
JOB_REGISTRY::GetKifaceType
static KIWAY::FACE_T GetKifaceType(const wxString &aName)
Definition
job_registry.cpp:37
JOB_REGISTRY::Add
static bool Add(const wxString &aName, JOB_REGISTRY_ENTRY entry, bool aDeprecated=false)
Definition
job_registry.cpp:23
JOB
An simple container class that lets us dispatch output jobs to kifaces.
Definition
job.h:183
KIWAY::FACE_T
FACE_T
Known KIFACE implementations.
Definition
kiway.h:292
job.h
KICOMMON_API
#define KICOMMON_API
Definition
kicommon.h:28
kiway.h
JOB_REGISTRY_ENTRY
Definition
job_registry.h:27
JOB_REGISTRY_ENTRY::deprecated
bool deprecated
Definition
job_registry.h:32
JOB_REGISTRY_ENTRY::createFunc
std::function< JOB *()> createFunc
Definition
job_registry.h:30
JOB_REGISTRY_ENTRY::kifaceType
KIWAY::FACE_T kifaceType
Definition
job_registry.h:29
JOB_REGISTRY_ENTRY::title
wxString title
Definition
job_registry.h:31
TRANSLINE_PARAMETERS::T
@ T
Definition
transline_calculation_base.h:38
src
common
jobs
job_registry.h
Generated on Sun Sep 21 2025 01:05:21 for KiCad PCB EDA Suite by
1.13.2