bes Updated for version 3.20.13
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#include "BESObj.h"
45
55template<typename C>
57{
58private:
59 std::map<std::string, BESPlugin<C> *> d_children;
60
67 // I just removed these impls entirely. jhrg 5/13/15
68 BESPluginFactory(const BESPluginFactory &); // throw (BESInternalError)
69#if 0
70 {
71 throw BESInternalError("Unimplemented method.", __FILE__, __LINE__);
72 }
73#endif
74
78 const BESPluginFactory &operator=(const BESPluginFactory &); // throw (BESInternalError)
79#if 0
80 {
81 throw BESInternalError("Unimplemented method.", __FILE__, __LINE__);
82 }
83#endif
84
85 struct DeletePlugins: public std::unary_function<std::pair<std::string, BESPlugin<C> *>, void>
86 {
87
88 void operator()(std::pair<std::string, BESPlugin<C> *> elem)
89 {
90 delete elem.second;
91 }
92 };
93
94public:
104 BESPluginFactory(const std::string &name, const std::string &library_name)
105 {
106 add_mapping(name, library_name);
107 }
108
112 {
113 }
114
115 virtual ~BESPluginFactory()
116 {
117 for_each(d_children.begin(), d_children.end(), DeletePlugins());
118 }
119
125 void add_mapping(const std::string &name, const std::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 std::string &name) throw (NoSuchObject, NoSuchLibrary)
147 {
148 BESPlugin<C> *child_implementation = d_children[name];
149 if (!child_implementation) throw NoSuchObject(std::string("No class is bound to ") + name, __FILE__, __LINE__);
150 return child_implementation->instantiate();
151 }
152
153 virtual void dump(std::ostream &strm) const
154 {
155 strm << "BESPluginFactory::dump - (" << (void *) this << ")" << std::endl;
156 /*
157 typedef map<string, BESPlugin<C> *>::const_iterator Plugin_citer ;
158 BESPluginFactory::Plugin_citer i = d_children.begin() ;
159 BESPluginFactory::Plugin_citer ie = d_children.end() ;
160 for( ; i != ie; i++ )
161 {
162 strm << i.second ;
163 }
164 */
165 }
166};
167
168#endif //plugin_h
exception thrown if internal error encountered
top level BES object to house generic methods
Definition: BESObj.h:54
BESPluginFactory(const std::string &name, const std::string &library_name)
virtual void dump(std::ostream &strm) const
dump the contents of this object to the specified ostream
void add_mapping(const std::string &name, const std::string &library_name)
C * get(const std::string &name)
M * instantiate()
Definition: BESPlugin.h:169