OpenASIP  2.0
MachinePart.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 MachinePart.hh
26  *
27  * Declaration of MachinePart class and derived Component and SubComponent
28  * classes.
29  *
30  * @author Lasse Laasonen 2003 (lasse.laasonen-no.spam-tut.fi)
31  * @note reviewed 17 Jun 2004 by jn, pj, jm, ll
32  * @note rating: red
33  */
34 
35 #ifndef TTA_MACHINE_PART_HH
36 #define TTA_MACHINE_PART_HH
37 
38 #include <string>
39 
40 #include "Serializable.hh"
41 #include "Exception.hh"
42 #include "TCEString.hh"
43 
44 class ObjectState;
45 
46 namespace TTAMachine {
47 
48 class Machine;
49 
50 ////////////////////////////////////////////////////////////////////////////
51 // MachinePart
52 ////////////////////////////////////////////////////////////////////////////
53 
54 /**
55  * Abstract base class for all the machine components.
56  */
57 class MachinePart : public Serializable {
58 public:
59  struct Comparator {
60  inline bool operator() (
61  const MachinePart* mp1,
62  const MachinePart* mp2) const;
63  };
64 protected:
65  MachinePart();
66  virtual ~MachinePart();
67 private:
68  /// Copying forbidden.
69  MachinePart(const MachinePart&);
70  /// Assingment forbidden.
72  /// Id just for comparison for sets and maps.
73  /// More deterministic than pointer to the object.
74  static int idCounter_;
75  int id_;
76 };
77 
78 
79 ////////////////////////////////////////////////////////////////////////////
80 // Component
81 ////////////////////////////////////////////////////////////////////////////
82 
83 /**
84  * Abstract base class for top-level machine components.
85  *
86  * Top-level machine components, like Bus and Socket, are independently
87  * defined parts of a target machine. Components can be registered to (or
88  * unregistered from) a Machine.
89  */
90 class Component : public MachinePart {
91 public:
92  virtual ~Component();
93 
94  virtual TCEString name() const;
95  virtual void setName(const std::string& name);
96 
97  /**
98  * Registers component into given Machine.
99  *
100  * @param machine A Machine.
101  */
102  virtual void setMachine(Machine& machine) = 0;
103 
104  /**
105  * Removes component from its current Machine.
106  */
107  virtual void unsetMachine() = 0;
108 
109  virtual Machine* machine() const;
110  virtual void ensureRegistration(const Component& component) const;
111  virtual bool isRegistered() const;
112 
113  // methods inherited from Serializable interface
114  virtual ObjectState* saveState() const;
115  virtual void loadState(const ObjectState* state);
116 
117  /**
118  * Compares 2 Component's names lexicographically (dictionary order).
119  *
120  * Can be used to organize containers of type Component to dictionary
121  * order according to their name field.
122  *
123  * @param a the first Component to compare.
124  * @param b the second Component to compare.
125  * @return true, if a comes before b in dictionary order.
126  */
128  public:
129  bool operator () (const Component* a, const Component* b) const {
130  return (a->name()) < (b->name());
131  }
132  };
133 
134  /// ObjectState name for component.
135  static const std::string OSNAME_COMPONENT;
136  /// ObjectState attribute key for the name of the component.
137  static const std::string OSKEY_NAME;
138 
139 protected:
140  Component(const std::string& name);
141  Component(const ObjectState* state);
142 
144  void internalUnsetMachine();
145 
146 private:
147  /// Copying forbidden.
148  Component(const Component&);
149  /// Assingment forbidden.
150  Component& operator=(const Component&);
151 
152  /// Name of the component.
153  std::string name_;
154  /// Machine to which the component is registered.
156 };
157 
158 ////////////////////////////////////////////////////////////////////////////
159 // SubComponent
160 ////////////////////////////////////////////////////////////////////////////
161 
162 /**
163  * Abstract base class for non-top-level machine components.
164  *
165  * Subcomponents belong to and are directly managed by one Component (not by
166  * a Machine).
167  */
168 class SubComponent : public MachinePart {
169 protected:
170  SubComponent();
171  virtual ~SubComponent();
172 
173 private:
174  /// Copying forbidden.
175  SubComponent(const SubComponent&);
176  /// Assingment forbidden.
178 };
179 }
180 
181 #include "MachinePart.icc"
182 
183 #endif
MachinePart.icc
TTAMachine::Component::internalUnsetMachine
void internalUnsetMachine()
TTAMachine::Component::setName
virtual void setName(const std::string &name)
Definition: MachinePart.cc:142
TTAMachine::Component::setMachine
virtual void setMachine(Machine &machine)=0
TTAMachine::SubComponent
Definition: MachinePart.hh:168
TTAMachine::Component::operator=
Component & operator=(const Component &)
Assingment forbidden.
TTAMachine::Component::name
virtual TCEString name() const
Definition: MachinePart.cc:125
TTAMachine::Component::isRegistered
virtual bool isRegistered() const
Definition: MachinePart.cc:177
TTAMachine::SubComponent::operator=
SubComponent & operator=(const SubComponent &)
Assingment forbidden.
Exception.hh
TTAMachine::Component::ensureRegistration
virtual void ensureRegistration(const Component &component) const
Definition: MachinePart.cc:163
Serializable
Definition: Serializable.hh:44
TTAMachine::SubComponent::SubComponent
SubComponent()
Definition: MachinePart.cc:237
TTAMachine::Component::saveState
virtual ObjectState * saveState() const
Definition: MachinePart.cc:189
ObjectState
Definition: ObjectState.hh:59
TTAMachine::MachinePart::Comparator::operator()
bool operator()(const MachinePart *mp1, const MachinePart *mp2) const
TTAMachine::MachinePart::MachinePart
MachinePart()
Definition: MachinePart.cc:55
TTAMachine::Component::internalSetMachine
void internalSetMachine(Machine &machine)
TTAMachine::Component::machine_
Machine * machine_
Machine to which the component is registered.
Definition: MachinePart.hh:155
TCEString.hh
TTAMachine::MachinePart::~MachinePart
virtual ~MachinePart()
Definition: MachinePart.cc:62
TTAMachine::Component::Component
Component(const std::string &name)
Definition: MachinePart.cc:82
TTAMachine::MachinePart::idCounter_
static int idCounter_
Id just for comparison for sets and maps. More deterministic than pointer to the object.
Definition: MachinePart.hh:74
TTAMachine::Component::loadState
virtual void loadState(const ObjectState *state)
Definition: MachinePart.cc:205
TTAMachine::MachinePart::operator=
MachinePart & operator=(const MachinePart &)
Assingment forbidden.
TTAMachine::Component
Definition: MachinePart.hh:90
TTAMachine::MachinePart
Definition: MachinePart.hh:57
TTAMachine::Component::OSKEY_NAME
static const std::string OSKEY_NAME
ObjectState attribute key for the name of the component.
Definition: MachinePart.hh:137
TTAMachine::Component::unsetMachine
virtual void unsetMachine()=0
TTAMachine::MachinePart::id_
int id_
Definition: MachinePart.hh:75
Serializable.hh
TTAMachine::Component::ComponentNameComparator
Definition: MachinePart.hh:127
TTAMachine::Component::OSNAME_COMPONENT
static const std::string OSNAME_COMPONENT
ObjectState name for component.
Definition: MachinePart.hh:135
TTAMachine::Component::machine
virtual Machine * machine() const
TTAMachine::SubComponent::~SubComponent
virtual ~SubComponent()
Definition: MachinePart.cc:244
TCEString
Definition: TCEString.hh:53
TTAMachine::Component::ComponentNameComparator::operator()
bool operator()(const Component *a, const Component *b) const
Definition: MachinePart.hh:129
TTAMachine::Component::~Component
virtual ~Component()
Definition: MachinePart.cc:115
TTAMachine
Definition: Assembler.hh:48
TTAMachine::MachinePart::Comparator
Definition: MachinePart.hh:59
TTAMachine::Component::name_
std::string name_
Name of the component.
Definition: MachinePart.hh:153
TTAMachine::Machine
Definition: Machine.hh:73