torc-master
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
FactoryType.hpp
Go to the documentation of this file.
1 // Torc - Copyright 2011-2013 University of Southern California. All Rights Reserved.
2 // $HeadURL$
3 // $Id$
4 
5 // This program is free software: you can redistribute it and/or modify it under the terms of the
6 // GNU General Public License as published by the Free Software Foundation, either version 3 of the
7 // License, or (at your option) any later version.
8 //
9 // This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
10 // without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See
11 // the GNU General Public License for more details.
12 //
13 // You should have received a copy of the GNU General Public License along with this program. If
14 // not, see <http://www.gnu.org/licenses/>.
15 
16 #ifndef TORC_GENERIC_FACTORYTYPE_HPP
17 #define TORC_GENERIC_FACTORYTYPE_HPP
18 
20 
21 namespace torc {
22 namespace generic {
23 
24 /**
25  * @brief A placeholder for a factory method
26  *
27  * The FactoryType template acts as a placeholder for a virtual function create that can be
28  * inherited by objects that want to create an object of an EOM type. This is typedeffed inside
29  * individual classes to generate a nested typename for a factory that can be used to create an
30  * object of that type. For example <i>Cell::Factory</i> can be used to create an object of type
31  * Cell.
32  * @note All objects creatable by FactoryType must inherit from SelfReferencing policy template
33  */
34 template <typename _Tp>
35 class FactoryType {
36 public:
37  /**
38  * A rename of the parameter type
39  */
40  typedef _Tp Type;
41 
42  /**
43  * A pointer to an object of type <i>Type</i>
44  */
46 
47  /**
48  * A weak pointer to an object of type <i>Type</i>
49  */
51 
52  /**
53  * Create an object of the Type specification of Factory. If the object has a boost::weak_ptr
54  * to itself, it is the task of this method to set this after the object is created.
55  *
56  * @return A pointer to the freshly created object.
57  */
58  virtual void create(Pointer& outPointer) throw (Error) {
59  try {
60  Pointer temp(new _Tp()); //Do not remove
61  outPointer = temp;
62  WeakPointer weakPtr(outPointer);
63  outPointer->setWeakThis(weakPtr);
64  } catch(std::exception& e) //May receive std::bad_alloc
65  {
66  //TBD::ERROR
67  }
68  }
69 
70 public:
72  }
73 
74 public:
75  virtual ~FactoryType() throw () {
76  }
77 
78 private:
79  FactoryType(const FactoryType<_Tp>& source);
80 
82 
83 };
84 
85 } // namespace generic
86 } // namespace torc
87 
88 #endif // TORC_GENERIC_FACTORYTYPE_HPP
virtual void create(Pointer &outPointer)
Definition: FactoryType.hpp:58
SelfReferencing< Type >::WeakPointer WeakPointer
Definition: FactoryType.hpp:50
The Error object thrown by different methods of EdifOM.
Definition: Error.hpp:41
boost::shared_ptr< Type > Pointer
boost::weak_ptr< Type > WeakPointer
FactoryType< _Tp > & operator=(const FactoryType< _Tp > &source)
A placeholder for a factory method.
Definition: FactoryType.hpp:35
SelfReferencing< Type >::Pointer Pointer
Definition: FactoryType.hpp:45