OpenASIP  2.0
Unit.hh
Go to the documentation of this file.
1 /*
2  Copyright (c) 2002-2009 Tampere University.
3 
4  This file is part of TTA-Based Codesign Environment (TCE).
5 
6  Permission is hereby granted, free of charge, to any person obtaining a
7  copy of this software and associated documentation files (the "Software"),
8  to deal in the Software without restriction, including without limitation
9  the rights to use, copy, modify, merge, publish, distribute, sublicense,
10  and/or sell copies of the Software, and to permit persons to whom the
11  Software is furnished to do so, subject to the following conditions:
12 
13  The above copyright notice and this permission notice shall be included in
14  all copies or substantial portions of the Software.
15 
16  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
19  THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21  FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
22  DEALINGS IN THE SOFTWARE.
23  */
24 /**
25  * @file Unit.hh
26  *
27  * Declaration of Unit class.
28  *
29  * @author Lasse Laasonen 2003 (lasse.laasonen-no.spam-tut.fi)
30  * @note rating: red
31  * @note reviewed 22 Jun 2004 by ao, ml, vpj, ll
32  */
33 
34 #ifndef TTA_UNIT_HH
35 #define TTA_UNIT_HH
36 
37 #include <string>
38 #include <vector>
39 #include <set>
40 
41 #include "MachinePart.hh"
42 #include "Exception.hh"
43 
44 namespace TTAMachine {
45 
46 class Port;
47 
48 /**
49  * An Abstract base class for the different units in the machine.
50  */
51 class Unit : public Component {
52 public:
53  virtual ~Unit();
54 
55  virtual bool hasPort(const std::string& name) const;
56  virtual Port* port(const std::string& name) const;
57  virtual Port* port(int index) const;
58  virtual int portCount() const;
59  virtual int outputPortCount(bool countBidir = false) const;
60  virtual int inputPortCount(bool countBidir = false) const;
61  virtual int bidirPortCount() const;
62 
63  virtual void setMachine(Machine& mach);
64  virtual void unsetMachine();
65 
66  virtual ObjectState* saveState() const;
67  virtual void loadState(const ObjectState* state);
68 
69  /// ObjectState name for Unit.
70  static const std::string OSNAME_UNIT;
71 
72 protected:
73  Unit(const std::string& name);
74  Unit(const ObjectState* state);
75 
76  virtual void removePort(Port& port);
77 
78 private:
79  /// Container for ports.
80  typedef std::vector<Port*> PortTable;
81  /// Set type for strings.
82  typedef std::set<std::string> NameSet;
83 
84  /// Copying forbidden.
85  Unit(const Unit&);
86  /// Assingment forbidden.
87  Unit& operator=(const Unit&);
88 
89  void addPort(Port& port);
90  void deleteAllPorts();
91  void deleteOtherPorts(const NameSet& portsToLeave);
92  static NameSet portNames(const ObjectState* state);
93  void loadStateWithoutReferences(const ObjectState* state);
94 
95  /// Contains all the ports of the unit.
97 
98  // Port is a friend class to be able add and remove itself from the unit
99  friend class Port;
100 };
101 }
102 
103 #endif
TTAMachine::Unit::addPort
void addPort(Port &port)
Definition: Unit.cc:213
TTAMachine::Component::name
virtual TCEString name() const
Definition: MachinePart.cc:125
Exception.hh
TTAMachine::Unit::removePort
virtual void removePort(Port &port)
Definition: Unit.cc:235
TTAMachine::Unit::deleteOtherPorts
void deleteOtherPorts(const NameSet &portsToLeave)
Definition: Unit.cc:389
TTAMachine::Unit::deleteAllPorts
void deleteAllPorts()
Definition: Unit.cc:373
TTAMachine::Unit::loadState
virtual void loadState(const ObjectState *state)
Definition: Unit.cc:309
ObjectState
Definition: ObjectState.hh:59
TTAMachine::Unit::bidirPortCount
virtual int bidirPortCount() const
Definition: Unit.cc:174
TTAMachine::Unit::operator=
Unit & operator=(const Unit &)
Assingment forbidden.
MachinePart.hh
TTAMachine::Unit::ports_
PortTable ports_
Contains all the ports of the unit.
Definition: Unit.hh:96
TTAMachine::Unit::NameSet
std::set< std::string > NameSet
Set type for strings.
Definition: Unit.hh:82
TTAMachine::Unit::saveState
virtual ObjectState * saveState() const
Definition: Unit.cc:285
TTAMachine::Unit::~Unit
virtual ~Unit()
Definition: Unit.cc:84
TTAMachine::Unit
Definition: Unit.hh:51
TTAMachine::Port
Definition: Port.hh:54
TTAMachine::Unit::port
virtual Port * port(const std::string &name) const
Definition: Unit.cc:116
TTAMachine::Unit::PortTable
std::vector< Port * > PortTable
Container for ports.
Definition: Unit.hh:80
TTAMachine::Component
Definition: MachinePart.hh:90
TTAMachine::Unit::hasPort
virtual bool hasPort(const std::string &name) const
Definition: Unit.cc:96
TTAMachine::Unit::loadStateWithoutReferences
void loadStateWithoutReferences(const ObjectState *state)
Definition: Unit.cc:334
TTAMachine::Unit::portCount
virtual int portCount() const
Definition: Unit.cc:135
TTAMachine::Unit::outputPortCount
virtual int outputPortCount(bool countBidir=false) const
Definition: Unit.cc:145
TTAMachine::Unit::portNames
static NameSet portNames(const ObjectState *state)
Definition: Unit.cc:409
TTAMachine::Unit::inputPortCount
virtual int inputPortCount(bool countBidir=false) const
Definition: Unit.cc:160
TTAMachine::Unit::setMachine
virtual void setMachine(Machine &mach)
Definition: Unit.cc:253
TTAMachine::Unit::OSNAME_UNIT
static const std::string OSNAME_UNIT
ObjectState name for Unit.
Definition: Unit.hh:70
TTAMachine
Definition: Assembler.hh:48
TTAMachine::Unit::Unit
Unit(const std::string &name)
Definition: Unit.cc:59
TTAMachine::Unit::unsetMachine
virtual void unsetMachine()
Definition: Unit.cc:262
TTAMachine::Machine
Definition: Machine.hh:73