torc-master
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
physical/Design.hpp
Go to the documentation of this file.
1 // Torc - Copyright 2011-2013 University of Southern California. All Rights Reserved.
2 // $HeadURL$
3 // $Id$
4 
5 // This program is free software: you can redistribute it and/or modify it under the terms of the
6 // GNU General Public License as published by the Free Software Foundation, either version 3 of the
7 // License, or (at your option) any later version.
8 //
9 // This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
10 // without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See
11 // the GNU General Public License for more details.
12 //
13 // You should have received a copy of the GNU General Public License along with this program. If
14 // not, see <http://www.gnu.org/licenses/>.
15 
16 /// \file
17 /// \brief Header for the Design class.
18 
19 #ifndef TORC_PHYSICAL_DESIGN_HPP
20 #define TORC_PHYSICAL_DESIGN_HPP
21 
23 #include "torc/physical/Module.hpp"
24 #include <string>
25 
26 namespace torc {
27 namespace physical {
28 
29  /// \brief Physical netlist design.
30  /// \details The design is the top-level entity. It consists of an arbitrary number of
31  /// modules, instances, and nets.
32  /// \details Design objects must be created by the Factory class.
33  class Design : public Circuit {
34  // friends
35  /// \brief The Factory class has direct access to our internals.
36  friend class Factory;
37  protected:
38  // types
39  /// \brief Imported type name.
41  // members
42  /// \brief Vector of module shared pointers.
44  /// \brief The target device specified for this design.
45  string mDevice;
46  /// \brief The device package specified for this design.
47  string mPackage;
48  /// \brief The device speed grade specified for this design.
49  string mSpeedGrade;
50  /// \brief The XDL version specified for this design.
51  string mXdlVersion;
52  // constructors
53  /// \brief Protected constructor. Designs must be created by the Factory.
54  /// \param inName The design name.
55  /// \param inDevice The design device.
56  /// \param inPackage The device package.
57  /// \param inSpeedGrade The device speed grade.
58  /// \param inXdlVersion The design XDL version.
59  Design(const string& inName, const string& inDevice, const string& inPackage,
60  const string& inSpeedGrade, const string& inXdlVersion) : Circuit(inName),
61  mDevice(inDevice), mPackage(inPackage), mSpeedGrade(inSpeedGrade),
62  mXdlVersion(inXdlVersion) {}
63  public:
64  // types
65  /// \brief Constant iterator for Module shared pointers.
66  typedef ModuleSharedPtrVector::const_iterator ModuleSharedPtrConstIterator;
67  /// \brief Non-constant iterator for Module shared pointers.
68  typedef ModuleSharedPtrVector::iterator ModuleSharedPtrIterator;
69  // functions
70  /// \brief Find a design module by name.
71  /// \param inName The module name to look for.
72  /// \returns an iterator for the specified module, or modulesEnd() if the name was not
73  /// found.
74  ModuleSharedPtrIterator findModule(const string& inName) {
75  NameComparator predicate(inName);
76  return std::find_if(modulesBegin(), modulesEnd(), predicate);
77  }
78  /// \brief Add a module to the design.
79  /// \param inModulePtr The module to add.
80  /// \returns true if the module was added, or false if a module with the same name already
81  /// exists in the design.
82  bool addModule(ModuleSharedPtr& inModulePtr) {
83  /// \todo Acquire mutex.
84  ModuleSharedPtrVector::iterator e = mModules.end();
85  ModuleSharedPtrVector::iterator result = findModule(inModulePtr->getName());
86  if(result == e) mModules.push_back(inModulePtr);
87  inModulePtr->setParentWeakPtr(mSelfWeakPtr);
88  return result == e; // return true if we added the module
89  /// \todo Release mutex.
90  }
91  /// \brief Remove a module from the design.
92  /// \param inModulePtr The module to remove.
93  /// \returns true if the module was removed, or false if the module did not exist.
94  bool removeModule(ModuleSharedPtr& inModulePtr) {
95  /// \todo Acquire mutex.
96  ModuleSharedPtrVector::iterator e = mModules.end();
97  ModuleSharedPtrVector::iterator result = std::find(mModules.begin(), e, inModulePtr);
98  if(result == e) return false;
99  mModules.erase(result);
100  /// \todo Release mutex.
101  return true;
102  }
103  // accessors
104  /// \brief Returns the target device for this design.
105  const string& getDevice(void) const { return mDevice; }
106  /// \brief Returns the device package for this design.
107  const string& getPackage(void) const { return mPackage; }
108  /// \brief Returns the device speed grade for this design.
109  const string& getSpeedGrade(void) const { return mSpeedGrade; }
110  /// \brief Returns the XDL version for this design.
111  const string& getXdlVersion(void) const { return mXdlVersion; }
112  /// \brief Sets the target device for this design.
113  void setDevice(const string& inDevice) { mDevice = inDevice; }
114  /// \brief Sets the device package for this design.
115  void setPackage(const string& inPackage) { mPackage = inPackage; }
116  /// \brief Sets the device speed grade for this design.
117  void setSpeedGrade(const string& inSpeedGrade) { mSpeedGrade = inSpeedGrade; }
118  /// \brief Sets the XDL version for this design.
119  void setXdlVersion(const string& inXdlVersion) { mXdlVersion = inXdlVersion; }
120  /// \brief Returns the number of modules in the design.
121  size_t getModuleCount(void) const { return mModules.size(); }
122  // iterators
123  /// \brief Returns the begin constant iterator for modules.
124  ModuleSharedPtrConstIterator modulesBegin(void) const { return mModules.begin(); }
125  /// \brief Returns the end constant iterator for modules.
126  ModuleSharedPtrConstIterator modulesEnd(void) const { return mModules.end(); }
127  /// \brief Returns the begin non-constant iterator for modules.
129  /// \brief Returns the end non-constant iterator for modules.
131  };
132 
133  /// \brief Shared pointer encapsulation of a Design.
134  typedef boost::shared_ptr<Design> DesignSharedPtr;
135 
136  /// \brief Vector of Design shared pointers.
137  typedef std::vector<DesignSharedPtr> DesignSharedPtrVector;
138 
139 } // namespace physical
140 } // namespace torc
141 
142 #endif // TORC_PHYSICAL_DESIGN_HPP
Design(const string &inName, const string &inDevice, const string &inPackage, const string &inSpeedGrade, const string &inXdlVersion)
Protected constructor. Designs must be created by the Factory.
Header for the Module class.
const string & getPackage(void) const
Returns the device package for this design.
bool addModule(ModuleSharedPtr &inModulePtr)
Add a module to the design.
Physical netlist design.
std::vector< DesignSharedPtr > DesignSharedPtrVector
Vector of Design shared pointers.
ModuleSharedPtrVector::const_iterator ModuleSharedPtrConstIterator
Constant iterator for Module shared pointers.
std::string string
Imported type name.
ModuleSharedPtrConstIterator modulesEnd(void) const
Returns the end constant iterator for modules.
std::string string
ModuleSharedPtrConstIterator modulesBegin(void) const
Returns the begin constant iterator for modules.
string mXdlVersion
The XDL version specified for this design.
boost::shared_ptr< Module > ModuleSharedPtr
Shared pointer encapsulation of a Module.
Definition: Module.hpp:114
ModuleSharedPtrVector mModules
Vector of module shared pointers.
Comparator class to serve as a predicate when searching for names.
Definition: Named.hpp:61
void setXdlVersion(const string &inXdlVersion)
Sets the XDL version for this design.
void setDevice(const string &inDevice)
Sets the target device for this design.
ModuleSharedPtrIterator findModule(const string &inName)
Find a design module by name.
string mSpeedGrade
The device speed grade specified for this design.
Factory class for physical netlist elements.
boost::shared_ptr< Design > DesignSharedPtr
Shared pointer encapsulation of a Design.
string mPackage
The device package specified for this design.
void setPackage(const string &inPackage)
Sets the device package for this design.
void setSpeedGrade(const string &inSpeedGrade)
Sets the device speed grade for this design.
const string & getXdlVersion(void) const
Returns the XDL version for this design.
size_t getModuleCount(void) const
Returns the number of modules in the design.
Header for the Circuit class.
bool removeModule(ModuleSharedPtr &inModulePtr)
Remove a module from the design.
ModuleSharedPtrVector::iterator ModuleSharedPtrIterator
Non-constant iterator for Module shared pointers.
const string & getSpeedGrade(void) const
Returns the device speed grade for this design.
const string & getDevice(void) const
Returns the target device for this design.
Circuit composed of instances and nets.
Definition: Circuit.hpp:46
WeakPtrType mSelfWeakPtr
Weak pointer this object.
Definition: Progenitor.hpp:57
std::vector< ModuleSharedPtr > ModuleSharedPtrVector
Vector of Module shared pointers.
Definition: Module.hpp:120
ModuleSharedPtrIterator modulesEnd(void)
Returns the end non-constant iterator for modules.
ModuleSharedPtrIterator modulesBegin(void)
Returns the begin non-constant iterator for modules.
string mDevice
The target device specified for this design.