torc-master
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
physical/Net.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 Net class.
18 
19 #ifndef TORC_PHYSICAL_NET_HPP
20 #define TORC_PHYSICAL_NET_HPP
21 
22 #include "torc/physical/Named.hpp"
28 #include "torc/physical/Pip.hpp"
31 #include <string>
32 
33 namespace torc {
34 namespace physical {
35 
36  /// \brief Physical design net.
37  /// \details The Net class owns its instance pins and its pips, and is responsible for deleting
38  /// them.
39  /// \todo Consider checking for duplicates whenever a source, sink, or pip is added. On the
40  /// other hand, we provide the functions to check for existing resources, so perhaps we can
41  /// just leave it to the user.
42  class Net : public Renamable<Circuit>, public Progeny<class Circuit>, public ConfigMap,
43  public common::Annotated, protected Progenitor<Net> {
44  // friends
45  /// \brief The Factory class has direct access to our internals.
46  friend class Factory;
47  protected:
48  // types
49  /// \brief Imported type name.
51  // members
52  /// \brief The net power type. See ENetType.
54  /// \brief Vector of instance pin shared pointer sources for the net.
56  /// \brief Vector of instance pin shared pointer sinks for the net.
58  /// \brief Vector of pips for the net.
60  // constructors
61  /// \brief Protected constructor.
62  /// \param inName The net name.
63  /// \param inNetType The net power type.
64  Net(const string& inName, ENetType inNetType) : Renamable<Circuit>(inName), ConfigMap(),
65  mNetType(inNetType) {}
66  public:
67  // types
68  /// \brief Constant iterator to InstancePin shared pointer objects.
69  typedef InstancePinSharedPtrVector::const_iterator InstancePinSharedPtrConstIterator;
70  /// \brief Non-constant iterator to InstancePin shared pointer objects.
71  typedef InstancePinSharedPtrVector::iterator InstancePinSharedPtrIterator;
72  /// \brief Constant iterator to Pip objects.
73  typedef PipVector::const_iterator PipConstIterator;
74  /// \brief Non-constant iterator to Pip objects.
75  typedef PipVector::iterator PipIterator;
76  // functions
77  /// \brief Determines whether the given instance pin is a source of this net.
78  /// \returns true if the given instance pin is a source of this net, or false otherwise.
79  bool containsSource(InstancePinSharedPtr& inInstancePinPtr) const {
80  return std::find(sourcesBegin(), sourcesEnd(), inInstancePinPtr) != sourcesEnd();
81  }
82  /// \brief Determines whether the given instance pin is a sink of this net.
83  /// \returns true if the given instance pin is a sink of this net, or false otherwise.
84  bool containsSink(InstancePinSharedPtr& inInstancePinPtr) const {
85  return std::find(sinksBegin(), sinksEnd(), inInstancePinPtr) != sinksEnd();
86  }
87  /// \brief Determines whether the net contains the given pip.
88  /// \returns true if the net contains the given pip, or false otherwise.
89  bool containsPip(const Pip& inPip) const {
90  return std::find(pipsBegin(), pipsEnd(), inPip) != pipsEnd();
91  }
92  /// \brief Adds the given instance pin as a source for this net.
93  /// \details Duplicate sources are not currently discarded.
94  void addSource(InstancePinSharedPtr& inInstancePinPtr) {
95  /// \todo Acquire mutex.
96  mSources.push_back(inInstancePinPtr);
97  inInstancePinPtr->setParentWeakPtr(mSelfWeakPtr);
98  inInstancePinPtr->addToInstance();
99 // inInstancePinPtr->getInstancePtr().lock()->addPin(inInstancePinPtr);
100  /// \todo Release mutex.
101  }
102  /// \brief Adds the given instance pin as a sink for this net.
103  /// \details Duplicate sinks are not currently discarded.
104  void addSink(InstancePinSharedPtr& inInstancePinPtr) {
105  /// \todo Acquire mutex.
106  mSinks.push_back(inInstancePinPtr);
107  inInstancePinPtr->setParentWeakPtr(mSelfWeakPtr);
108  inInstancePinPtr->addToInstance();
109 // inInstancePinPtr->getInstancePtr().lock()->addPin(inInstancePinPtr);
110  /// \todo Release mutex.
111  }
112  /// \brief Removes the given instance pin from the sources of this net.
113  /// \returns true if the instance pin was removed from the source list, or false if it was
114  /// not found.
115  bool removeSource(InstancePinSharedPtr& inInstancePinPtr) {
116  /// \todo Acquire mutex.
118  InstancePinSharedPtrIterator result = std::find(sourcesBegin(), e, inInstancePinPtr);
119  if(result == e) return false;
120  inInstancePinPtr->removeFromInstance();
121  mSources.erase(result);
122  /// \todo Release mutex.
123  return true;
124  }
125  /// \brief Removes the given instance pin from the sinks of this net.
126  /// \returns true if the instance pin was removed from the sink list, or false if it was
127  /// not found.
128  bool removeSink(InstancePinSharedPtr& inInstancePinPtr) {
129  /// \todo Acquire mutex.
131  InstancePinSharedPtrIterator result = std::find(sinksBegin(), e, inInstancePinPtr);
132  if(result == e) return false;
133  inInstancePinPtr->removeFromInstance();
134  mSinks.erase(result);
135  /// \todo Release mutex.
136  return true;
137  }
138  /// \brief Adds the given pip to this net.
139  /// \details Duplicate pips are not currently discarded.
140  void addPip(const Pip& inPip) {
141  /// \todo Acquire mutex.
142  mPips.push_back(inPip);
143  const_cast<Pip&>(inPip).setParentWeakPtr(mSelfWeakPtr);
144  /// \todo Release mutex.
145  }
146  /// \brief Removes the given pip from this net.
147  /// \returns true if the pip was removed from this net, or false if it was not found.
148  bool removePip(const Pip& inPip) {
149  /// \todo Acquire mutex.
150  // look up the pip
151  PipIterator e = pipsEnd();
152  PipIterator result = std::find(pipsBegin(), e, inPip);
153  // do nothing if the pip doesn't exist
154  if(result == e) return false;
155  // erase the pip
156  mPips.erase(result);
157  /// \todo Release mutex.
158  return true;
159  }
160  /// \brief Unroute the net.
161  /// \details The net is unrouted by clearing its pip list.
162  void unroute(void) {
163  mPips.clear();
164  }
165  // tests
166  /// \brief Returns true if the net has any sources.
167  bool hasAnySources(void) const { return !mSources.empty(); }
168  /// \brief Returns true if the net has exactly one source.
169  bool hasOneSource(void) const { return mSources.size() == 1; }
170  /// \brief Returns true if the net has more than one source.
171  bool hasMultipleSources(void) const { return mSources.size() > 1; }
172  /// \brief Returns the number of sources on the net.
173  size_t getSourceCount(void) const { return mSources.size(); }
174  /// \brief Returns true if the net has any sinks.
175  bool hasAnySinks(void) const { return !mSinks.empty(); }
176  /// \brief Returns true if the net has exactly one sink.
177  bool hasOneSink(void) const { return mSinks.size() == 1; }
178  /// \brief Returns true if the next has more than one sink.
179  bool hasMultipleSinks(void) const { return mSinks.size() > 1; }
180  /// \brief Returns the number of sinks on the net.
181  size_t getSinkCount(void) const { return mSinks.size(); }
182  /// \brief Returns true if the net has any pips.
183  bool hasAnyPips(void) const { return !mPips.empty(); }
184  /// \brief Returns the number of pips on the net.
185  size_t getPipCount(void) const { return mPips.size(); }
186  /// \brief Returns true if the net has any pips.
187  bool isRouted(void) const { return hasAnyPips(); }
188  /// \brief Returns true if the net has no pips.
189  bool isUnrouted(void) const { return !hasAnyPips(); }
190  // iterators
191  /// \brief Returns the begin constant iterator for source instance pins.
193  /// \brief Returns the end constant iterator for source instance pins.
195  /// \brief Returns the begin non-constant iterator for source instance pins.
197  /// \brief Returns the end non-constant iterator for source instance pins.
199  /// \brief Returns the begin constant iterator for sink instance pins.
200  InstancePinSharedPtrConstIterator sinksBegin(void) const { return mSinks.begin(); }
201  /// \brief Returns the end constant iterator for sink instance pins.
202  InstancePinSharedPtrConstIterator sinksEnd(void) const { return mSinks.end(); }
203  /// \brief Returns the begin non-constant iterator for sink instance pins.
205  /// \brief Returns the end non-constant iterator for sink instance pins.
207  /// \brief Returns the begin constant iterator for pips.
208  PipConstIterator pipsBegin(void) const { return mPips.begin(); }
209  /// \brief Returns the end constant iterator for pips.
210  PipConstIterator pipsEnd(void) const { return mPips.end(); }
211  /// \brief Returns the begin non-constant iterator for pips.
212  PipIterator pipsBegin(void) { return mPips.begin(); }
213  /// \brief Returns the end non-constant iterator for pips.
214  PipIterator pipsEnd(void) { return mPips.end(); }
215  // accessors
216  /// \brief Returns the net power type. See ENetPowerType.
217  ENetType getNetType(void) const { return mNetType; }
218  /// \brief Sets the net power type. See ENetPowerType.
219  void setNetType(ENetType inNetType) { mNetType = inNetType; }
220  // operators
221  /// \brief Equality operator.
222  /// \details This function deems nets equal if their names are identical.
223  /// \param rhs The net to compare against.
224  /// \returns true if both net names are identical, or false otherwise.
225  bool operator ==(const Net& rhs) const { return mName == rhs.mName; }
226  };
227 
228  /// \brief Shared pointer encapsulation of a Net.
229  typedef boost::shared_ptr<Net> NetSharedPtr;
230 
231  /// \brief Weak pointer encapsulation of a Net.
232  typedef boost::weak_ptr<Net> NetWeakPtr;
233 
234  /// \brief Vector of Net shared pointers.
235  typedef std::vector<NetSharedPtr> NetSharedPtrVector;
236 
237 } // namespace physical
238 } // namespace torc
239 
240 #endif // TORC_PHYSICAL_NET_HPP
InstancePinSharedPtrConstIterator sinksBegin(void) const
Returns the begin constant iterator for sink instance pins.
bool isRouted(void) const
Returns true if the net has any pips.
ENetType
Enumeration of net power types.
Header for the Renamable class.
InstancePinSharedPtrIterator sinksBegin(void)
Returns the begin non-constant iterator for sink instance pins.
bool hasAnyPips(void) const
Returns true if the net has any pips.
size_t getPipCount(void) const
Returns the number of pips on the net.
Header for the ConfigMap class.
InstancePinSharedPtrConstIterator sourcesEnd(void) const
Returns the end constant iterator for source instance pins.
void setParentWeakPtr(WeakPtrType inParentPtr)
Sets the weak pointer to the parent.
Definition: Progeny.hpp:49
ENetType getNetType(void) const
Returns the net power type. See ENetPowerType.
InstancePinSharedPtrConstIterator sinksEnd(void) const
Returns the end constant iterator for sink instance pins.
PipIterator pipsEnd(void)
Returns the end non-constant iterator for pips.
bool removeSource(InstancePinSharedPtr &inInstancePinPtr)
Removes the given instance pin from the sources of this net.
bool hasMultipleSources(void) const
Returns true if the net has more than one source.
Net(const string &inName, ENetType inNetType)
Protected constructor.
PipVector::const_iterator PipConstIterator
Constant iterator to Pip objects.
string mName
The name of the object.
Definition: Named.hpp:43
void setNetType(ENetType inNetType)
Sets the net power type. See ENetPowerType.
InstancePinSharedPtrVector::iterator InstancePinSharedPtrIterator
Non-constant iterator to InstancePin shared pointer objects.
bool removePip(const Pip &inPip)
Removes the given pip from this net.
void addSink(InstancePinSharedPtr &inInstancePinPtr)
Adds the given instance pin as a sink for this net.
std::vector< InstancePinSharedPtr > InstancePinSharedPtrVector
Vector of InstancePin shared pointers.
Header for the Routethrough class.
size_t getSinkCount(void) const
Returns the number of sinks on the net.
InstancePinSharedPtrVector mSources
Vector of instance pin shared pointer sources for the net.
boost::shared_ptr< class InstancePin > InstancePinSharedPtr
Shared pointer encapsulation of an InstancePin.
bool hasOneSink(void) const
Returns true if the net has exactly one sink.
InstancePinSharedPtrVector mSinks
Vector of instance pin shared pointer sinks for the net.
InstancePinSharedPtrConstIterator sourcesBegin(void) const
Returns the begin constant iterator for source instance pins.
std::string string
PipIterator pipsBegin(void)
Returns the begin non-constant iterator for pips.
InstancePinSharedPtrIterator sourcesEnd(void)
Returns the end non-constant iterator for source instance pins.
ENetType mNetType
The net power type. See ENetType.
Header for the Progenitor class.
Header for the Annotated class.
InstancePinSharedPtrIterator sourcesBegin(void)
Returns the begin non-constant iterator for source instance pins.
bool hasAnySinks(void) const
Returns true if the net has any sinks.
bool isUnrouted(void) const
Returns true if the net has no pips.
bool containsSink(InstancePinSharedPtr &inInstancePinPtr) const
Determines whether the given instance pin is a sink of this net.
void addPip(const Pip &inPip)
Adds the given pip to this net.
Header for the Named class.
Physical design net.
PipConstIterator pipsBegin(void) const
Returns the begin constant iterator for pips.
size_t getSourceCount(void) const
Returns the number of sources on the net.
PipVector mPips
Vector of pips for the net.
std::vector< NetSharedPtr > NetSharedPtrVector
Vector of Net shared pointers.
boost::shared_ptr< Net > NetSharedPtr
Shared pointer encapsulation of a Net.
boost::weak_ptr< Net > NetWeakPtr
Weak pointer encapsulation of a Net.
bool containsSource(InstancePinSharedPtr &inInstancePinPtr) const
Determines whether the given instance pin is a source of this net.
Factory class for physical netlist elements.
Concept for any object that may have children.
Definition: Progenitor.hpp:36
InstancePinSharedPtrVector::const_iterator InstancePinSharedPtrConstIterator
Constant iterator to InstancePin shared pointer objects.
Concept for any object that may have a parent.
Definition: Progeny.hpp:29
Header for the Progeny class.
Concept for any object that can be renamed.
Physical design programmable interconnect point.
Definition: Pip.hpp:34
std::string string
Imported type name.
Configuration setting map.
Definition: ConfigMap.hpp:39
void unroute(void)
Unroute the net.
InstancePinSharedPtrIterator sinksEnd(void)
Returns the end non-constant iterator for sink instance pins.
PipConstIterator pipsEnd(void) const
Returns the end constant iterator for pips.
bool containsPip(const Pip &inPip) const
Determines whether the net contains the given pip.
bool hasMultipleSinks(void) const
Returns true if the next has more than one sink.
Header for the Pip class.
void addSource(InstancePinSharedPtr &inInstancePinPtr)
Adds the given instance pin as a source for this net.
Circuit composed of instances and nets.
Definition: Circuit.hpp:46
WeakPtrType mSelfWeakPtr
Weak pointer this object.
Definition: Progenitor.hpp:57
bool removeSink(InstancePinSharedPtr &inInstancePinPtr)
Removes the given instance pin from the sinks of this net.
bool operator==(const Net &rhs) const
Equality operator.
Header for the InstancePin class.
bool hasAnySources(void) const
Returns true if the net has any sources.
Concept for any object that can be annotated.
Definition: Annotated.hpp:29
PipVector::iterator PipIterator
Non-constant iterator to Pip objects.
bool hasOneSource(void) const
Returns true if the net has exactly one source.
std::vector< Pip > PipVector
Vector of pips.
Definition: Pip.hpp:95