00001 // Torc - Copyright 2011 University of Southern California. All Rights Reserved. 00002 // $HeadURL: https://svn.east.isi.edu/torc/trunk/src/torc/physical/Design.hpp $ 00003 // $Id: Design.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 Design class. 00018 00019 #ifndef TORC_PHYSICAL_DESIGN_HPP 00020 #define TORC_PHYSICAL_DESIGN_HPP 00021 00022 #include "torc/physical/Circuit.hpp" 00023 #include "torc/physical/Module.hpp" 00024 #include <string> 00025 00026 namespace torc { 00027 namespace physical { 00028 00029 /// \brief Physical netlist design. 00030 /// \details The design is the top-level entity. It consists of an arbitrary number of 00031 /// modules, instances, and nets. 00032 /// \details Design objects must be created by the Factory class. 00033 class Design : public Circuit { 00034 // friends 00035 /// \brief The Factory class has direct access to our internals. 00036 friend class Factory; 00037 protected: 00038 // types 00039 /// \brief Imported type name. 00040 typedef std::string string; 00041 // members 00042 /// \brief Vector of module shared pointers. 00043 ModuleSharedPtrVector mModules; 00044 /// \brief The target device specified for this design. 00045 string mDevice; 00046 /// \brief The device package specified for this design. 00047 string mPackage; 00048 /// \brief The device speed grade specified for this design. 00049 string mSpeedGrade; 00050 /// \brief The XDL version specified for this design. 00051 string mXdlVersion; 00052 // constructors 00053 /// \brief Protected constructor. Designs must be created by the Factory. 00054 /// \param inName The design name. 00055 /// \param inDevice The design device. 00056 /// \param inPackage The device package. 00057 /// \param inSpeedGrade The device speed grade. 00058 /// \param inXdlVersion The design XDL version. 00059 Design(const string& inName, const string& inDevice, const string& inPackage, 00060 const string& inSpeedGrade, const string& inXdlVersion) : Circuit(inName), 00061 mDevice(inDevice), mPackage(inPackage), mSpeedGrade(inSpeedGrade), 00062 mXdlVersion(inXdlVersion) {} 00063 public: 00064 // types 00065 /// \brief Constant iterator for Module shared pointers. 00066 typedef ModuleSharedPtrVector::const_iterator ModuleSharedPtrConstIterator; 00067 /// \brief Non-constant iterator for Module shared pointers. 00068 typedef ModuleSharedPtrVector::iterator ModuleSharedPtrIterator; 00069 // functions 00070 /// \brief Find a design module by name. 00071 /// \param inName The module name to look for. 00072 /// \returns an iterator for the specified module, or modulesEnd() if the name was not 00073 /// found. 00074 ModuleSharedPtrIterator findModule(const string& inName) { 00075 NameComparator predicate(inName); 00076 return std::find_if(modulesBegin(), modulesEnd(), predicate); 00077 } 00078 /// \brief Add a module to the design. 00079 /// \param inModulePtr The module to add. 00080 /// \returns true if the module was added, or false if a module with the same name already 00081 /// exists in the design. 00082 bool addModule(ModuleSharedPtr& inModulePtr) { 00083 /// \todo Acquire mutex. 00084 ModuleSharedPtrVector::iterator e = mModules.end(); 00085 ModuleSharedPtrVector::iterator result = findModule(inModulePtr->getName()); 00086 if(result == e) mModules.push_back(inModulePtr); 00087 inModulePtr->setParentWeakPtr(mSelfWeakPtr); 00088 return result == e; // return true if we added the module 00089 /// \todo Release mutex. 00090 } 00091 /// \brief Remove a module from the design. 00092 /// \param inModulePtr The module to remove. 00093 /// \returns true if the module was remove, or false if the module did not exist. 00094 bool removeModule(ModuleSharedPtr& inModulePtr) { 00095 /// \todo Acquire mutex. 00096 ModuleSharedPtrVector::iterator e = mModules.end(); 00097 ModuleSharedPtrVector::iterator result = std::find(mModules.begin(), e, inModulePtr); 00098 if(result == e) return false; 00099 mModules.erase(result); 00100 /// \todo Release mutex. 00101 return true; 00102 } 00103 // accessors 00104 /// \brief Returns the target device for this design. 00105 const string& getDevice(void) const { return mDevice; } 00106 /// \brief Returns the device package for this design. 00107 const string& getPackage(void) const { return mPackage; } 00108 /// \brief Returns the device speed grade for this design. 00109 const string& getSpeedGrade(void) const { return mSpeedGrade; } 00110 /// \brief Returns the XDL version for this design. 00111 const string& getXdlVersion(void) const { return mXdlVersion; } 00112 /// \brief Sets the target device for this design. 00113 void setDevice(const string& inDevice) { mDevice = inDevice; } 00114 /// \brief Sets the device package for this design. 00115 void setPackage(const string& inPackage) { mPackage = inPackage; } 00116 /// \brief Sets the device speed grade for this design. 00117 void setSpeedGrade(const string& inSpeedGrade) { mSpeedGrade = inSpeedGrade; } 00118 /// \brief Sets the XDL version for this design. 00119 void setXdlVersion(const string& inXdlVersion) { mXdlVersion = inXdlVersion; } 00120 /// \brief Returns the number of modules in the design. 00121 size_t getModuleCount(void) const { return mModules.size(); } 00122 // iterators 00123 /// \brief Returns the begin constant iterator for modules. 00124 ModuleSharedPtrConstIterator modulesBegin(void) const { return mModules.begin(); } 00125 /// \brief Returns the end constant iterator for modules. 00126 ModuleSharedPtrConstIterator modulesEnd(void) const { return mModules.end(); } 00127 /// \brief Returns the begin non-constant iterator for modules. 00128 ModuleSharedPtrIterator modulesBegin(void) { return mModules.begin(); } 00129 /// \brief Returns the end non-constant iterator for modules. 00130 ModuleSharedPtrIterator modulesEnd(void) { return mModules.end(); } 00131 }; 00132 00133 /// \brief Shared pointer encapsulation of a Design. 00134 typedef boost::shared_ptr<Design> DesignSharedPtr; 00135 00136 /// \brief Vector of Design shared pointers. 00137 typedef std::vector<DesignSharedPtr> DesignSharedPtrVector; 00138 00139 } // namespace physical 00140 } // namespace torc 00141 00142 #endif // TORC_PHYSICAL_DESIGN_HPP