μHAL (v2.8.17)
Part of the IPbus software repository
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
DerivedNodeFactory.cpp
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 aod 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
34
35
36#include <memory>
37#include <stddef.h> // for NULL
38#include <unordered_map>
39
40#include "uhal/log/LogLevels.hpp" // for Warning
41#include "uhal/log/log_inserters.quote.hpp" // for Quote, _Quote
42#include "uhal/log/log.hpp"
43#include "uhal/Node.hpp"
44
45
46namespace uhal
47{
48
49 std::shared_ptr<DerivedNodeFactory> DerivedNodeFactory::mInstance;
50
51
53 {
54 }
55
56
58 {
59 }
60
61
63 {
64 if ( ! mInstance )
65 {
66 mInstance.reset(new DerivedNodeFactory());
67 }
68
69 return *mInstance;
70 }
71
72
74 {
75 std::unordered_map< std::string , std::shared_ptr<CreatorInterface> >::const_iterator lIt = mCreators.find ( aNode->mClassName );
76
77 if ( lIt == mCreators.end() )
78 {
79 log ( Warning , "Class " , Quote ( aNode->mClassName ) , " is unknown to the NodeTreeBuilder class factory. A plain node will be returned instead." );
80
81 if ( mCreators.size() )
82 {
83 log ( Warning , "Known types are:" );
84
85 for ( std::unordered_map< std::string , std::shared_ptr<CreatorInterface> >::const_iterator lIt = mCreators.begin() ; lIt != mCreators.end() ; ++lIt )
86 {
87 log ( Warning , " > " , lIt->first );
88 }
89 }
90 else
91 {
92 log ( Warning , "No class types have been defined" );
93 }
94
95 return aNode;
96 }
97 else
98 {
99 Node* lClassNode ( lIt->second->create ( *aNode ) );
100 delete aNode;
101 return lClassNode;
102 }
103 }
104
105}
A singleton class to register derived nodes, and create instances of them later NOTE!...
Node * convertToClassType(Node *aNode)
virtual ~DerivedNodeFactory()
Destructor.
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.
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...
static std::shared_ptr< DerivedNodeFactory > mInstance
The single instance of the class.
A heirarchical node for navigating heirarchical firmwares.
Definition: Node.hpp:85
std::string mClassName
Class name used to construct the derived node type.
Definition: Node.hpp:364
_Quote< T > Quote(const T &aT)
void log(FatalLevel &aFatal, const T0 &aArg0)
Function to add a log entry at Fatal level.
Definition: log.hxx:18
WarningLevel Warning
Definition: LogLevels.cpp:79