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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 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 private:
63  map<string, BESPlugin<C> *> d_children;
64 
72  {
73  throw BESInternalError("Unimplemented method.", __FILE__, __LINE__);
74  }
75 
79  const BESPluginFactory &operator=(const BESPluginFactory &rhs) throw (BESInternalError)
80  {
81  throw BESInternalError("Unimplemented method.", __FILE__, __LINE__);
82  }
83 
84  struct DeletePlugins: public unary_function<pair<string, BESPlugin<C> *>, void> {
85 
86  void operator()(pair<string, BESPlugin<C> *> elem)
87  {
88  delete elem.second;
89  }
90  };
91 
92 public:
102  BESPluginFactory(const string &name, const string &library_name)
103  {
104  add_mapping(name, library_name);
105  }
106 
110  {
111  }
112 
114  {
115  for_each(d_children.begin(), d_children.end(), DeletePlugins());
116  }
117 
123  void add_mapping(const string &name, const string &library_name)
124  {
125  BESPlugin<C> *child_class = new BESPlugin<C>(library_name);
126  d_children.insert(std::make_pair(name, child_class));
127  }
128 
144  C *get(const string &name) throw (NoSuchObject, NoSuchLibrary)
145  {
146  BESPlugin<C> *child_implementation = d_children[name];
147  if (!child_implementation) throw NoSuchObject(string("No class is bound to ") + name, __FILE__, __LINE__);
148  return child_implementation->instantiate();
149  }
150 
151  virtual void dump(ostream &strm) const
152  {
153  strm << "BESPluginFactory::dump - (" << (void *) this << ")" << endl;
154  /*
155  typedef map<string, BESPlugin<C> *>::const_iterator Plugin_citer ;
156  BESPluginFactory::Plugin_citer i = d_children.begin() ;
157  BESPluginFactory::Plugin_citer ie = d_children.end() ;
158  for( ; i != ie; i++ )
159  {
160  strm << i.second ;
161  }
162  */
163  }
164 };
165 
166 #endif //plugin_h
exception thrown if inernal error encountered
Thrown as an exception when BESPlugin cannot find the named shareable library.
Definition: BESPlugin.h:56
Thrown as an exception when BESPlugin cannot find or run the maker() function in a shared library alr...
Definition: BESPlugin.h:67
BESPluginFactory()
Create an empty BESPluginFactory.
M * instantiate()
Instantiate the object.
Definition: BESPlugin.h:167
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 ~BESPluginFactory()
A Factory for objects whose implementations reside in shared objects designed to be loaded at run tim...
virtual void dump(ostream &strm) const
dump the contents of this object to the specified ostream
void add_mapping(const string &name, const string &library_name)
Add a mapping of name to library_name to the BESPluginFactory.