μHAL (v2.6.5)
Part of the IPbus software repository
ClientFactory.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_ClientFactory_hpp_
41 #define _uhal_ClientFactory_hpp_
42 
43 #include "uhal/log/exception.hpp"
44 #include "uhal/ClientInterface.hpp"
45 #include "uhal/log/log.hpp"
46 
47 #include <boost/noncopyable.hpp>
48 #include <boost/shared_ptr.hpp>
49 #include <boost/unordered_map.hpp>
50 
51 #include <map>
52 
53 
54 namespace uhal
55 {
56  namespace exception
57  {
58  // //! Exception class to handle the case where a protocol already exists in the creator map. Uses the base uhal::exception implementation of what()
59  // class ProtocolAlreadyExist : public exception {};
61  UHAL_DEFINE_EXCEPTION_CLASS ( ProtocolDoesNotExist , "Exception class to handle the case where the protocol requested does not exists in the creator map." )
62 
63 
64  UHAL_DEFINE_EXCEPTION_CLASS ( FailedToParseURI , "Exception class to handle the case where the factory failed to parse URI." )
65  }
66 
72  class ClientFactory: private boost::noncopyable
73  {
74 
75  private:
80  ClientFactory();
81 
85  virtual ~ClientFactory();
86 
87  public:
92  static ClientFactory& getInstance();
93 
99  template <class T>
100  void add ( const std::string& aProtocol , const std::string& aDescription = "" );
101 
108  boost::shared_ptr<ClientInterface> getClient ( const std::string& aId , const std::string& aUri );
109 
110  private:
113  {
114  public:
119  {
120  }
125  {
126  }
133  virtual boost::shared_ptr<ClientInterface> create ( const std::string& aId , const URI& aUri ) = 0;
134  };
135 
137  template <class T>
138  class Creator: public CreatorInterface
139  {
140  public:
141 
146  {
147  }
151  virtual ~Creator()
152  {
153  }
160  boost::shared_ptr<ClientInterface> create ( const std::string& aId , const URI& aUri );
161  };
162 
163 
164  private:
168  boost::unordered_map< std::string , boost::shared_ptr< CreatorInterface > > mCreators; //map string name of each protocol to a creator for that protocol
170  std::map< std::string , std::string > mProductDescriptions;
171 
172  };
173 
174 }
175 
177 
178 #endif
CreatorInterface()
Default constructor.
std::map< std::string, std::string > mProductDescriptions
Store the description of the factory product.
#define UHAL_DEFINE_EXCEPTION_CLASS(ClassName, ClassDescription)
Definition: exception.hpp:64
Creator()
Default constructor.
Templated concrete implementation with a CreatorInterface interface.
An abstract base class for defining the interface to the creators.
A class to construct an IPbus client based on the protocol identifier specified NOTE! This is a facto...
virtual ~Creator()
Destructor.
boost::unordered_map< std::string, boost::shared_ptr< CreatorInterface > > mCreators
Hash map associating a creator for a particular protocol with a file name.
Struct to store a URI when parsed by boost spirit.
Definition: URI.hpp:49
static ClientFactory * mInstance
The single instance of the class.