00001 // BESAggFactory.cc 00002 00003 // This file is part of bes, A C++ back-end server implementation framework 00004 // for the OPeNDAP Data Access Protocol. 00005 00006 // Copyright (c) 2004,2005 University Corporation for Atmospheric Research 00007 // Author: Patrick West <pwest@ucar.edu> and Jose Garcia <jgarcia@ucar.edu> 00008 // 00009 // This library is free software; you can redistribute it and/or 00010 // modify it under the terms of the GNU Lesser General Public 00011 // License as published by the Free Software Foundation; either 00012 // version 2.1 of the License, or (at your option) any later version. 00013 // 00014 // This library is distributed in the hope that it will be useful, 00015 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00016 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00017 // Lesser General Public License for more details. 00018 // 00019 // You should have received a copy of the GNU Lesser General Public 00020 // License along with this library; if not, write to the Free Software 00021 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 00022 // 00023 // You can contact University Corporation for Atmospheric Research at 00024 // 3080 Center Green Drive, Boulder, CO 80301 00025 00026 // (c) COPYRIGHT University Corporation for Atmospheric Research 2004-2005 00027 // Please read the full copyright statement in the file COPYRIGHT_UCAR. 00028 // 00029 // Authors: 00030 // pwest Patrick West <pwest@ucar.edu> 00031 // jgarcia Jose Garcia <jgarcia@ucar.edu> 00032 00033 #include "BESAggFactory.h" 00034 00035 BESAggFactory *BESAggFactory::_instance = 0 ; 00036 00047 bool 00048 BESAggFactory::add_handler( string handler_name, 00049 p_agg_handler handler_method ) 00050 { 00051 BESAggFactory::Handler_citer i ; 00052 i = _handler_list.find( handler_name ) ; 00053 if( i == _handler_list.end() ) 00054 { 00055 _handler_list[handler_name] = handler_method ; 00056 return true ; 00057 } 00058 return false ; 00059 } 00060 00070 bool 00071 BESAggFactory::remove_handler( string handler_name ) 00072 { 00073 BESAggFactory::Handler_iter i ; 00074 i = _handler_list.find( handler_name ) ; 00075 if( i != _handler_list.end() ) 00076 { 00077 _handler_list.erase( i ) ; 00078 return true ; 00079 } 00080 return false ; 00081 } 00082 00095 BESAggregationServer * 00096 BESAggFactory::find_handler( string handler_name ) 00097 { 00098 BESAggFactory::Handler_citer i ; 00099 i = _handler_list.find( handler_name ) ; 00100 if( i != _handler_list.end() ) 00101 { 00102 p_agg_handler p = (*i).second ; 00103 if( p ) 00104 { 00105 return p( handler_name ) ; 00106 } 00107 } 00108 return 0 ; 00109 } 00110 00119 string 00120 BESAggFactory::get_handler_names() 00121 { 00122 string ret ; 00123 bool first_name = true ; 00124 BESAggFactory::Handler_citer i = _handler_list.begin() ; 00125 for( ; i != _handler_list.end(); i++ ) 00126 { 00127 if( !first_name ) 00128 ret += ", " ; 00129 ret += (*i).first ; 00130 first_name = false ; 00131 } 00132 return ret ; 00133 } 00134 00142 void 00143 BESAggFactory::dump( ostream &strm ) const 00144 { 00145 strm << BESIndent::LMarg << "BESAggFactory::dump - (" 00146 << (void *)this << ")" << endl ; 00147 BESIndent::Indent() ; 00148 if( _handler_list.size() ) 00149 { 00150 strm << BESIndent::LMarg << "registered agg handlers:" << endl ; 00151 BESIndent::Indent() ; 00152 BESAggFactory::Handler_citer i = _handler_list.begin() ; 00153 for( ; i != _handler_list.end(); i++ ) 00154 { 00155 strm << BESIndent::LMarg << (*i).first << endl ; 00156 } 00157 BESIndent::UnIndent() ; 00158 } 00159 else 00160 { 00161 strm << BESIndent::LMarg << "registered agg handlers: none" << endl ; 00162 } 00163 BESIndent::UnIndent() ; 00164 } 00165 00166 BESAggFactory * 00167 BESAggFactory::TheFactory() 00168 { 00169 if( _instance == 0 ) 00170 { 00171 _instance = new BESAggFactory ; 00172 } 00173 return _instance ; 00174 } 00175