μHAL (v2.7.9)
Part of the IPbus software repository
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 <stddef.h> // for NULL
37 
38 #include <boost/shared_ptr.hpp> // for shared_ptr
39 #include <boost/unordered_map.hpp> // for operator!=, operator==
40 
41 #include "uhal/log/LogLevels.hpp" // for Warning
42 #include "uhal/log/log_inserters.quote.hpp" // for Quote, _Quote
43 #include "uhal/log/log.hpp"
44 #include "uhal/Node.hpp"
45 
46 
47 namespace uhal
48 {
49 
51 
52 
54  {
55  }
56 
57 
59  {
60  }
61 
62 
64  {
65  if ( ! mInstance )
66  {
67  mInstance.reset(new DerivedNodeFactory());
68  }
69 
70  return *mInstance;
71  }
72 
73 
75  {
76  boost::unordered_map< std::string , boost::shared_ptr<CreatorInterface> >::const_iterator lIt = mCreators.find ( aNode->mClassName );
77 
78  if ( lIt == mCreators.end() )
79  {
80  log ( Warning , "Class " , Quote ( aNode->mClassName ) , " is unknown to the NodeTreeBuilder class factory. A plain node will be returned instead." );
81 
82  if ( mCreators.size() )
83  {
84  log ( Warning , "Known types are:" );
85 
86  for ( boost::unordered_map< std::string , boost::shared_ptr<CreatorInterface> >::const_iterator lIt = mCreators.begin() ; lIt != mCreators.end() ; ++lIt )
87  {
88  log ( Warning , " > " , lIt->first );
89  }
90  }
91  else
92  {
93  log ( Warning , "No class types have been defined" );
94  }
95 
96  return aNode;
97  }
98  else
99  {
100  Node* lClassNode ( lIt->second->create ( *aNode ) );
101  delete aNode;
102  return lClassNode;
103  }
104  }
105 
106 }
boost::shared_ptr
Definition: DerivedNodeFactory.hpp:52
uhal::DerivedNodeFactory::mInstance
static boost::shared_ptr< DerivedNodeFactory > mInstance
The single instance of the class.
Definition: DerivedNodeFactory.hpp:157
Node.hpp
uhal::DerivedNodeFactory
A singleton class to register derived nodes, and create instances of them later NOTE!...
Definition: DerivedNodeFactory.hpp:69
uhal
Definition: HttpResponseGrammar.hpp:49
uhal::DerivedNodeFactory::DerivedNodeFactory
DerivedNodeFactory()
Default constructor This is private since only a single instance is to be created,...
Definition: DerivedNodeFactory.cpp:53
uhal::Node
A heirarchical node for navigating heirarchical firmwares.
Definition: Node.hpp:86
log_inserters.quote.hpp
uhal::log
void log(FatalLevel &aFatal, const T0 &aArg0)
Function to add a log entry at Fatal level.
Definition: log.hxx:20
uhal::Warning
WarningLevel Warning
Definition: LogLevels.cpp:79
uhal::Quote
_Quote< T > Quote(const T &aT)
Definition: log_inserters.quote.hxx:49
uhal::Node::mClassName
std::string mClassName
Class name used to construct the derived node type.
Definition: Node.hpp:363
uhal::DerivedNodeFactory::convertToClassType
Node * convertToClassType(Node *aNode)
Definition: DerivedNodeFactory.cpp:74
uhal::DerivedNodeFactory::~DerivedNodeFactory
virtual ~DerivedNodeFactory()
Destructor.
Definition: DerivedNodeFactory.cpp:58
DerivedNodeFactory.hpp
log.hpp
LogLevels.hpp
uhal::DerivedNodeFactory::getInstance
static DerivedNodeFactory & getInstance()
Static method to retrieve the single instance of the class.
Definition: DerivedNodeFactory.cpp:63
uhal::DerivedNodeFactory::mCreators
boost::unordered_map< std::string, boost::shared_ptr< CreatorInterface > > mCreators
Hash map associating a creator for a particular node type with a string identifier for that node type...
Definition: DerivedNodeFactory.hpp:160