User Manual, Developers Guide and API Documentation

Module.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_MODULE_HPP
00029 #define WNS_MODULE_MODULE_HPP
00030 
00031 #include <WNS/module/Base.hpp>
00032 #include <WNS/pyconfig/View.hpp>
00033 #include <WNS/pyconfig/Parser.hpp>
00034 #include <WNS/Exception.hpp>
00035 
00036 #define MODULE_REGISTER_SERVICE(CreateType, Name, CreateFunctionName)\
00037 registerService<CreateType, &CreateFunctionName>(Name);
00038 
00039 namespace wns { namespace module {
00040 
00047     template <typename Deriver>
00048     class Module :
00049         public Base
00050     {
00051     public:
00055         Module(const pyconfig::View& _pyConfigView) :
00056             Base(_pyConfigView)
00057         {
00058             pyConfigView()=_pyConfigView;
00059             if(instantiated == true) {
00060                 Exception e("Only one instance of a module::Module allowed");
00061                 throw e;
00062             }
00063             instantiated = true;
00064         }
00065 
00069         virtual
00070         ~Module()
00071         {
00072             instantiated = false;
00073         }
00074 
00078         static bool
00079         isInstantiated()
00080         {
00081             return instantiated;
00082         }
00083 
00088         static wns::pyconfig::View&
00089         getPyConfigView()
00090         {
00091             return pyConfigView();
00092         }
00093 
00094     protected:
00098         template <typename T,
00099               T (Deriver::*callback)()>
00100         void
00101         registerService(const std::string& s)
00102         {
00103             struct Local
00104             {
00105                 static wns::ChamaeleonBase* Trampoline(
00106                     Base* mod)
00107                 {
00108                     assureType(mod, Deriver*);
00109                     Deriver* m = static_cast<Deriver*>(mod);
00110                     return new wns::Chamaeleon<T>(((*m).*callback)());
00111                 }
00112             };
00113             addServiceToGlobalMap(s);
00114             convertMap[s]=&Local::Trampoline;
00115         }
00116 
00127         static pyconfig::View&
00128         pyConfigView()
00129         {
00130             // Initialize with some default value
00131             static pyconfig::View p = pyconfig::Parser();
00132             return p;
00133         }
00134 
00135     private:
00139         static bool instantiated;
00140     };
00141 
00142     template <typename Deriver>
00143     bool
00144     Module<Deriver>::instantiated = false;
00145 
00146 } // module
00147 } // wns
00148 #endif  // NOT defined WNS_MODULE_HPP
00149 

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