torc-master
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Progeny.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 Progeny class.
18 
19 #ifndef TORC_PHYSICAL_PROGENY_HPP
20 #define TORC_PHYSICAL_PROGENY_HPP
21 
22 #include <string>
23 #include <boost/smart_ptr.hpp>
24 
25 namespace torc {
26 namespace physical {
27 
28  /// \brief Concept for any object that may have a parent.
29  template <class T> class Progeny {
30  protected:
31  // types
32  /// \brief Weak pointer of our own type.
33  typedef boost::weak_ptr<T> WeakPtrType;
34  /// \brief Shared pointer of our own type.
35  typedef boost::shared_ptr<T> SharedPtrType;
36  // members
37  /// \brief Weak pointer to the parent.
39  public:
40  // constructors
41  /// \brief Null constructor.
42  Progeny(void) {}
43  /// \brief Constructor that specifies a parent.
44  Progeny(const WeakPtrType& inParentPtr) : mParentWeakPtr(inParentPtr) {}
45  // accessors
46  /// \brief Returns a weak pointer to the parent.
47  const WeakPtrType& getParentWeakPtr(void) const { return mParentWeakPtr; }
48  /// \brief Sets the weak pointer to the parent.
49  void setParentWeakPtr(WeakPtrType inParentPtr) { mParentWeakPtr = inParentPtr; }
50  /// \brief Method to reset and orphan this object.
51  void resetParentWeakPtr(void) { mParentWeakPtr.reset(); }
52  // broken
53  /// \brief Returns a shared pointer to the parent (WARNING: Does not work right).
54  /// \details Always seems to generate a "Returning reference to temporary" warning, and I
55  /// cannot figure out why.
56  /// \details It is the caller's responsibility to reset the shared pointer when done.
57  /// \todo Figure out why Progeny<T>::getParentSharedPtr() yields a "Returning reference to
58  /// temporary" warning.
59  const SharedPtrType& getParentSharedPtr(void) const { return mParentWeakPtr.lock(); }
60  };
61 
62 } // namespace physical
63 } // namespace torc
64 
65 #endif // TORC_PHYSICAL_PROGENY_HPP
Progeny(const WeakPtrType &inParentPtr)
Constructor that specifies a parent.
Definition: Progeny.hpp:44
void setParentWeakPtr(WeakPtrType inParentPtr)
Sets the weak pointer to the parent.
Definition: Progeny.hpp:49
const SharedPtrType & getParentSharedPtr(void) const
Returns a shared pointer to the parent (WARNING: Does not work right).
Definition: Progeny.hpp:59
const WeakPtrType & getParentWeakPtr(void) const
Returns a weak pointer to the parent.
Definition: Progeny.hpp:47
boost::weak_ptr< T > WeakPtrType
Weak pointer of our own type.
Definition: Progeny.hpp:33
WeakPtrType mParentWeakPtr
Weak pointer to the parent.
Definition: Progeny.hpp:38
void resetParentWeakPtr(void)
Method to reset and orphan this object.
Definition: Progeny.hpp:51
Progeny(void)
Null constructor.
Definition: Progeny.hpp:42
Concept for any object that may have a parent.
Definition: Progeny.hpp:29
boost::shared_ptr< T > SharedPtrType
Shared pointer of our own type.
Definition: Progeny.hpp:35