μHAL (v2.8.17)
Part of the IPbus software repository
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
DerivedNodeFactory.hpp
Go to the documentation of this file.
1/*
2---------------------------------------------------------------------------
3
4 This file is part of uHAL.
5
6 uHAL is a hardware access library and programming framework
7 originally developed for upgrades of the Level-1 trigger of the CMS
8 experiment at CERN.
9
10 uHAL is free software: you can redistribute it and/or modify
11 it under the terms of the GNU General Public License as published by
12 the Free Software Foundation, either version 3 of the License, or
13 (at your option) any later version.
14
15 uHAL is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 GNU General Public License for more details.
19
20 You should have received a copy of the GNU General Public License
21 along with uHAL. If not, see <http://www.gnu.org/licenses/>.
22
23
24 Andrew Rose, Imperial College, London
25 email: awr01 <AT> imperial.ac.uk
26
27 Marc Magrans de Abril, CERN
28 email: marc.magrans.de.abril <AT> cern.ch
29
30---------------------------------------------------------------------------
31*/
32
40#ifndef _uhal_DerivedNodeFactory_hpp_
41#define _uhal_DerivedNodeFactory_hpp_
42
43
44#include <memory>
45#include <string>
46#include <unordered_map>
47
48
49namespace uhal
50{
51 class Node;
52 class NodeTreeBuilder; // IWYU pragma: keep
53
55 template< typename T > struct RegistrationHelper; // IWYU pragma: keep
56
57
63 {
64 friend class NodeTreeBuilder;
65
66 public:
67
69 template< typename T > friend struct RegistrationHelper;
70
71 private:
77
78 public:
79
82
84 virtual ~DerivedNodeFactory ();
85
91
92
93 private:
94
95 Node* convertToClassType( Node* aNode );
96
101 template <class T>
102 void add ( const std::string& aNodeClassName );
103
104
107 {
108 public:
111 {
112 }
113
116 {
117 }
118
124 virtual Node* create ( const Node& aNode ) = 0;
125 };
126
127
129 template <class T>
131 {
132 public:
133
136 {
137 }
138
140 virtual ~Creator()
141 {
142 }
143
149 Node* create ( const Node& aNode );
150 };
151
152
153 private:
155 static std::shared_ptr<DerivedNodeFactory> mInstance;
156
158 std::unordered_map< std::string , std::shared_ptr< CreatorInterface > > mCreators;
159 };
160}
161
163
164#endif
Templated concrete implementation with a CreatorInterface interface.
Node * create(const Node &aNode)
Concrete function which creates a new IPbus client based on the protocol identifier specified.
An abstract base class for defining the interface to the creators.
virtual Node * create(const Node &aNode)=0
Interface to a function which create a new derived node class based on the class name.
A singleton class to register derived nodes, and create instances of them later NOTE!...
Node * convertToClassType(Node *aNode)
virtual ~DerivedNodeFactory()
Destructor.
DerivedNodeFactory & operator=(const DerivedNodeFactory &)=delete
DerivedNodeFactory()
Default constructor This is private since only a single instance is to be created,...
static DerivedNodeFactory & getInstance()
Static method to retrieve the single instance of the class.
DerivedNodeFactory(const DerivedNodeFactory &)=delete
std::unordered_map< std::string, std::shared_ptr< CreatorInterface > > mCreators
Hash map associating a creator for a particular node type with a string identifier for that node type...
void add(const std::string &aNodeClassName)
Method to create an associate between a node type identifier and a Creator of that particular node ty...
static std::shared_ptr< DerivedNodeFactory > mInstance
The single instance of the class.
A heirarchical node for navigating heirarchical firmwares.
Definition: Node.hpp:85
A class to build a node tree from an address table file.
Experimental!! Helper struct for adding the DerivedNode to the Node Factory Declaring an instance of ...
Definition: DerivedNode.hpp:80