bes  Updated for version 3.19.1
BESPluginFactory.h
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 {
63 private:
64  map<string, BESPlugin<C> *> d_children;
65 
72  // I just removed these impls entirely. jhrg 5/13/15
73  BESPluginFactory(const BESPluginFactory &); // throw (BESInternalError)
74 #if 0
75  {
76  throw BESInternalError("Unimplemented method.", __FILE__, __LINE__);
77  }
78 #endif
79 
83  const BESPluginFactory &operator=(const BESPluginFactory &); // throw (BESInternalError)
84 #if 0
85  {
86  throw BESInternalError("Unimplemented method.", __FILE__, __LINE__);
87  }
88 #endif
89 
90  struct DeletePlugins: public unary_function<pair<string, BESPlugin<C> *>, void>
91  {
92 
93  void operator()(pair<string, BESPlugin<C> *> elem)
94  {
95  delete elem.second;
96  }
97  };
98 
99 public:
109  BESPluginFactory(const string &name, const string &library_name)
110  {
111  add_mapping(name, library_name);
112  }
113 
117  {
118  }
119 
120  virtual ~BESPluginFactory()
121  {
122  for_each(d_children.begin(), d_children.end(), DeletePlugins());
123  }
124 
130  void add_mapping(const string &name, const string &library_name)
131  {
132  BESPlugin<C> *child_class = new BESPlugin<C>(library_name);
133  d_children.insert(std::make_pair(name, child_class));
134  }
135 
151  C *get(const string &name) throw (NoSuchObject, NoSuchLibrary)
152  {
153  BESPlugin<C> *child_implementation = d_children[name];
154  if (!child_implementation) throw NoSuchObject(string("No class is bound to ") + name, __FILE__, __LINE__);
155  return child_implementation->instantiate();
156  }
157 
158  virtual void dump(ostream &strm) const
159  {
160  strm << "BESPluginFactory::dump - (" << (void *) this << ")" << endl;
161  /*
162  typedef map<string, BESPlugin<C> *>::const_iterator Plugin_citer ;
163  BESPluginFactory::Plugin_citer i = d_children.begin() ;
164  BESPluginFactory::Plugin_citer ie = d_children.end() ;
165  for( ; i != ie; i++ )
166  {
167  strm << i.second ;
168  }
169  */
170  }
171 };
172 
173 #endif //plugin_h
exception thrown if inernal error encountered
M * instantiate()
Definition: BESPlugin.h:173
Base object for bes objects.
Definition: BESObj.h:52
BESPluginFactory(const string &name, const string &library_name)
virtual void dump(ostream &strm) const
dump the contents of this object to the specified ostream
C * get(const string &name)
void add_mapping(const string &name, const string &library_name)