ServantFactory.cpp
Go to the documentation of this file.
00001 // -*- C++ -*-
00019 #ifndef DOIL_SERVANTFACTORY_H
00020 #define DOIL_SERVANTFACTORY_H
00021 
00022 #include <doil/ServantBase.h>
00023 
00024 namespace doil
00025 {
00026 
00027   // Servant 生成・削除関数のtypedef
00028   typedef ServantBase* (*ServantNewFunc)();
00029   typedef void (*ServantDeleteFunc)(ServantBase*);
00030 
00031   // Servant 生成のためのテンプレート関数
00032   template <class Servant>
00033   ServantBase* New()
00034   {
00035     return new Servant();
00036   }
00037 
00038   // Servant 削除のためのテンプレート関数
00039   template <class Servant>
00040   void Delete(ServantBase* servant)
00041   {
00042     if (servant != NULL)
00043       {
00044         delete servant;
00045         servant == NULL;
00046       }
00047   }
00048 
00049   class ServantFactoryBase
00050   {
00051   public:
00052     virtual ~ServantFactoryBase(){}
00053     virtual const char* name() = 0;
00054     virtual ServantBase* create() = 0;
00055     virtual void destroy(ServantBase* servant) = 0;
00056   };
00057 
00058 
00059   class ServantFactory
00060     : public ServantFactoryBase
00061   {
00062   public:
00063     ServantFactory(const char* name, 
00064                    ServantNewFunc new_func,
00065                    ServantDeleteFunc delete_func);
00066 
00067     virtual ~ServantFactory();
00068 
00069     virtual const char* name();
00070     virtual ServantBase* create();
00071     virtual void destroy(ServantBase* servant);
00072   };
00073 
00074 
00075 };
00076 #endif // DOIL_SERVANTFACTORY_H


openrtm_aist
Author(s): Noriaki Ando
autogenerated on Thu Aug 27 2015 14:16:39