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/physical/Progenitor.hpp $ 00003 // $Id: Progenitor.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 /// \file 00017 /// \brief Header for the Progenitor class. 00018 00019 #ifndef TORC_PHYSICAL_PROGENITOR_HPP 00020 #define TORC_PHYSICAL_PROGENITOR_HPP 00021 00022 #include "torc/physical/Renamable.hpp" 00023 #include <string> 00024 #include <boost/smart_ptr.hpp> 00025 00026 namespace torc { 00027 namespace physical { 00028 00029 // forward declaration of our unit test class within its namespace 00030 namespace physical { class ProgenitorUnitTest; } 00031 namespace physical { class ProgenyUnitTest; } 00032 00033 /// \brief Concept for any object that may have children. 00034 /// \todo Rename Progenitor to SelfReferent, since some childless objects need to refer to 00035 /// themselves. c.f. InstancePin. 00036 template <class T> class Progenitor { 00037 // friends 00038 /// \brief The Factory class has direct access to our internals. 00039 /// \details The Factory class needs access so that it can set this object's self weak 00040 /// pointer after constructing it. This object can in turn share its weak pointer with 00041 /// its children, allowing them to link back. 00042 friend class Factory; 00043 /// \brief Our unit test has direct access to our internals. 00044 friend class torc::physical::physical::ProgenitorUnitTest; 00045 /// \brief The Progeny<T> unit test has direct access to our internals. 00046 friend class torc::physical::physical::ProgenyUnitTest; 00047 protected: 00048 // types 00049 /// \brief Weak pointer of our own type. 00050 typedef boost::weak_ptr<T> WeakPtrType; 00051 /// \brief Shared pointer of our own type. 00052 typedef boost::shared_ptr<T> SharedPtrType; 00053 // members 00054 /// \brief Weak pointer this object. 00055 /// \details This weak pointer is kept here to be passed along to our children, allowing 00056 /// them to point back to us without the strong dependency of a shared pointer. 00057 WeakPtrType mSelfWeakPtr; 00058 /// \brief Sets the weak pointer to this object. 00059 void setSelfWeakPtr(WeakPtrType inSelfPtr) { mSelfWeakPtr = inSelfPtr; } 00060 // functions 00061 // /// \brief Rename a child element. 00062 // void renameChild(Renamable& inChild, const string& inName) { 00063 // inChild.setName(inName); 00064 // } 00065 public: 00066 // accessors 00067 /// \brief Returns a weak pointer to this object. 00068 const WeakPtrType& getSelfWeakPtr(void) const { return mSelfWeakPtr; } 00069 }; 00070 00071 } // namespace physical 00072 } // namespace torc 00073 00074 #endif // TORC_PHYSICAL_PROGENITOR_HPP