User Manual, Developers Guide and API Documentation

Base.hpp

Go to the documentation of this file.
00001 /*******************************************************************************
00002  * This file is part of openWNS (open Wireless Network Simulator)
00003  * _____________________________________________________________________________
00004  *
00005  * Copyright (C) 2004-2007
00006  * Chair of Communication Networks (ComNets)
00007  * Kopernikusstr. 16, D-52074 Aachen, Germany
00008  * phone: ++49-241-80-27910,
00009  * fax: ++49-241-80-22242
00010  * email: info@openwns.org
00011  * www: http://www.openwns.org
00012  * _____________________________________________________________________________
00013  *
00014  * openWNS is free software; you can redistribute it and/or modify it under the
00015  * terms of the GNU Lesser General Public License version 2 as published by the
00016  * Free Software Foundation;
00017  *
00018  * openWNS is distributed in the hope that it will be useful, but WITHOUT ANY
00019  * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
00020  * A PARTICULAR PURPOSE.  See the GNU Lesser General Public License for more
00021  * details.
00022  *
00023  * You should have received a copy of the GNU Lesser General Public License
00024  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
00025  *
00026  ******************************************************************************/
00027 
00028 #ifndef WNS_MODULE_BASE_HPP
00029 #define WNS_MODULE_BASE_HPP
00030 
00031 
00032 #include <WNS/module/MultiTypeFactory.hpp>
00033 #include <WNS/StaticFactory.hpp>
00034 #include <WNS/pyconfig/View.hpp>
00035 #include <WNS/PyConfigViewCreator.hpp>
00036 #include <WNS/logger/Logger.hpp>
00037 
00038 #include <map>
00039 
00040 namespace wns { namespace module {
00044     class Base :
00045         public MultiTypeFactory<std::string>
00046     {
00047     public:
00051         Base(const pyconfig::View& pyco);
00052 
00056         virtual
00057         ~Base();
00058 
00062         virtual void
00063         configure() =0;
00064 
00068         virtual void
00069         shutDown() =0;
00070 
00074         //VersionInformation
00075         //getVersionInformation() const;
00076 
00080         static bool
00081         existsService(const std::string& s);
00082 
00089         template <typename T>
00090         static T
00091         getService(const std::string& s)
00092         {
00093             typename TypeMap::iterator itr =
00094                 getGlobalMap().find(s);
00095 
00096             try {
00097                 assure(itr!=getGlobalMap().end(),
00098                        "Service not registered");
00099             }
00100             catch (wns::Exception e)
00101             {
00102                 std::stringstream ss;
00103                 ss << "Service \"" << s
00104                    << "\" not registered!" << std::endl;
00105                 ss << "Registered services are:" << std::endl;
00106                 for (itr = getGlobalMap().begin();
00107                      itr != getGlobalMap().end();
00108                      ++itr) {
00109                     ss << "  " << itr->first << std::endl;
00110                 }
00111                 throw(Exception(ss.str()));
00112             }
00113 
00114             return itr->second->get<T>(s);
00115         }
00116 
00117         bool
00118         getGlobalFlag() const;
00119 
00123         static bool
00124         load(const std::string& name, bool absolutePath, bool beVerbose, bool lazyBinding);
00125 
00126     protected:
00130         typedef wns::ChamaeleonBase* (*ConvertFunction)(Base*);
00131 
00135         typedef std::map<std::string, ConvertFunction> ConvertMap;
00136 
00140         void
00141         addServiceToGlobalMap(const std::string& s);
00142 
00146         ConvertMap convertMap;
00147 
00151         //VersionInformation version;
00152 
00156         bool global;
00157 
00161         logger::Logger logger;
00162 
00163     private:
00167         typedef std::map<std::string, Base*> TypeMap;
00168 
00172         static TypeMap& getGlobalMap();
00173 
00178         ChamaeleonBase*
00179         create(const std::string& s);
00180 
00184         void
00185         removeServiceFromGlobalMap(const std::string& s);
00186     };
00187 
00191     typedef PyConfigViewCreator<Base> Creator;
00192 
00196     typedef StaticFactory<Creator> Factory;
00197 } // module
00198 } // wns
00199 #endif  // NOT defined WNS_MODULEBASE_HPP

Generated on Sun May 27 03:31:48 2012 for openWNS by  doxygen 1.5.5