μHAL (v2.7.9)
Part of the IPbus software repository
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 <string>
45 
46 #include <boost/noncopyable.hpp>
47 #include <boost/shared_ptr.hpp>
48 #include <boost/unordered_map.hpp>
49 
50 
51 namespace boost {
52  template <class Y> class shared_ptr;
53 }
54 
55 namespace uhal
56 {
57  class Node;
58  class NodeTreeBuilder; // IWYU pragma: keep
59 
61  template< typename T > struct RegistrationHelper; // IWYU pragma: keep
62 
63 
68  class DerivedNodeFactory: private boost::noncopyable
69  {
70  friend class NodeTreeBuilder;
71 
72  public:
73 
75  template< typename T > friend struct RegistrationHelper;
76 
77  private:
83 
84  public:
86  virtual ~DerivedNodeFactory ();
87 
93 
94 
95  private:
96 
97  Node* convertToClassType( Node* aNode );
98 
103  template <class T>
104  void add ( const std::string& aNodeClassName );
105 
106 
109  {
110  public:
113  {
114  }
115 
118  {
119  }
120 
126  virtual Node* create ( const Node& aNode ) = 0;
127  };
128 
129 
131  template <class T>
132  class Creator: public CreatorInterface
133  {
134  public:
135 
138  {
139  }
140 
142  virtual ~Creator()
143  {
144  }
145 
151  Node* create ( const Node& aNode );
152  };
153 
154 
155  private:
158 
160  boost::unordered_map< std::string , boost::shared_ptr< CreatorInterface > > mCreators;
161  };
162 }
163 
165 
166 #endif
uhal::DerivedNodeFactory::CreatorInterface::~CreatorInterface
virtual ~CreatorInterface()
Destructor.
Definition: DerivedNodeFactory.hpp:117
uhal::DerivedNodeFactory::add
void add(const std::string &aNodeClassName)
Method to create an associate between a node type identifier and a Creator of that particular node ty...
Definition: DerivedNodeFactory.hxx:44
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
uhal::DerivedNodeFactory::CreatorInterface::create
virtual Node * create(const Node &aNode)=0
Interface to a function which create a new derived node class based on the class name.
boost
Definition: log.hpp:13
uhal::DerivedNodeFactory::Creator::~Creator
virtual ~Creator()
Destructor.
Definition: DerivedNodeFactory.hpp:142
uhal::DerivedNodeFactory::Creator
Templated concrete implementation with a CreatorInterface interface.
Definition: DerivedNodeFactory.hpp:133
uhal::DerivedNodeFactory
A singleton class to register derived nodes, and create instances of them later NOTE!...
Definition: DerivedNodeFactory.hpp:69
uhal::RegistrationHelper
Experimental!! Helper struct for adding the DerivedNode to the Node Factory Declaring an instance of ...
Definition: DerivedNode.hpp:83
uhal::NodeTreeBuilder
A class to build a node tree from an Address table file NOTE! This is a factory method and must be Mu...
Definition: NodeTreeBuilder.hpp:88
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
uhal::DerivedNodeFactory::CreatorInterface::CreatorInterface
CreatorInterface()
Default constructor.
Definition: DerivedNodeFactory.hpp:112
uhal::DerivedNodeFactory::Creator::create
Node * create(const Node &aNode)
Concrete function which creates a new IPbus client based on the protocol identifier specified.
Definition: DerivedNodeFactory.hxx:59
uhal::DerivedNodeFactory::convertToClassType
Node * convertToClassType(Node *aNode)
Definition: DerivedNodeFactory.cpp:74
uhal::DerivedNodeFactory::~DerivedNodeFactory
virtual ~DerivedNodeFactory()
Destructor.
Definition: DerivedNodeFactory.cpp:58
DerivedNodeFactory.hxx
uhal::DerivedNodeFactory::getInstance
static DerivedNodeFactory & getInstance()
Static method to retrieve the single instance of the class.
Definition: DerivedNodeFactory.cpp:63
uhal::DerivedNodeFactory::CreatorInterface
An abstract base class for defining the interface to the creators.
Definition: DerivedNodeFactory.hpp:109
uhal::DerivedNodeFactory::Creator::Creator
Creator()
Default constructor.
Definition: DerivedNodeFactory.hpp:137
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