torc-master
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Element.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 #ifndef TORC_PACKER_ELEMENT_HPP
17 #define TORC_PACKER_ELEMENT_HPP
18 
19 #include <string>
20 #include <map>
21 #include <algorithm>
22 #include <iostream>
23 #include <sstream>
24 #include <iterator>
25 #include <functional>
26 #include <boost/smart_ptr.hpp>
27 
30 
31 namespace torc {
32 namespace physical {
33 
34  using namespace std;
35 
36  typedef vector<string> ConfigVector;
37 
38 
39  /// \brief Element composed of connections and pins.
40  /// \details This class implements everything for XDLRC elements.
41  class Element : public Component{
42  // friends
43  /// \brief The Factory class has direct access to our internals.
44  friend class RcFactory;
45  protected:
46 
49 
50  /// \brief Constructor.
51  Element(const string& inName) : Component(inName){}
52  public:
53 
54  typedef ConnectionSharedPtrVector::const_iterator ConnectionSharedPtrConstIterator;
55  typedef ConnectionSharedPtrVector::iterator ConnectionSharedPtrIterator;
56 
57  typedef ConfigVector::const_iterator ConfigConstIterator;
58  typedef ConfigVector::iterator ConfigIterator;
59 
60 
61  bool addConnection(ConnectionSharedPtr& inConnectionPtr) {
62  /// \todo Acquire mutex.
63  mConnections.push_back(inConnectionPtr);
64  return true;
65  /// \todo Release mutex.
66  }
67  bool removeConnection(ConnectionSharedPtr& inConnectionPtr) {
68  /// \todo Acquire mutex.
69  ConnectionSharedPtrIterator e = connectionsEnd();
70  ConnectionSharedPtrIterator result = std::find(connectionsBegin(), e, inConnectionPtr);
71  if(result == e) return false;
72  mConnections.erase(result);
73  /// \todo Release mutex.
74  return true;
75  }
76 
78  /// \todo Acquire mutex.
79 
80  mConnections.erase(inConnectionIter);
81  /// \todo Release mutex.
82  return true;
83  }
84 
85  // connection iterators
86  ConnectionSharedPtrConstIterator connectionsBegin(void) const { return mConnections.begin(); }
87  ConnectionSharedPtrConstIterator connectionsEnd(void) const { return mConnections.end(); }
88  ConnectionSharedPtrIterator connectionsBegin(void) { return mConnections.begin(); }
89  ConnectionSharedPtrIterator connectionsEnd(void) { return mConnections.end(); }
90  size_t getConnectionCount(void) const { return mConnections.size(); }
91 
92  bool addConfig(string& inConfigPtr) {
93  /// \todo Acquire mutex.
94  ConfigIterator e = mConfigs.end();
95  ConfigIterator result = std::find(mConfigs.begin(), e, inConfigPtr);
96  if(result != e) return false;
97  mConfigs.push_back(inConfigPtr);
98  return true;
99  /// \todo Release mutex.
100  }
101  bool removeConfig(string& inConfigPtr) {
102  /// \todo Acquire mutex.
103  ConfigIterator e = mConfigs.end();
104  ConfigIterator result = std::find(mConfigs.begin(), e, inConfigPtr);
105  if(result == e) return false;
106  mConfigs.erase(result);
107  /// \todo Release mutex.
108  return true;
109  }
110  // connection iterators
111  ConfigConstIterator confsBegin(void) const { return mConfigs.begin(); }
112  ConfigConstIterator confsEnd(void) const { return mConfigs.end(); }
113  ConfigIterator confsBegin(void) { return mConfigs.begin(); }
114  ConfigIterator confsEnd(void) { return mConfigs.end(); }
115  size_t getConfigCount(void) const { return mConfigs.size(); }
116  };
117 
118  /// \brief Shared pointer encapsulation of a element.
119  typedef boost::shared_ptr<Element> ElementSharedPtr;
120 
121  /// \brief Weak pointer encapsulation of a element.
122  typedef boost::weak_ptr<Element> ElementWeakPtr;
123 
124  /// \brief Vector of element shared pointers.
125  typedef std::vector<ElementSharedPtr> ElementSharedPtrVector;
126 
127 
128 } // namespace physical
129 } // namespace torc
130 
131 #endif // TORC_PACKER_ELEMENT_HPP
size_t getConnectionCount(void) const
Definition: Element.hpp:90
ConnectionSharedPtrIterator connectionsBegin(void)
Definition: Element.hpp:88
ConnectionSharedPtrVector mConnections
Definition: Element.hpp:47
boost::shared_ptr< Element > ElementSharedPtr
Shared pointer encapsulation of a element.
Definition: Element.hpp:119
bool removeConnection(ConnectionSharedPtrIterator inConnectionIter)
Definition: Element.hpp:77
RcFactory class for physical netlist elements.
Definition: RcFactory.hpp:34
Element(const string &inName)
Constructor.
Definition: Element.hpp:51
boost::weak_ptr< Element > ElementWeakPtr
Weak pointer encapsulation of a element.
Definition: Element.hpp:122
bool removeConfig(string &inConfigPtr)
Definition: Element.hpp:101
ConfigVector::iterator ConfigIterator
Definition: Element.hpp:58
bool addConfig(string &inConfigPtr)
Definition: Element.hpp:92
ConnectionSharedPtrIterator connectionsEnd(void)
Definition: Element.hpp:89
ConnectionSharedPtrVector::const_iterator ConnectionSharedPtrConstIterator
Definition: Element.hpp:54
size_t getConfigCount(void) const
Definition: Element.hpp:115
ConfigConstIterator confsBegin(void) const
Definition: Element.hpp:111
ConfigVector::const_iterator ConfigConstIterator
Definition: Element.hpp:57
ConnectionSharedPtrConstIterator connectionsEnd(void) const
Definition: Element.hpp:87
ConfigConstIterator confsEnd(void) const
Definition: Element.hpp:112
bool addConnection(ConnectionSharedPtr &inConnectionPtr)
Definition: Element.hpp:61
std::vector< ConnectionSharedPtr > ConnectionSharedPtrVector
Vector of componenet shared pointers.
Definition: Connection.hpp:88
boost::shared_ptr< Connection > ConnectionSharedPtr
Shared pointer encapsulation of a componenet.
Definition: Connection.hpp:82
ConfigVector mConfigs
Definition: Element.hpp:48
Hierarchical componenet.
Definition: Component.hpp:30
Element composed of connections and pins.
Definition: Element.hpp:41
vector< string > ConfigVector
Definition: Element.hpp:36
std::vector< ElementSharedPtr > ElementSharedPtrVector
Vector of element shared pointers.
Definition: Element.hpp:125
ConnectionSharedPtrVector::iterator ConnectionSharedPtrIterator
Definition: Element.hpp:55
ConfigIterator confsEnd(void)
Definition: Element.hpp:114
ConfigIterator confsBegin(void)
Definition: Element.hpp:113
ConnectionSharedPtrConstIterator connectionsBegin(void) const
Definition: Element.hpp:86
bool removeConnection(ConnectionSharedPtr &inConnectionPtr)
Definition: Element.hpp:67