00001 // Torc - Copyright 2011 University of Southern California. All Rights Reserved. 00002 // $HeadURL: https://svn.east.isi.edu/torc/trunk/src/torc/physical/Port.hpp $ 00003 // $Id: Port.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 Port class. 00018 00019 #ifndef TORC_PHYSICAL_PORT_HPP 00020 #define TORC_PHYSICAL_PORT_HPP 00021 00022 #include "torc/physical/Named.hpp" 00023 #include "torc/physical/Progeny.hpp" 00024 #include "torc/physical/Instance.hpp" 00025 #include <boost/smart_ptr.hpp> 00026 00027 // forward declaration of XdlParser within its namespace 00028 namespace torc { 00029 class XdlParser; 00030 } // namespace torc 00031 00032 namespace torc { 00033 namespace physical { 00034 00035 /// \brief Module input or output port. 00036 /// \details This class declares a named port for the enclosing module. 00037 class Port : public Named, public Progeny<class Module> { 00038 // friends 00039 /// \brief The Factory class has direct access to our internals. 00040 friend class Factory; 00041 protected: 00042 // types 00043 /// \brief Imported type name. 00044 typedef std::string string; 00045 // members 00046 /// \brief The port instance pointer. 00047 InstanceWeakPtr mInstancePtr; 00048 /// \brief The port pin name. 00049 PinName mPinName; 00050 // constructors 00051 /// \brief Protected constructor. 00052 /// \param inName The port name. 00053 /// \param inInstancePtr The port instance pointer. 00054 /// \param inPinName The port pin name. 00055 Port(const string& inName, InstanceSharedPtr inInstancePtr, const string& inPinName) 00056 : Named(inName), mInstancePtr(inInstancePtr), mPinName(inPinName) {} 00057 public: 00058 // accessors 00059 /// \brief Returns a weak instance pointer. 00060 const InstanceWeakPtr& getInstancePtr(void) const { return mInstancePtr; } 00061 /// \brief Returns the pin name. 00062 const PinName& getPinName(void) const { return mPinName; } 00063 // operators 00064 /// \brief Equality operator. 00065 /// \details This function deems ports equal if their names are identical. 00066 /// \returns true if both port names are identical, or false otherwise. 00067 bool operator ==(const Port& rhs) const { return mName == rhs.mName; } 00068 }; 00069 00070 /// \brief Shared pointer encapsulation of a Port. 00071 typedef boost::shared_ptr<Port> PortSharedPtr; 00072 00073 /// \brief Weak pointer encapsulation of a Port. 00074 typedef boost::weak_ptr<Port> PortWeakPtr; 00075 00076 /// \brief Vector of Port shared pointers. 00077 typedef std::vector<PortSharedPtr> PortSharedPtrVector; 00078 00079 /// \brief Temporary module port. 00080 /// \details This class should only be used by XdlParser to remember the port while awaiting 00081 /// the definition of the port's instance. 00082 class PortTemp { 00083 /// \brief The XdlParser class has direct access to our internals. 00084 friend class torc::XdlParser; 00085 // types 00086 /// \brief Imported type name. 00087 typedef std::string string; 00088 protected: 00089 // members 00090 /// \brief The port name. 00091 string mName; 00092 /// \brief The port instance. 00093 string mInstance; 00094 /// \brief The port pin. 00095 string mPin; 00096 // constructors 00097 /// \param inName The port name. 00098 /// \param inInstance The port instance. 00099 /// \param inPin The port pin. 00100 PortTemp(const string& inName, const string& inInstance, const string& inPin) 00101 : mName(inName), mInstance(inInstance), mPin(inPin) {} 00102 // accessors 00103 /// \brief Returns the port name. 00104 const string& getName(void) const { return mName; } 00105 /// \brief Returns the port instance. 00106 const string& getInstance(void) const { return mInstance; } 00107 /// \brief Returns the port instance pin. 00108 const string& getPin(void) const { return mPin; } 00109 }; 00110 00111 /// \brief Vector 00112 typedef std::vector<PortTemp> PortTempVector; 00113 00114 00115 } // namespace physical 00116 } // namespace torc 00117 00118 #endif // TORC_PHYSICAL_PORT_HPP