ServerFunctionsList.cc
// ServerFunctionsList.cc
// This file is part of bes, A C++ back-end server implementation framework
// for the OPeNDAP Data Access Protocol.
// Copyright (c) 2013 OPeNDAP, Inc.
// Author: James Gallagher <jgallagher@opendap.org>
//
// This library is free software; you can redistribute it and/or
// modify it under the terms of the GNU Lesser General Public
// License as published by the Free Software Foundation; either
// version 2.1 of the License, or (at your option) any later version.
//
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
// Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public
// License along with this library; if not, write to the Free Software
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
//
// You can contact OPeNDAP, Inc. at PO Box 112, Saunderstown, RI. 02874-0112.
#include "config.h"
#ifdef HAVE_STDLIB_H
#include <stdlib.h>
#endif
#include <pthread.h>
#include <iostream>
#include <algorithm>
//#define DODS_DEBUG
#include <expr.h>
#include "debug.h"
#include "ServerFunctionsList.h"
using namespace std;
using namespace libdap;
namespace libdap {
static pthread_once_t ServerFunctionsList_instance_control = PTHREAD_ONCE_INIT;
ServerFunctionsList *ServerFunctionsList::d_instance = 0 ;
void ServerFunctionsList::initialize_instance() {
if (d_instance == 0) {
DBG(cerr << "ServerFunctionsList::initialize_instance() - Creating singleton ServerFunctionList instance." << endl);
d_instance = new ServerFunctionsList;
#if HAVE_ATEXIT
atexit(delete_instance);
#endif
}
}
void ServerFunctionsList::delete_instance() {
DBG(cerr << "ServerFunctionsList::delete_instance() - Deleting singleton ServerFunctionList instance." << endl);
delete d_instance;
d_instance = 0;
}
ServerFunctionsList::~ServerFunctionsList() {
SFLIter fit;
for(fit=d_func_list.begin(); fit!=d_func_list.end() ; fit++){
ServerFunction *func = fit->second;
DBG(cerr << "ServerFunctionsList::~ServerFunctionsList() - Deleting ServerFunction " << func->getName() << " from ServerFunctionsList." << endl);
delete func;
}
d_func_list.clear();
}
ServerFunctionsList * ServerFunctionsList::TheList() {
pthread_once(&ServerFunctionsList_instance_control, initialize_instance);
DBG(cerr << "ServerFunctionsList::TheList() - Returning singleton ServerFunctionList instance." << endl);
return d_instance;
}
void ServerFunctionsList::add_function(ServerFunction *func )
{
DBG(cerr << "ServerFunctionsList::add_function() - Adding ServerFunction " << func->getName() << endl);
d_func_list.insert(std::make_pair(func->getName(),func));
}
bool ServerFunctionsList::find_function(const std::string &name, bool_func *f) const
{
if (d_func_list.empty())
return false;
std::pair <SFLCIter, SFLCIter> ret;
ret = d_func_list.equal_range(name);
for (SFLCIter it = ret.first; it != ret.second; ++it) {
if (name == it->first && (*f = it->second->get_bool_func())){
DBG(cerr << "ServerFunctionsList::find_function() - Found boolean function " << it->second->getName() << endl);
return true;
}
}
return false;
}
bool ServerFunctionsList::find_function(const string &name, btp_func *f) const
{
if (d_func_list.empty())
return false;
DBG(cerr << "ServerFunctionsList::find_function() - Looking for ServerFunction '" << name << "'" << endl);
std::pair <SFLCIter, SFLCIter> ret;
ret = d_func_list.equal_range(name);
for (SFLCIter it = ret.first; it != ret.second; ++it) {
if (name == it->first && (*f = it->second->get_btp_func())){
DBG(cerr << "ServerFunctionsList::find_function() - Found basetype function " << it->second->getName() << endl);
return true;
}
}
return false;
}
bool ServerFunctionsList::find_function(const string &name, proj_func *f) const
{
if (d_func_list.empty())
return false;
std::pair <SFLCIter, SFLCIter> ret;
ret = d_func_list.equal_range(name);
for (SFLCIter it = ret.first; it != ret.second; ++it) {
if (name == it->first && (*f = it->second->get_proj_func())){
DBG(cerr << "ServerFunctionsList::find_function() - Found projection function " << it->second->getName() << endl);
return true;
}
}
return false;
}
bool ServerFunctionsList::find_function(const string &name, D4Function *f) const
{
if (d_func_list.empty())
return false;
std::pair <SFLCIter, SFLCIter> ret;
ret = d_func_list.equal_range(name);
for (SFLCIter it = ret.first; it != ret.second; ++it) {
if (name == it->first && (*f = it->second->get_d4_function())) {
return true;
}
}
return false;
}
ServerFunctionsList::SFLIter ServerFunctionsList::begin()
{
return d_func_list.begin();
}
ServerFunctionsList::SFLIter ServerFunctionsList::end()
{
return d_func_list.end();
}
ServerFunction *ServerFunctionsList::getFunction(SFLIter it)
{
return (*it).second;
}
void ServerFunctionsList::getFunctionNames(vector<string> *names){
SFLIter fit;
for(fit = d_func_list.begin(); fit != d_func_list.end(); fit++) {
ServerFunction *func = fit->second;
names->push_back(func->getName());
}
}
} // namespace libdap
libdap
top level DAP object to house generic methods
Definition: AlarmHandler.h:35
libdap::ServerFunctionsList
Definition: ServerFunctionsList.h:46
libdap::ServerFunction
Definition: ServerFunction.h:42