libdap Updated for version 3.21.0
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 <algorithm>
34#include <iostream>
35
36// #define DODS_DEBUG
37
38#include "debug.h"
39#include <expr.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."
58 << endl);
59 d_instance = new ServerFunctionsList;
60#if HAVE_ATEXIT
61 atexit(delete_instance);
62#endif
63 }
64}
65
69void ServerFunctionsList::delete_instance() {
70 DBG(cerr << "ServerFunctionsList::delete_instance() - Deleting singleton ServerFunctionList instance." << endl);
71 delete d_instance;
72 d_instance = 0;
73}
74
78
79ServerFunctionsList::~ServerFunctionsList() {
80 SFLIter fit;
81 for (fit = d_func_list.begin(); fit != d_func_list.end(); fit++) {
82 ServerFunction *func = fit->second;
83 DBG(cerr << "ServerFunctionsList::~ServerFunctionsList() - Deleting ServerFunction " << func->getName()
84 << " from ServerFunctionsList." << endl);
85 delete func;
86 }
87 d_func_list.clear();
88}
89
90ServerFunctionsList *ServerFunctionsList::TheList() {
91 pthread_once(&ServerFunctionsList_instance_control, initialize_instance);
92 DBG(cerr << "ServerFunctionsList::TheList() - Returning singleton ServerFunctionList instance." << endl);
93 return d_instance;
94}
95
106 DBG(cerr << "ServerFunctionsList::add_function() - Adding ServerFunction " << func->getName() << endl);
107 d_func_list.insert(std::make_pair(func->getName(), func));
108}
109
130bool ServerFunctionsList::find_function(const std::string &name, bool_func *f) const {
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 if (d_func_list.empty())
168 return false;
169 DBG(cerr << "ServerFunctionsList::find_function() - Looking for ServerFunction '" << name << "'" << endl);
170
171 std::pair<SFLCIter, SFLCIter> ret;
172 ret = d_func_list.equal_range(name);
173 for (SFLCIter it = ret.first; it != ret.second; ++it) {
174 if (name == it->first && it->second->get_btp_func()) {
175 *f = it->second->get_btp_func();
176 return true;
177 }
178 }
179
180 return false;
181}
182
203bool ServerFunctionsList::find_function(const string &name, proj_func *f) const {
204 if (d_func_list.empty())
205 return false;
206
207 std::pair<SFLCIter, SFLCIter> ret;
208 ret = d_func_list.equal_range(name);
209 for (SFLCIter it = ret.first; it != ret.second; ++it) {
210 if (name == it->first && it->second->get_proj_func()) {
211 *f = it->second->get_proj_func();
212 return true;
213 }
214 }
215
216 return false;
217}
218
226bool ServerFunctionsList::find_function(const string &name, D4Function *f) const {
227 if (d_func_list.empty())
228 return false;
229
230 std::pair<SFLCIter, SFLCIter> ret;
231 ret = d_func_list.equal_range(name);
232 for (SFLCIter it = ret.first; it != ret.second; ++it) {
233 if (name == it->first && it->second->get_d4_function()) {
234 *f = it->second->get_d4_function();
235 return true;
236 }
237 }
238
239 return false;
240}
241
243ServerFunctionsList::SFLIter ServerFunctionsList::begin() { return d_func_list.begin(); }
244
246ServerFunctionsList::SFLIter ServerFunctionsList::end() { return d_func_list.end(); }
247
254ServerFunction *ServerFunctionsList::getFunction(SFLIter it) { return (*it).second; }
255
256void ServerFunctionsList::getFunctionNames(vector<string> *names) {
257 SFLIter fit;
258 for (fit = d_func_list.begin(); fit != d_func_list.end(); fit++) {
259 ServerFunction *func = fit->second;
260 names->push_back(func->getName());
261 }
262}
263
264} // 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 AISConnect.cc:30