2 Copyright (c) 2002-2010 Tampere University.
4 This file is part of TTA-Based Codesign Environment (TCE).
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:
13 The above copyright notice and this permission notice shall be included in
14 all copies or substantial portions of the Software.
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.
25 * @file ObjectState.icc
27 * Inline implementation of ObjectState class.
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
35 #include "Conversion.hh"
36 #include "TCEString.hh"
37 #include <boost/format.hpp>
40 * Returns the parent of the ObjectState instance.
42 * If there is no parent, returns null pointer.
44 * @return Parent of the ObjectState instance.
47 ObjectState::parent() const {
53 * Returns the name of the object.
55 * @return Name of the object.
58 ObjectState::name() const {
64 * Sets the name of the object.
66 * @param name The new name.
69 ObjectState::setName(const std::string& name) {
75 * Sets the value of the object.
77 * @param value Value of the object.
80 ObjectState::setValue(const std::string& value) {
86 * Sets the value of the object.
88 * @param value Value of the object.
91 ObjectState::setValue(int value) {
92 value_ = Conversion::toString(value);
96 * Sets the value of the object.
98 * @param value Value of the object.
101 ObjectState::setValue(unsigned value) {
102 value_ = Conversion::toString(value);
106 * Sets the value of the object.
108 * @param value Value of the object.
111 ObjectState::setValue(double value) {
112 value_ = Conversion::toString(value);
117 * Sets the value of the object.
119 * @param value Value of the object.
122 ObjectState::setValue(bool value) {
123 value_ = Conversion::toString(value);
128 * Returns the value of the node.
130 * @return Value of the node.
133 ObjectState::stringValue() const {
139 * Returns the value of the node.
141 * @return Value of the node.
142 * @exception NumberFormatException If the value cannot be converted to int.
145 ObjectState::intValue() const {
146 return Conversion::toInt(value_);
150 * Returns the value of the node.
152 * @return Value of the node.
153 * @exception NumberFormatException If the value cannot be converted to int.
156 ObjectState::unsignedIntValue() const {
157 return Conversion::toUnsignedInt(value_);
161 * Returns the value of the node.
163 * @return Value of the node.
164 * @exception NumberFormatException If the value cannot be converted to
168 ObjectState::doubleValue() const {
169 return Conversion::toDouble(value_);
173 * Returns the value of the node.
175 * @return Value of the node.
176 * @exception TypeMismatch If the value cannot be converted to boolean.
179 ObjectState::boolValue() const {
182 intValue = this->intValue();
183 } catch (const NumberFormatException& exception) {
184 TCEString strValue = this->stringValue();
185 strValue = strValue.lower();
186 if (strValue == "false") {
188 } else if (strValue == "true") {
192 __FILE__, __LINE__, __func__,
193 (boost::format("Cannot convert '%s' to a boolean.") %
202 * Returns the number of attributes of the ObjectState instance.
204 * @return Number of attributes.
207 ObjectState::attributeCount() const {
208 return attributes_.size();
213 * Returns the number of child instances of the ObjectState instance.
215 * @return The number of children.
218 ObjectState::childCount() const {
219 return children_.size();