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/InstanceReference.hpp $ 00003 // $Id: InstanceReference.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 InstanceReference class. 00018 00019 #ifndef TORC_PHYSICAL_INSTANCEREFERENCE_HPP 00020 #define TORC_PHYSICAL_INSTANCEREFERENCE_HPP 00021 00022 #include <string> 00023 #include <boost/smart_ptr.hpp> 00024 00025 namespace torc { 00026 namespace physical { 00027 00028 /// \brief Instantiation of a module instance. 00029 /// \details This class references a module instance. It is used in cases where a module has 00030 /// been instantiated in a design, and instances appearing in that design point back to 00031 /// the module instances they were instantiated from. 00032 class InstanceReference { 00033 // friends 00034 /// \brief The Factory class has direct access to our internals. 00035 friend class Factory; 00036 protected: 00037 // types 00038 /// \brief Imported type name. 00039 typedef std::string string; 00040 /// \brief Local forward declaration of InstanceSharedPtr to avoid dependency loops. 00041 typedef boost::shared_ptr<class Instance> InstanceSharedPtr; 00042 /// \brief Local forward declaration of InstanceWeakPtr to avoid dependency loops. 00043 typedef boost::weak_ptr<class Instance> InstanceWeakPtr; 00044 /// \brief Local forward declaration of ModuleSharedPtr to avoid dependency loops. 00045 typedef boost::shared_ptr<class Module> ModuleSharedPtr; 00046 /// \brief Local forward declaration of ModuleWeakPtr to avoid dependency loops. 00047 typedef boost::weak_ptr<class Module> ModuleWeakPtr; 00048 // members 00049 /// \brief The module instantiation name. 00050 /// \details The instantiation name is the name under which the module was instantiated. 00051 string mInstantiationName; 00052 /// \brief The module weak pointer. 00053 ModuleWeakPtr mModulePtr; 00054 /// \brief The instance weak pointer. 00055 /// \details The instance pointer points to the module instance that this object references. 00056 InstanceWeakPtr mInstancePtr; 00057 // constructors 00058 /// \brief Protected constructor. 00059 /// \param inInstantiationName The name under which the reference module was instantiated. 00060 /// \param inModulePtr The module containing the referenced instance. 00061 /// \param inInstancePtr The instance being referenced. 00062 InstanceReference(const string& inInstantiationName, ModuleSharedPtr inModulePtr, 00063 InstanceSharedPtr inInstancePtr) : mInstantiationName(inInstantiationName), 00064 mModulePtr(inModulePtr), mInstancePtr(inInstancePtr) {} 00065 public: 00066 // accessors 00067 /// \brief Returns the weak module pointer. 00068 const ModuleWeakPtr& getModulePtr(void) const { return mModulePtr; } 00069 /// \brief Returns the weak instance pointer. 00070 const InstanceWeakPtr& getInstancePtr(void) const { return mInstancePtr; } 00071 /// \brief Returns the instantiation name. 00072 const string& getInstantiationName(void) const { return mInstantiationName; } 00073 // Setting accessors will be provided if necessary. 00074 // operators 00075 /// \brief Equality operator. 00076 bool operator ==(const InstanceReference& rhs) const { 00077 return !(mInstancePtr < rhs.mInstancePtr) && !(rhs.mInstancePtr < mInstancePtr) 00078 && !(mModulePtr < rhs.mModulePtr) && !(rhs.mModulePtr < mModulePtr) 00079 && mInstantiationName == rhs.mInstantiationName; 00080 } 00081 }; 00082 00083 /// \brief Shared pointer encapsulation of an InstanceReference. 00084 typedef boost::shared_ptr<InstanceReference> InstanceReferenceSharedPtr; 00085 00086 /// \brief Weak pointer encapsulation of an InstanceReference. 00087 typedef boost::weak_ptr<InstanceReference> InstanceReferenceWeakPtr; 00088 00089 } // namespace physical 00090 } // namespace torc 00091 00092 #endif // TORC_PHYSICAL_INSTANCEREFERENCE_HPP