00001 // Torc - Copyright 2011 University of Southern California. All Rights Reserved. 00002 // $HeadURL: https://torc-isi.svn.sourceforge.net/svnroot/torc-isi/branches/staging/0.9/src/torc/generic/om/FactoryType.hpp $ 00003 // $Id: FactoryType.hpp 10 2011-10-12 18:40:16Z nsteiner $ 00004 00005 // This program is free software: you can redistribute it and/or modify it under the terms of the 00006 // GNU General Public License as published by the Free Software Foundation, either version 3 of the 00007 // License, or (at your option) any later version. 00008 // 00009 // This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; 00010 // without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See 00011 // the GNU General Public License for more details. 00012 // 00013 // You should have received a copy of the GNU General Public License along with this program. If 00014 // not, see <http://www.gnu.org/licenses/>. 00015 00016 #ifndef TORC_GENERIC_OM_FACTORYTYPE_HPP 00017 #define TORC_GENERIC_OM_FACTORYTYPE_HPP 00018 00019 #include "torc/generic/om/SelfReferencing.hpp" 00020 00021 namespace torc { 00022 00023 namespace generic { 00024 00025 /** 00026 * @brief A placeholder for a factory method 00027 * 00028 * The FactoryType template acts as a placeholder for a virtual function create that can be inherited by objects that want to create an object of an EOM type. This is typedeffed inside individual classes to generate a nested typename for a factory that can be used to create an object of that type. For example <i>Cell::Factory</i> can be used to create an object of type Cell. 00029 * @note All objects creatable by FactoryType must inherit from SelfReferencing policy template 00030 */ 00031 template<typename _Tp> 00032 class FactoryType 00033 { 00034 public: 00035 /** 00036 * A rename of the parameter type 00037 */ 00038 typedef _Tp Type; 00039 00040 /** 00041 * A pointer to an object of type <i>Type</i> 00042 */ 00043 typedef typename SelfReferencing<Type>::Pointer Pointer; 00044 00045 /** 00046 * A weak pointer to an object of type <i>Type</i> 00047 */ 00048 typedef typename SelfReferencing<Type>::WeakPointer WeakPointer; 00049 00050 /** 00051 * Create an object of the Type specification of Factory. If the objet has a boost::weak_ptr to itself, it is the task of this method to set this after the object is created. 00052 * 00053 * @return A pointer to the freshly created object. 00054 */ 00055 virtual void 00056 create( Pointer &outPointer ) throw(Error) 00057 { 00058 try 00059 { 00060 Pointer temp( new _Tp() ); //Do not remove 00061 outPointer = temp; 00062 WeakPointer weakPtr( outPointer ); 00063 outPointer->setWeakThis( weakPtr ); 00064 } 00065 catch( std::exception &e ) //May receive std::bad_alloc 00066 { 00067 //TBD::ERROR 00068 } 00069 } 00070 00071 public: 00072 FactoryType() { 00073 } 00074 00075 00076 public: 00077 virtual 00078 ~FactoryType() throw() { 00079 } 00080 00081 private: 00082 FactoryType(const FactoryType<_Tp> & source) throw(); 00083 00084 FactoryType<_Tp> & 00085 operator=(const FactoryType<_Tp> & source) throw(); 00086 00087 00088 }; 00089 00090 } // namespace torc::generic 00091 00092 } // namespace torc 00093 #endif // TORC_GENERIC_OM_FACTORYTYPE_HPP