OpenASIP 2.2
Loading...
Searching...
No Matches
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
44class ObjectState;
45
46namespace TTAMachine {
47
48class Machine;
49
50////////////////////////////////////////////////////////////////////////////
51// MachinePart
52////////////////////////////////////////////////////////////////////////////
53
54/**
55 * Abstract base class for all the machine components.
56 */
57class MachinePart : public Serializable {
58public:
59 struct Comparator {
60 inline bool operator() (
61 const MachinePart* mp1,
62 const MachinePart* mp2) const;
63 };
64protected:
66 virtual ~MachinePart();
67private:
68 /// Copying forbidden.
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 */
90class Component : public MachinePart {
91public:
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
139protected:
140 Component(const std::string& name);
141 Component(const ObjectState* state);
142
145
146private:
147 /// Copying forbidden.
149 /// Assingment forbidden.
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 */
168class SubComponent : public MachinePart {
169protected:
170 SubComponent();
171 virtual ~SubComponent();
172
173private:
174 /// Copying forbidden.
176 /// Assingment forbidden.
178};
179}
180
181#include "MachinePart.icc"
182
183#endif
bool operator()(const Component *a, const Component *b) const
virtual void setName(const std::string &name)
virtual void unsetMachine()=0
virtual Machine * machine() const
Component(const Component &)
Copying forbidden.
virtual void loadState(const ObjectState *state)
static const std::string OSKEY_NAME
ObjectState attribute key for the name of the component.
virtual void setMachine(Machine &machine)=0
static const std::string OSNAME_COMPONENT
ObjectState name for component.
Component & operator=(const Component &)
Assingment forbidden.
void internalSetMachine(Machine &machine)
std::string name_
Name of the component.
virtual bool isRegistered() const
Machine * machine_
Machine to which the component is registered.
virtual void ensureRegistration(const Component &component) const
virtual TCEString name() const
virtual ObjectState * saveState() const
static int idCounter_
Id just for comparison for sets and maps. More deterministic than pointer to the object.
MachinePart & operator=(const MachinePart &)
Assingment forbidden.
MachinePart(const MachinePart &)
Copying forbidden.
SubComponent & operator=(const SubComponent &)
Assingment forbidden.
SubComponent(const SubComponent &)
Copying forbidden.
bool operator()(const MachinePart *mp1, const MachinePart *mp2) const