ctkAbstractObjectFactory.h

Go to the documentation of this file.
00001 /*=========================================================================
00002 
00003   Library:   CTK
00004  
00005   Copyright (c) 2010  Kitware Inc.
00006 
00007   Licensed under the Apache License, Version 2.0 (the "License");
00008   you may not use this file except in compliance with the License.
00009   You may obtain a copy of the License at
00010 
00011       http://www.commontk.org/LICENSE
00012 
00013   Unless required by applicable law or agreed to in writing, software
00014   distributed under the License is distributed on an "AS IS" BASIS,
00015   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00016   See the License for the specific language governing permissions and
00017   limitations under the License.
00018  
00019 =========================================================================*/
00020 
00021 #ifndef __ctkAbstractObjectFactory_h
00022 #define __ctkAbstractObjectFactory_h
00023 
00024 // Qt includes
00025 #include <QDebug>
00026 
00027 // CTK includes
00028 #include "ctkAbstractFactory.h"
00029 
00030 //----------------------------------------------------------------------------
00031 namespace{
00034   template<typename BaseClassType, typename ClassType>
00035     BaseClassType *instantiateObject()
00036   {
00037     return new ClassType;
00038   }
00039 }
00040 
00041 //----------------------------------------------------------------------------
00042 template<typename BaseClassType, typename ClassType>
00043 class ctkFactoryObjectItem : public ctkAbstractFactoryItem<BaseClassType>
00044 {
00045 protected:
00046   typedef BaseClassType *(*InstantiateObjectFunc)();
00047 public:
00048   explicit ctkFactoryObjectItem(const QString& key);
00049   virtual bool load();
00050 protected:
00051   virtual BaseClassType* instanciator();
00052 private:
00053   InstantiateObjectFunc instantiateObjectFunc;
00054 };
00055 
00056 //----------------------------------------------------------------------------
00057 template<typename BaseClassType>
00058 class ctkAbstractObjectFactory : public ctkAbstractFactory<BaseClassType>
00059 {
00060 public:
00063   explicit ctkAbstractObjectFactory();
00064   virtual ~ctkAbstractObjectFactory();
00065 
00068   template<typename ClassType>
00069   bool registerObject(const QString& key);
00070 
00071 private:
00072   ctkAbstractObjectFactory(const ctkAbstractObjectFactory &);  
00073   void operator=(const ctkAbstractObjectFactory&); 
00074 };
00075 
00076 #include "ctkAbstractObjectFactory.tpp"
00077 
00078 #endif
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Defines

Generated on 21 May 2010 for CTK by  doxygen 1.6.1