BESPluginFactory.h

Go to the documentation of this file.
00001 // BESPluginFactory.h
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 // and James Gallagher <jgallagher@gso.uri.edu>
00009 //
00010 // This library is free software; you can redistribute it and/or
00011 // modify it under the terms of the GNU Lesser General Public
00012 // License as published by the Free Software Foundation; either
00013 // version 2.1 of the License, or (at your option) any later version.
00014 // 
00015 // This library is distributed in the hope that it will be useful,
00016 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00017 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00018 // Lesser General Public License for more details.
00019 // 
00020 // You should have received a copy of the GNU Lesser General Public
00021 // License along with this library; if not, write to the Free Software
00022 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00023 //
00024 // You can contact University Corporation for Atmospheric Research at
00025 // 3080 Center Green Drive, Boulder, CO 80301
00026  
00027 // (c) COPYRIGHT University Corporation for Atmospheric Research 2004-2005
00028 // Please read the full copyright statement in the file COPYRIGHT_UCAR.
00029 //
00030 // Authors:
00031 //      pwest       Patrick West <pwest@ucar.edu>
00032 //      jgarcia     Jose Garcia <jgarcia@ucar.edu>
00033 //      jimg        James Gallagher <jgallagher@gso.uri.edu>
00034 
00035 #ifndef plugin_factory_h
00036 #define plugin_factory_h
00037 
00038 #include <string>
00039 #include <map>
00040 #include <algorithm>
00041 
00042 #include "BESPlugin.h"
00043 
00044 using std::string;
00045 using std::map;
00046 using std::pair;
00047 using std::unary_function;
00048 
00049 #include "BESObj.h"
00050 
00060 template<typename C>
00061 class BESPluginFactory : public BESObj
00062 {
00063 private:
00064     map<string, BESPlugin<C> *> d_children;
00065 
00072     BESPluginFactory(const BESPluginFactory &pf)
00073         throw(BESInternalError)
00074     {
00075         throw BESInternalError( "Unimplemented method.");
00076     }
00077 
00081     const BESPluginFactory &operator=(const BESPluginFactory &rhs)
00082         throw (BESInternalError)
00083     {
00084         throw BESInternalError( "Unimplemented method.");
00085     }
00086 
00087     struct DeletePlugins 
00088         : public unary_function<pair<string, BESPlugin<C> *>, void>
00089     {
00090 
00091         void operator()(pair<string, BESPlugin<C> *> elem) {
00092             delete elem.second;
00093         }
00094     };
00095 
00096 public:
00106     BESPluginFactory(const string &name, const string &library_name)
00107     {
00108         add_mapping(name, library_name);
00109     }
00110 
00113     BESPluginFactory() { }
00114 
00115     virtual ~BESPluginFactory()
00116     {
00117         for_each(d_children.begin(), d_children.end(), DeletePlugins());
00118     }
00119 
00125     void add_mapping(const string &name, const string &library_name)
00126     {
00127         BESPlugin<C> *child_class = new BESPlugin<C>(library_name);
00128         d_children.insert(std::make_pair(name, child_class));
00129     }
00130 
00146     C *get(const string &name) throw(NoSuchObject, NoSuchLibrary)
00147     {
00148         BESPlugin<C> *child_implementation = d_children[name];
00149         if (!child_implementation)
00150             throw NoSuchObject(string("No class is bound to ") + name, __FILE__, __LINE__ );
00151         return child_implementation->instantiate();
00152     }
00153 
00154     virtual void dump( ostream &strm ) const
00155     {
00156         strm << "BESPluginFactory::dump - (" << (void *)this << ")" << endl ;
00157         /*
00158         typedef map<string, BESPlugin<C> *>::const_iterator Plugin_citer ;
00159         BESPluginFactory::Plugin_citer i = d_children.begin() ;
00160         BESPluginFactory::Plugin_citer ie = d_children.end() ;
00161         for( ; i != ie; i++ )
00162         {
00163             strm << i.second ;
00164         }
00165         */
00166     }
00167 };
00168 
00169 #endif //plugin_h
00170 

Generated on Tue Mar 4 23:13:35 2008 for OPeNDAP Back End Server (BES) by  doxygen 1.5.1