OpenASIP  2.0
DestinationField.cc
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 DestinationField.cc
26  *
27  * Implementation of DestinationField class.
28  *
29  * @author Lasse Laasonen 2005 (lasse.laasonen-no.spam-tut.fi)
30  * @note rating: red
31  */
32 
33 #include <string>
34 
35 #include "DestinationField.hh"
36 #include "MoveSlot.hh"
37 #include "Application.hh"
38 #include "ObjectState.hh"
39 
40 using std::string;
41 
42 const std::string DestinationField::OSNAME_DESTINATION_FIELD = "dest_field";
43 
44 /**
45  * The constructor.
46  *
47  * Registers the destination field to the given move slot automatically.
48  *
49  * @param socketIDPos Position of the socket ID within the destination field.
50  * @param parent The parent move slot.
51  * @exception ObjectAlreadyExists If the parent move slot already has a
52  * destination field.
53  * @exception IllegalParameters If the given socket ID position is not the same
54  * with other destination fields.
55  */
57  BinaryEncoding::Position socketIDPos, MoveSlot& parent)
58  : SlotField(socketIDPos, parent) {
59  BinaryEncoding* bem = parent.parent();
60  for (int i = 0; i < bem->moveSlotCount(); i++) {
61  MoveSlot& slot = bem->moveSlot(i);
62  if (slot.hasDestinationField() &&
63  slot.destinationField().componentIDPosition() != socketIDPos) {
64  const string procName = "SourceField::SourceField";
65  throw IllegalParameters(__FILE__, __LINE__, procName);
66  } else {
67  break;
68  }
69  }
70 
71  setParent(NULL);
73  setParent(&parent);
74 }
75 
76 /**
77  * The constructor.
78  *
79  * Loads the state of the object from the given ObjectState tree.
80  *
81  * @param state The ObjectState tree.
82  * @param parent The parent move slot.
83  * @exception ObjectStateLoadingException If an error occurs while loading the
84  * state.
85  * @exception ObjectAlreadyExists If the parent move slot already has a
86  * destination field.
87  */
89  : SlotField(state, parent) {
90  if (state->name() != OSNAME_DESTINATION_FIELD) {
91  const string procName = "DestinationField::DestinationField";
92  throw ObjectStateLoadingException(__FILE__, __LINE__, procName);
93  }
94 
95  setParent(NULL);
97  setParent(&parent);
98 }
99 
100 /**
101  * The destructor.
102  */
104  MoveSlot* parent = this->parent();
105  assert(parent != NULL);
106  setParent(NULL);
108 }
109 
110 
111 /**
112  * Saves the state of the object to an ObjectState tree.
113  *
114  * @return The newly created ObjectState tree.
115  */
120  return state;
121 }
BinaryEncoding
Definition: BinaryEncoding.hh:61
MoveSlot
Definition: MoveSlot.hh:60
ObjectStateLoadingException
Definition: Exception.hh:551
SlotField::saveState
virtual ObjectState * saveState() const
Definition: SlotField.cc:388
ObjectState
Definition: ObjectState.hh:59
MoveSlot::unsetDestinationField
void unsetDestinationField()
Definition: MoveSlot.cc:314
ObjectState::setName
void setName(const std::string &name)
MoveSlot.hh
assert
#define assert(condition)
Definition: Application.hh:86
IllegalParameters
Definition: Exception.hh:113
BinaryEncoding::Position
Position
Definition: BinaryEncoding.hh:63
MoveSlot::hasDestinationField
bool hasDestinationField() const
Definition: MoveSlot.cc:327
Application.hh
InstructionField::setParent
void setParent(InstructionField *parent)
Definition: InstructionField.cc:282
ObjectState.hh
DestinationField::OSNAME_DESTINATION_FIELD
static const std::string OSNAME_DESTINATION_FIELD
ObjectState name for destination field.
Definition: DestinationField.hh:54
SlotField::componentIDPosition
BinaryEncoding::Position componentIDPosition() const
Definition: SlotField.cc:296
DestinationField::saveState
virtual ObjectState * saveState() const
Definition: DestinationField.cc:117
ObjectState::name
std::string name() const
DestinationField::DestinationField
DestinationField(BinaryEncoding::Position socketIDPos, MoveSlot &parent)
Definition: DestinationField.cc:56
DestinationField::~DestinationField
virtual ~DestinationField()
Definition: DestinationField.cc:103
MoveSlot::parent
BinaryEncoding * parent() const
Definition: MoveSlot.cc:118
SlotField
Definition: SlotField.hh:58
MoveSlot::setDestinationField
void setDestinationField(DestinationField &field)
Definition: MoveSlot.cc:296
BinaryEncoding::moveSlot
MoveSlot & moveSlot(int index) const
Definition: BinaryEncoding.cc:121
MoveSlot::destinationField
DestinationField & destinationField() const
Definition: MoveSlot.cc:341
DestinationField.hh
BinaryEncoding::moveSlotCount
int moveSlotCount() const
Definition: BinaryEncoding.cc:104
SlotField::parent
MoveSlot * parent() const
Definition: SlotField.cc:98