• Main Page
  • Related Pages
  • Classes
  • Files
  • File List

src/FactoryInformer.hh

00001 /*
00002  * This file is part of peekabot.
00003  *
00004  * peekabot is free software; you can redistribute it and/or modify
00005  * it under the terms of the GNU General Public License as published by
00006  * the Free Software Foundation; either version 3 of the License, or
00007  * (at your option) any later version.
00008  *
00009  * peekabot is distributed in the hope that it will be useful,
00010  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00011  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012  * GNU General Public License for more details.
00013  *
00014  * You should have received a copy of the GNU General Public License
00015  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
00016  */
00017 
00018 #ifndef __PEEKABOT_FACTORY_INFORMER_HH
00019 #define __PEEKABOT_FACTORY_INFORMER_HH
00020 
00021 
00022 #include <boost/function.hpp>
00023 
00024 #include "Types.hh"
00025 #include "Factory.hh"
00026 #include "Singleton.hh"
00027 
00028 
00029 namespace peekabot
00030 {
00031 
00032     // Auxillary class for defining derived actions.
00033     // Declare a static member of type FactoryInformer(my_id, my_create_fn)
00034     template<class FactorySingleton>
00035     class FactoryInformer
00036     {
00037     public:
00038         typedef typename FactorySingleton::InstanceType FactoryType;
00039         typedef typename FactoryType::IdentifierTypeType GUIDType;
00040         typedef typename FactoryType::AbstractProductType AbstractProduct;
00041         typedef typename FactoryType::ProductCreatorType ProductCreatorType;
00042 
00043         FactoryInformer(
00044             GUIDType guid, 
00045             ProductCreatorType creator) throw()
00046             : m_guid(guid)
00047         {
00048             FactorySingleton::instance().register_product(m_guid, creator);
00049         }
00050 
00051         ~FactoryInformer() throw()
00052         {
00053             FactorySingleton::instance().deregister_product(m_guid);
00054         }
00055 
00056         GUIDType get_guid() const throw()
00057         {
00058             return m_guid;
00059         }
00060 
00061     private:
00062         GUIDType m_guid;
00063     };
00064 
00065 
00066     
00067 }
00068 
00069 
00070 #endif // __PEEKABOT_FACTORY_INFORMER_HH

Generated on Sun Jan 30 2011 for peekabot by  doxygen 1.7.1