bes Updated for version 3.21.1
The Backend Server (BES) is the lower two tiers of the Hyrax data server
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 <memory>
41
42#include "BESPlugin.h"
43
44#include "BESObj.h"
45
54
55template<typename C>
56class BESPluginFactory : public BESObj {
57 std::map<std::string, std::unique_ptr<BESPlugin<C>> > d_children;
58
59public:
60 BESPluginFactory() = default;
61
68 BESPluginFactory(const std::string &name, const std::string &library_name) {
69 add_mapping(name, library_name);
70 }
71
72 BESPluginFactory(const BESPluginFactory &) = delete;
73
74 ~BESPluginFactory() override = default;
75
76 const BESPluginFactory &operator=(const BESPluginFactory &) = delete;
77
83 void add_mapping(const std::string &name, const std::string &library_name) {
84 d_children.emplace(name, std::make_unique<BESPlugin<C>>(library_name));
85 }
86
99 C *get(const std::string &name) {
100 auto plugin_it = d_children.find(name);
101 if (plugin_it == d_children.end()) {
102 throw NoSuchObject(std::string("No class is bound to ") + name, __FILE__, __LINE__);
103 }
104 return plugin_it->second->instantiate();
105 }
106
107 void dump(std::ostream &strm) const override {
108 strm << "BESPluginFactory::dump - (" << std::ios::hex << this << ")" << std::endl;
109 }
110};
111
112#endif //plugin_h
top level BES object to house generic methods
Definition BESObj.h:54
BESPluginFactory(const std::string &name, const std::string &library_name)
void add_mapping(const std::string &name, const std::string &library_name)
C * get(const std::string &name)
void dump(std::ostream &strm) const override
dump the contents of this object to the specified ostream