OPeNDAP Hyrax Back End Server (BES)  Updated for version 3.8.3
BESPluginFactory.h
Go to the documentation of this file.
1 // BESPluginFactory.h
2 
3 // This file is part of bes, A C++ back-end server implementation framework
4 // for the OPeNDAP Data Access Protocol.
5 
6 // Copyright (c) 2004-2009 University Corporation for Atmospheric Research
7 // Author: Patrick West <pwest@ucar.edu> and Jose Garcia <jgarcia@ucar.edu>
8 // and James Gallagher <jgallagher@gso.uri.edu>
9 //
10 // This library is free software; you can redistribute it and/or
11 // modify it under the terms of the GNU Lesser General Public
12 // License as published by the Free Software Foundation; either
13 // version 2.1 of the License, or (at your option) any later version.
14 //
15 // This library 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 GNU
18 // Lesser General Public License for more details.
19 //
20 // You should have received a copy of the GNU Lesser General Public
21 // License along with this library; if not, write to the Free Software
22 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23 //
24 // You can contact University Corporation for Atmospheric Research at
25 // 3080 Center Green Drive, Boulder, CO 80301
26 
27 // (c) COPYRIGHT University Corporation for Atmospheric Research 2004-2005
28 // Please read the full copyright statement in the file COPYRIGHT_UCAR.
29 //
30 // Authors:
31 // pwest Patrick West <pwest@ucar.edu>
32 // jgarcia Jose Garcia <jgarcia@ucar.edu>
33 // jimg James Gallagher <jgallagher@gso.uri.edu>
34 
35 #ifndef plugin_factory_h
36 #define plugin_factory_h
37 
38 #include <string>
39 #include <map>
40 #include <algorithm>
41 
42 #include "BESPlugin.h"
43 
44 using std::string;
45 using std::map;
46 using std::pair;
47 using std::unary_function;
48 
49 #include "BESObj.h"
50 
60 template<typename C>
61 class BESPluginFactory : public BESObj
62 {
63 private:
64  map<string, BESPlugin<C> *> d_children;
65 
73  throw(BESInternalError)
74  {
75  throw BESInternalError( "Unimplemented method.");
76  }
77 
81  const BESPluginFactory &operator=(const BESPluginFactory &rhs)
82  throw (BESInternalError)
83  {
84  throw BESInternalError( "Unimplemented method.");
85  }
86 
87  struct DeletePlugins
88  : public unary_function<pair<string, BESPlugin<C> *>, void>
89  {
90 
91  void operator()(pair<string, BESPlugin<C> *> elem) {
92  delete elem.second;
93  }
94  };
95 
96 public:
106  BESPluginFactory(const string &name, const string &library_name)
107  {
108  add_mapping(name, library_name);
109  }
110 
114 
116  {
117  for_each(d_children.begin(), d_children.end(), DeletePlugins());
118  }
119 
125  void add_mapping(const string &name, const string &library_name)
126  {
127  BESPlugin<C> *child_class = new BESPlugin<C>(library_name);
128  d_children.insert(std::make_pair(name, child_class));
129  }
130 
146  C *get(const string &name) throw(NoSuchObject, NoSuchLibrary)
147  {
148  BESPlugin<C> *child_implementation = d_children[name];
149  if (!child_implementation)
150  throw NoSuchObject(string("No class is bound to ") + name, __FILE__, __LINE__ );
151  return child_implementation->instantiate();
152  }
153 
154  virtual void dump( ostream &strm ) const
155  {
156  strm << "BESPluginFactory::dump - (" << (void *)this << ")" << endl ;
157  /*
158  typedef map<string, BESPlugin<C> *>::const_iterator Plugin_citer ;
159  BESPluginFactory::Plugin_citer i = d_children.begin() ;
160  BESPluginFactory::Plugin_citer ie = d_children.end() ;
161  for( ; i != ie; i++ )
162  {
163  strm << i.second ;
164  }
165  */
166  }
167 };
168 
169 #endif //plugin_h
170 
exception thrown if inernal error encountered
Thrown as an exception when BESPlugin cannot find the named shareable library.
Definition: BESPlugin.h:53
Thrown as an exception when BESPlugin cannot find or run the maker() function in a shared library alr...
Definition: BESPlugin.h:63
BESPluginFactory()
Create an empty BESPluginFactory.
M * instantiate()
Instantiate the object.
Definition: BESPlugin.h:152
Base object for bes objects.
Definition: BESObj.h:52
BESPluginFactory(const string &name, const string &library_name)
Create a BESPluginFactory and set up a single entry.
virtual void dump(ostream &strm) const
dump the contents of this object to the specified ostream
virtual ~BESPluginFactory()
A Factory for objects whose implementations reside in shared objects designed to be loaded at run tim...
void add_mapping(const string &name, const string &library_name)
Add a mapping of name to library_name to the BESPluginFactory.