<commit_before>// 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: <NAME> <<EMAIL>>
//
// 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., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
//
// You can contact OPeNDAP, Inc. at PO Box 112, Saunderstown, RI. 02874-0112.

#include <iostream>
#include <algorithm>

#define DODS_DEBUG

#include <expr.h>
#include "debug.h"

#include "ServerFunctionsList.h"

using std::cerr;
using std::string;
using std::endl;
using namespace std;
using namespace libdap;



namespace libdap {

ServerFunctionsList *ServerFunctionsList::d_instance = 0 ;

/**
 * private static that only gets called once in the life cycle of the process.
 */
void ServerFunctionsList::initialize_instance() {
    if (d_instance == 0) {
        DBG(cerr << "ServerFunctionsList::initialize_instance() - Creating singleton ServerFunctionList instance." << endl);
        d_instance = new ServerFunctionsList;
        atexit(delete_instance);
    }
}

/**
 * Private static function can only be called by friends andf pThreads code.
 */
void ServerFunctionsList::delete_instance() {
    delete d_instance;
    d_instance = 0;
}

/**
 * Private method insures that nobody can try to delete the singleton class.
 */

ServerFunctionsList::~ServerFunctionsList() {
    std::multimap<string,libdap::ServerFunction *>::iterator fit;
    for(fit=d_func_list.begin(); fit!=d_func_list.end() ; fit++){
        libdap::ServerFunction *func = fit->second;
        DBG(cerr << "ServerFunctionsList::~ServerFunctionsList() - Deleting ServerFunction " << func->getName() << " from ServerFunctionsList." << endl);
        delete func;
    }
    d_func_list.clear();
}



ServerFunctionsList * ServerFunctionsList::TheList() {
    initialize_instance();
    return d_instance;
}




/**
 * Adds the passed ServerFunction pointer to the list of ServerFunctions using
 * the value of ServerFunction.getName() as the key in the list.
 *
 * @brief Adds the passed ServerFunction pointer to the list of ServerFunctions.<commit_msg>libdap: Added instrumentation (enabled in this check in) to ServerFunctionsList in an effort to understand the seg fault problem that seems to be associated with server side function calls.<commit_after>// 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: <NAME> <<EMAIL>>
//
// 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., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
//
// You can contact OPeNDAP, Inc. at PO Box 112, Saunderstown, RI. 02874-0112.

#include <iostream>
#include <algorithm>

#define DODS_DEBUG

#include <expr.h>
#include "debug.h"

#include "ServerFunctionsList.h"

using std::cerr;
using std::string;
using std::endl;
using namespace std;
using namespace libdap;



namespace libdap {

ServerFunctionsList *ServerFunctionsList::d_instance = 0 ;

/**
 * private static that only gets called once in the life cycle of the process.
 */
void ServerFunctionsList::initialize_instance() {
    if (d_instance == 0) {
        DBG(cerr << "ServerFunctionsList::initialize_instance() - Creating singleton ServerFunctionList instance." << endl);
        d_instance = new ServerFunctionsList;
        atexit(delete_instance);
    }
}

/**
 * Private static function can only be called by friends andf pThreads code.
 */
void ServerFunctionsList::delete_instance() {
    DBG(cerr << "ServerFunctionsList::delete_instance() - Deleting singleton ServerFunctionList instance." << endl);
    delete d_instance;
    d_instance = 0;
}

/**
 * Private method insures that nobody can try to delete the singleton class.
 */

ServerFunctionsList::~ServerFunctionsList() {
    std::multimap<string,libdap::ServerFunction *>::iterator fit;
    for(fit=d_func_list.begin(); fit!=d_func_list.end() ; fit++){
        libdap::ServerFunction *func = fit->second;
        DBG(cerr << "ServerFunctionsList::~ServerFunctionsList() - Deleting ServerFunction " << func->getName() << " from ServerFunctionsList." << endl);
        delete func;
    }
    d_func_list.clear();
}



ServerFunctionsList * ServerFunctionsList::TheList() {
    initialize_instance();
    DBG(cerr << "ServerFunctionsList::TheList() - Returning singleton ServerFunctionList instance." << endl);
    return d_instance;
}




/**
 * Adds the passed ServerFunction pointer to the list of ServerFunctions using
 * the value of ServerFunction.getName() as the key in the list.
 *
 * @brief Adds the passed ServerFunction pointer to the list of ServerFunctions.
{'fraction_non_alphanumeric': 0.10078424828967128, 'fraction_numerical': 0.011680293675955281, 'mean_word_length': 3.978405315614618, 'pattern_counts': {'":': 0, '<': 49, '<?xml version=': 0, '>': 21, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5248707', 'n_tokens_mistral': 1702, 'n_tokens_neox': 1626, 'n_words': 647}