Homepage | Demos | Overview | Downloads | Dev. Resources | Reference | Credits |
Factory.hGo to the documentation of this file.00001 //-*-c++-*- 00002 #ifndef INCLUDED_Factory_h_ 00003 #define INCLUDED_Factory_h_ 00004 00005 //! Base class for Factory templated subclasses 00006 class FactoryBase { 00007 public: 00008 virtual ~FactoryBase() {} //!< destructor -- does nothing 00009 virtual void* constructTemplate()=0; //!< return a new object from the Factory subclass 00010 }; 00011 00012 //! A lightweight class to override for constructing new objects (if you need to pass constructors parameters, etc.) 00013 /*! Say you don't want to construct your behavior at boot-up (if it's big and might not even be 00014 * used) but your behavior needs special setup during creation (might be invoked 00015 * several difference ways for instance) then you'll want to subclass this to do the setup when 00016 * your behavior is activated.\n 00017 * The default is to simply call the default constructor */ 00018 template<class B> 00019 class Factory : public FactoryBase { 00020 public: 00021 virtual B* construct() { return new B(); } //!< Just returns a new B 00022 virtual void* constructTemplate() { return construct(); } 00023 }; 00024 00025 //! Uses template to specify a constant parameter to the constructor 00026 template<class B, class A1, A1 a1> 00027 class Factory1Arg : public Factory<B> { 00028 public: 00029 virtual B* construct() { return new B(a1); } //!< Just returns a new B constructed with arguments @a a1 00030 virtual void* constructTemplate() { return construct(); } 00031 }; 00032 00033 //! Uses template to specify constant parameters to the constructor 00034 template<class B, class A1, A1 a1, class A2, A2 a2> 00035 class Factory2Arg : public Factory<B> { 00036 public: 00037 virtual B* construct() { return new B(a1,a2); } //!< Just returns a new B constructed with arguments @a a1, @a a2 00038 virtual void* constructTemplate() { return construct(); } 00039 }; 00040 00041 //! Uses template to specify constant parameters to the constructor 00042 template<class B, class A1, A1 a1, class A2, A2 a2, class A3, A3 a3> 00043 class Factory3Arg : public Factory<B> { 00044 public: 00045 virtual B* construct() { return new B(a1,a2,a3); } //!< Just returns a new B constructed with arguments @a a1 - @a a3 00046 virtual void* constructTemplate() { return construct(); } 00047 }; 00048 00049 //! Uses template to specify constant parameters to the constructor 00050 template<class B, class A1, A1 a1, class A2, A2 a2, class A3, A3 a3, class A4, A4 a4> 00051 class Factory4Arg : public Factory<B> { 00052 public: 00053 virtual B* construct() { return new B(a1,a2,a3,a4); } //!< Just returns a new B constructed with arguments @a a1 - @a a4 00054 virtual void* constructTemplate() { return construct(); } 00055 }; 00056 00057 /*! @file 00058 * @brief Defines Factory, a lightweight class to override for constructing new objects 00059 * @author ejt (Creator) 00060 * 00061 * $Author: ejt $ 00062 * $Name: tekkotsu-2_4_1 $ 00063 * $Revision: 1.7 $ 00064 * $State: Exp $ 00065 * $Date: 2005/07/26 03:11:20 $ 00066 */ 00067 00068 #endif 00069 |
Tekkotsu v2.4.1 |
Generated Tue Aug 16 16:32:47 2005 by Doxygen 1.4.4 |