OpenASIP  2.0
OperationTriggeredField.cc
Go to the documentation of this file.
1 /*
2  Copyright (c) 2002-2021 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 OperationTriggeredField.cc
26  *
27  * Implementation of OperationTriggeredField class.
28  *
29  * @author Kari Hepola 2022 (kari.hepola@tuni.fi)
30  * @note rating: red
31  */
32 
35 #include "ObjectState.hh"
36 
37 const std::string OperationTriggeredField::OSNAME_FIELD = "ota-field";
38 const std::string OperationTriggeredField::OSKEY_PIECE_NAME = "piece";
39 const std::string OperationTriggeredField::OSKEY_START_NAME = "start";
40 const std::string OperationTriggeredField::OSKEY_WIDTH_NAME = "width";
41 
42 /**
43  * The constructor.
44  *
45  * Registers the field encoding to the parent
46  * binary encoding automatically.
47  *
48  * @param parent The parent binaryEncoding.
49  */
50 
52  OperationTriggeredEncoding& parent, int piece, int start, int width)
53  : piece_(piece), start_(start), width_(width) {
54  parent.addField(*this);
55 }
56 
57 /**
58  * The constructor
59  *
60  * Loads the state of the field encoding from
61  * the given ObjectState tree
62  *
63  * @param state The ObjectState tree
64  * @param parent The parent operation triggered encoding
65  * @exception ObjectStateLoadingException If an error occurs while loading
66  the state.
67  */
68 
70  const ObjectState* state, OperationTriggeredEncoding& parent) {
71  parent.addField(*this);
72  loadState(state);
73 }
74 
75 /**
76  * Returns the piece index that indicates the index of the encoding piece.
77  *
78  * @return The encoding piece index.
79  */
80 
81 int
83  return piece_;
84 }
85 
86 void
88  piece_ = piece;
89 }
90 
91 /**
92  * Returns the piece index that indicates the index of the encoding piece.
93  *
94  * @return The encoding piece index.
95  */
96 
97 int
99  return start_;
100 }
101 
102 void
104  start_ = start;
105 }
106 
107 /**
108  * Always returns 0 because field encoding does not
109  * have any child fields.
110  *
111  * @return 0
112  */
113 
114 int
116  return 0;
117 }
118 
119 /**
120  * Returns the bit width of the field encoding
121  *
122  * @return The bit width of the field encoding.
123  */
124 
125 int
127  return width_;
128 }
129 
130 void
132  width_ = width;
133 }
134 
135 /**
136  * Loads the state of the field
137  * encoding from the given ObjectState tree.
138  *
139  * @param state The ObjectState tree.
140  * @exception ObjectStateLoadingException If an error occurs while loading
141  * the state.
142  */
143 
144 void
146  ObjectState* newState = new ObjectState(*state);
147 
148  try {
149  piece_ = newState->intAttribute(OSKEY_PIECE_NAME);
150  start_ = newState->intAttribute(OSKEY_START_NAME);
151  width_ = newState->intAttribute(OSKEY_WIDTH_NAME);
152 
153  } catch (const Exception& exception) {
154  const std::string procName = "OperationTriggeredField::loadState";
156  __FILE__, __LINE__, procName, exception.errorMessage());
157  }
158 
159  delete newState;
160 }
161 
162 /**
163  * Saves the state of the field encoding
164  * to an ObjectState tree.
165  *
166  * @return The newly created ObjectState tree.
167  */
168 
171  ObjectState* state = new ObjectState(OSNAME_FIELD);
175 
176  return state;
177 }
OperationTriggeredEncoding.hh
OperationTriggeredField::setWidth
void setWidth(int width)
Definition: OperationTriggeredField.cc:131
OperationTriggeredField.hh
OperationTriggeredField::OSKEY_PIECE_NAME
static const std::string OSKEY_PIECE_NAME
Definition: OperationTriggeredField.hh:66
OperationTriggeredField::start
int start() const
Definition: OperationTriggeredField.cc:98
ObjectStateLoadingException
Definition: Exception.hh:551
OperationTriggeredField::OSNAME_FIELD
static const std::string OSNAME_FIELD
Definition: OperationTriggeredField.hh:65
ObjectState
Definition: ObjectState.hh:59
OperationTriggeredField::childFieldCount
virtual int childFieldCount() const
Definition: OperationTriggeredField.cc:115
OperationTriggeredField::loadState
virtual void loadState(const ObjectState *state)
Definition: OperationTriggeredField.cc:145
OperationTriggeredEncoding::addField
void addField(OperationTriggeredField &field)
Definition: OperationTriggeredEncoding.cc:138
OperationTriggeredField::saveState
virtual ObjectState * saveState() const
Definition: OperationTriggeredField.cc:170
OperationTriggeredField::piece
int piece() const
Definition: OperationTriggeredField.cc:82
ObjectState.hh
OperationTriggeredField::OSKEY_WIDTH_NAME
static const std::string OSKEY_WIDTH_NAME
Definition: OperationTriggeredField.hh:68
OperationTriggeredEncoding
Definition: OperationTriggeredEncoding.hh:44
OperationTriggeredField::OperationTriggeredField
OperationTriggeredField(const ObjectState *state, OperationTriggeredEncoding &parent)
Definition: OperationTriggeredField.cc:69
Exception
Definition: Exception.hh:54
OperationTriggeredField::start_
int start_
Definition: OperationTriggeredField.hh:72
Exception::errorMessage
std::string errorMessage() const
Definition: Exception.cc:123
OperationTriggeredField::width_
int width_
Definition: OperationTriggeredField.hh:73
OperationTriggeredField::setStart
void setStart(int start)
Definition: OperationTriggeredField.cc:103
OperationTriggeredField::width
virtual int width() const
Definition: OperationTriggeredField.cc:126
ObjectState::intAttribute
int intAttribute(const std::string &name) const
Definition: ObjectState.cc:276
OperationTriggeredField::setPiece
void setPiece(int piece)
Definition: OperationTriggeredField.cc:87
OperationTriggeredField::OSKEY_START_NAME
static const std::string OSKEY_START_NAME
Definition: OperationTriggeredField.hh:67
ObjectState::setAttribute
void setAttribute(const std::string &name, const std::string &value)
Definition: ObjectState.cc:100
OperationTriggeredField::piece_
int piece_
Definition: OperationTriggeredField.hh:71