OpenASIP  2.0
ObjectState.icc
Go to the documentation of this file.
1 /*
2  Copyright (c) 2002-2010 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 ObjectState.icc
26  *
27  * Inline implementation of ObjectState class.
28  *
29  * @author Lasse Laasonen 2003 (lasse.laasonen-no.spam-tut.fi)
30  * @author Pekka Jääskeläinen 2010
31  * @note reviewed 8 Jun 2004 by tr, jm, am, ll
32  * @note rating: red
33  */
34 
35 #include "Conversion.hh"
36 #include "TCEString.hh"
37 #include <boost/format.hpp>
38 
39 /**
40  * Returns the parent of the ObjectState instance.
41  *
42  * If there is no parent, returns null pointer.
43  *
44  * @return Parent of the ObjectState instance.
45  */
46 inline ObjectState*
47 ObjectState::parent() const {
48  return parent_;
49 }
50 
51 
52 /**
53  * Returns the name of the object.
54  *
55  * @return Name of the object.
56  */
57 inline std::string
58 ObjectState::name() const {
59  return name_;
60 }
61 
62 
63 /**
64  * Sets the name of the object.
65  *
66  * @param name The new name.
67  */
68 inline void
69 ObjectState::setName(const std::string& name) {
70  name_ = name;
71 }
72 
73 
74 /**
75  * Sets the value of the object.
76  *
77  * @param value Value of the object.
78  */
79 inline void
80 ObjectState::setValue(const std::string& value) {
81  value_ = value;
82 }
83 
84 
85 /**
86  * Sets the value of the object.
87  *
88  * @param value Value of the object.
89  */
90 inline void
91 ObjectState::setValue(int value) {
92  value_ = Conversion::toString(value);
93 }
94 
95 /**
96  * Sets the value of the object.
97  *
98  * @param value Value of the object.
99  */
100 inline void
101 ObjectState::setValue(unsigned value) {
102  value_ = Conversion::toString(value);
103 }
104 
105 /**
106  * Sets the value of the object.
107  *
108  * @param value Value of the object.
109  */
110 inline void
111 ObjectState::setValue(double value) {
112  value_ = Conversion::toString(value);
113 }
114 
115 
116 /**
117  * Sets the value of the object.
118  *
119  * @param value Value of the object.
120  */
121 inline void
122 ObjectState::setValue(bool value) {
123  value_ = Conversion::toString(value);
124 }
125 
126 
127 /**
128  * Returns the value of the node.
129  *
130  * @return Value of the node.
131  */
132 inline std::string
133 ObjectState::stringValue() const {
134  return value_;
135 }
136 
137 
138 /**
139  * Returns the value of the node.
140  *
141  * @return Value of the node.
142  * @exception NumberFormatException If the value cannot be converted to int.
143  */
144 inline int
145 ObjectState::intValue() const {
146  return Conversion::toInt(value_);
147 }
148 
149 /**
150  * Returns the value of the node.
151  *
152  * @return Value of the node.
153  * @exception NumberFormatException If the value cannot be converted to int.
154  */
155 inline unsigned int
156 ObjectState::unsignedIntValue() const {
157  return Conversion::toUnsignedInt(value_);
158 }
159 
160 /**
161  * Returns the value of the node.
162  *
163  * @return Value of the node.
164  * @exception NumberFormatException If the value cannot be converted to
165  * double.
166  */
167 inline double
168 ObjectState::doubleValue() const {
169  return Conversion::toDouble(value_);
170 }
171 
172 /**
173  * Returns the value of the node.
174  *
175  * @return Value of the node.
176  * @exception TypeMismatch If the value cannot be converted to boolean.
177  */
178 inline bool
179 ObjectState::boolValue() const {
180  int intValue;
181  try {
182  intValue = this->intValue();
183  } catch (const NumberFormatException& exception) {
184  TCEString strValue = this->stringValue();
185  strValue = strValue.lower();
186  if (strValue == "false") {
187  return false;
188  } else if (strValue == "true") {
189  return true;
190  } else {
191  throw TypeMismatch(
192  __FILE__, __LINE__, __func__,
193  (boost::format("Cannot convert '%s' to a boolean.") %
194  strValue).str());
195  }
196  }
197 
198  return intValue;
199 }
200 
201 /**
202  * Returns the number of attributes of the ObjectState instance.
203  *
204  * @return Number of attributes.
205  */
206 inline int
207 ObjectState::attributeCount() const {
208  return attributes_.size();
209 }
210 
211 
212 /**
213  * Returns the number of child instances of the ObjectState instance.
214  *
215  * @return The number of children.
216  */
217 inline int
218 ObjectState::childCount() const {
219  return children_.size();
220 }