00001 // Torc - Copyright 2011 University of Southern California. All Rights Reserved. 00002 // $HeadURL: https://svn.east.isi.edu/torc/trunk/src/torc/physical/Progeny.hpp $ 00003 // $Id: Progeny.hpp 380 2011-02-23 04:05:26Z 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 /// \file 00017 /// \brief Header for the Progeny class. 00018 00019 #ifndef TORC_PHYSICAL_PROGENY_HPP 00020 #define TORC_PHYSICAL_PROGENY_HPP 00021 00022 #include <string> 00023 #include <boost/smart_ptr.hpp> 00024 00025 namespace torc { 00026 namespace physical { 00027 00028 /// \brief Concept for any object that may have a parent. 00029 template <class T> class Progeny { 00030 protected: 00031 // types 00032 /// \brief Weak pointer of our own type. 00033 typedef boost::weak_ptr<T> WeakPtrType; 00034 /// \brief Shared pointer of our own type. 00035 typedef boost::shared_ptr<T> SharedPtrType; 00036 // members 00037 /// \brief Weak pointer to the parent. 00038 WeakPtrType mParentWeakPtr; 00039 public: 00040 // constructors 00041 /// \brief Null constructor. 00042 Progeny(void) {} 00043 /// \brief Constructor that specifies a parent. 00044 Progeny(const WeakPtrType& inParentPtr) : mParentWeakPtr(inParentPtr) {} 00045 // accessors 00046 /// \brief Returns a weak pointer to the parent. 00047 const WeakPtrType& getParentWeakPtr(void) const { return mParentWeakPtr; } 00048 /// \brief Sets the weak pointer to the parent. 00049 void setParentWeakPtr(WeakPtrType inParentPtr) { mParentWeakPtr = inParentPtr; } 00050 /// \brief Method to reset and orphan this object. 00051 void resetParentWeakPtr(void) { mParentWeakPtr.reset(); } 00052 // broken 00053 /// \brief Returns a shared pointer to the parent (WARNING: Does not work right). 00054 /// \details Always seems to generate a "Returning reference to temporary" warning, and I 00055 /// cannot figure out why. 00056 /// \details It is the caller's responsibility to reset the shared pointer when done. 00057 /// \todo Figure out why Progeny<T>::getParentSharedPtr() yields a "Returning reference to 00058 /// temporary" warning. 00059 const SharedPtrType& getParentSharedPtr(void) const { return mParentWeakPtr.lock(); } 00060 }; 00061 00062 } // namespace physical 00063 } // namespace torc 00064 00065 #endif // TORC_PHYSICAL_PROGENY_HPP