torc-master
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Progenitor.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 /// \file
17 /// \brief Header for the Progenitor class.
18 
19 #ifndef TORC_PHYSICAL_PROGENITOR_HPP
20 #define TORC_PHYSICAL_PROGENITOR_HPP
21 
23 #include <string>
24 #include <boost/smart_ptr.hpp>
25 
26 namespace torc {
27 namespace physical {
28 
29 // forward declaration of our unit test class within its namespace
30 namespace physical { class ProgenitorUnitTest; }
31 namespace physical { class ProgenyUnitTest; }
32 
33  /// \brief Concept for any object that may have children.
34  /// \todo Rename Progenitor to SelfReferent, since some childless objects need to refer to
35  /// themselves. c.f. InstancePin.
36  template <class T> class Progenitor {
37  // friends
38  /// \brief The Factory class has direct access to our internals.
39  /// \details The Factory class needs access so that it can set this object's self weak
40  /// pointer after constructing it. This object can in turn share its weak pointer with
41  /// its children, allowing them to link back.
42  friend class Factory;
43  /// \brief Our unit test has direct access to our internals.
44  friend class torc::physical::physical::ProgenitorUnitTest;
45  /// \brief The Progeny<T> unit test has direct access to our internals.
46  friend class torc::physical::physical::ProgenyUnitTest;
47  protected:
48  // types
49  /// \brief Weak pointer of our own type.
50  typedef boost::weak_ptr<T> WeakPtrType;
51  /// \brief Shared pointer of our own type.
52  typedef boost::shared_ptr<T> SharedPtrType;
53  // members
54  /// \brief Weak pointer this object.
55  /// \details This weak pointer is kept here to be passed along to our children, allowing
56  /// them to point back to us without the strong dependency of a shared pointer.
58  /// \brief Sets the weak pointer to this object.
59  void setSelfWeakPtr(WeakPtrType inSelfPtr) { mSelfWeakPtr = inSelfPtr; }
60  // functions
61 // /// \brief Rename a child element.
62 // void renameChild(Renamable& inChild, const string& inName) {
63 // inChild.setName(inName);
64 // }
65  public:
66  // accessors
67  /// \brief Returns a weak pointer to this object.
68  const WeakPtrType& getSelfWeakPtr(void) const { return mSelfWeakPtr; }
69  };
70 
71 } // namespace physical
72 } // namespace torc
73 
74 #endif // TORC_PHYSICAL_PROGENITOR_HPP
Header for the Renamable class.
Factory class for physical netlist elements.
boost::shared_ptr< T > SharedPtrType
Shared pointer of our own type.
Definition: Progenitor.hpp:52
boost::weak_ptr< T > WeakPtrType
Weak pointer of our own type.
Definition: Progenitor.hpp:50
Concept for any object that may have children.
Definition: Progenitor.hpp:36
void setSelfWeakPtr(WeakPtrType inSelfPtr)
Sets the weak pointer to this object.
Definition: Progenitor.hpp:59
const WeakPtrType & getSelfWeakPtr(void) const
Returns a weak pointer to this object.
Definition: Progenitor.hpp:68
WeakPtrType mSelfWeakPtr
Weak pointer this object.
Definition: Progenitor.hpp:57