libdap Updated for version 3.20.11
libdap4 is an implementation of OPeNDAP's DAP protocol.
ServerFunctionsList.cc
1// ServerFunctionsList.cc
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) 2013 OPeNDAP, Inc.
7// Author: James Gallagher <jgallagher@opendap.org>
8//
9// This library is free software; you can redistribute it and/or
10// modify it under the terms of the GNU Lesser General Public
11// License as published by the Free Software Foundation; either
12// version 2.1 of the License, or (at your option) any later version.
13//
14// This library is distributed in the hope that it will be useful,
15// but WITHOUT ANY WARRANTY; without even the implied warranty of
16// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17// Lesser General Public License for more details.
18//
19// You should have received a copy of the GNU Lesser General Public
20// License along with this library; if not, write to the Free Software
21// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
22//
23// You can contact OPeNDAP, Inc. at PO Box 112, Saunderstown, RI. 02874-0112.
24
25#include "config.h"
26
27#ifdef HAVE_STDLIB_H
28#include <stdlib.h>
29#endif
30
31#include <pthread.h>
32
33#include <iostream>
34#include <algorithm>
35
36//#define DODS_DEBUG
37
38#include <expr.h>
39#include "debug.h"
40
41#include "ServerFunctionsList.h"
42
43using namespace std;
44using namespace libdap;
45
46namespace libdap {
47
48static pthread_once_t ServerFunctionsList_instance_control = PTHREAD_ONCE_INIT;
49
50ServerFunctionsList *ServerFunctionsList::d_instance = 0 ;
51
55void ServerFunctionsList::initialize_instance() {
56 if (d_instance == 0) {
57 DBG(cerr << "ServerFunctionsList::initialize_instance() - Creating singleton ServerFunctionList instance." << endl);
58 d_instance = new ServerFunctionsList;
59 #if HAVE_ATEXIT
60 atexit(delete_instance);
61 #endif
62 }
63}
64
68void ServerFunctionsList::delete_instance() {
69 DBG(cerr << "ServerFunctionsList::delete_instance() - Deleting singleton ServerFunctionList instance." << endl);
70 delete d_instance;
71 d_instance = 0;
72}
73
78ServerFunctionsList::~ServerFunctionsList() {
79 SFLIter fit;
80 for(fit=d_func_list.begin(); fit!=d_func_list.end() ; fit++){
81 ServerFunction *func = fit->second;
82 DBG(cerr << "ServerFunctionsList::~ServerFunctionsList() - Deleting ServerFunction " << func->getName() << " from ServerFunctionsList." << endl);
83 delete func;
84 }
85 d_func_list.clear();
86}
87
88ServerFunctionsList * ServerFunctionsList::TheList() {
89 pthread_once(&ServerFunctionsList_instance_control, initialize_instance);
90 DBG(cerr << "ServerFunctionsList::TheList() - Returning singleton ServerFunctionList instance." << endl);
91 return d_instance;
92}
93
104{
105 DBG(cerr << "ServerFunctionsList::add_function() - Adding ServerFunction " << func->getName() << endl);
106 d_func_list.insert(std::make_pair(func->getName(),func));
107}
108
129bool ServerFunctionsList::find_function(const std::string &name, bool_func *f) const
130{
131 if (d_func_list.empty())
132 return false;
133
134 std::pair <SFLCIter, SFLCIter> ret;
135 ret = d_func_list.equal_range(name);
136 for (SFLCIter it = ret.first; it != ret.second; ++it) {
137 if (name == it->first && it->second->get_bool_func()) {
138 *f = it->second->get_bool_func();
139 return true;
140 }
141 }
142
143 return false;
144}
145
166bool ServerFunctionsList::find_function(const string &name, btp_func *f) const
167{
168 if (d_func_list.empty())
169 return false;
170 DBG(cerr << "ServerFunctionsList::find_function() - Looking for ServerFunction '" << name << "'" << endl);
171
172 std::pair <SFLCIter, SFLCIter> ret;
173 ret = d_func_list.equal_range(name);
174 for (SFLCIter it = ret.first; it != ret.second; ++it) {
175 if (name == it->first && it->second->get_btp_func()) {
176 *f = it->second->get_btp_func();
177 return true;
178 }
179 }
180
181 return false;
182}
183
204bool ServerFunctionsList::find_function(const string &name, proj_func *f) const
205{
206 if (d_func_list.empty())
207 return false;
208
209 std::pair <SFLCIter, SFLCIter> ret;
210 ret = d_func_list.equal_range(name);
211 for (SFLCIter it = ret.first; it != ret.second; ++it) {
212 if (name == it->first && it->second->get_proj_func()) {
213 *f = it->second->get_proj_func();
214 return true;
215 }
216 }
217
218 return false;
219}
220
228bool ServerFunctionsList::find_function(const string &name, D4Function *f) const
229{
230 if (d_func_list.empty())
231 return false;
232
233 std::pair <SFLCIter, SFLCIter> ret;
234 ret = d_func_list.equal_range(name);
235 for (SFLCIter it = ret.first; it != ret.second; ++it) {
236 if (name == it->first && it->second->get_d4_function()) {
237 *f = it->second->get_d4_function();
238 return true;
239 }
240 }
241
242 return false;
243}
244
246ServerFunctionsList::SFLIter ServerFunctionsList::begin()
247{
248 return d_func_list.begin();
249}
250
252ServerFunctionsList::SFLIter ServerFunctionsList::end()
253{
254 return d_func_list.end();
255}
256
264{
265 return (*it).second;
266}
267
268void ServerFunctionsList::getFunctionNames(vector<string> *names){
269 SFLIter fit;
270 for(fit = d_func_list.begin(); fit != d_func_list.end(); fit++) {
271 ServerFunction *func = fit->second;
272 names->push_back(func->getName());
273 }
274}
275
276} // namespace libdap
virtual bool find_function(const std::string &name, bool_func *f) const
Find a boolean function with a given name in the function list.
virtual void add_function(ServerFunction *func)
Adds the passed ServerFunction pointer to the list of ServerFunctions.
SFLIter begin()
Returns an iterator pointing to the first key pair in the ServerFunctionList.
SFLIter end()
Returns an iterator pointing to the last key pair in the ServerFunctionList.
ServerFunction * getFunction(SFLIter it)
Returns the ServerFunction pointed to by the passed iterator.
top level DAP object to house generic methods
Definition: AlarmHandler.h:36