OpenASIP 2.2
Loading...
Searching...
No Matches
ObjectState.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 ObjectState.hh
26 *
27 * Declaration of ObjectState class.
28 *
29 * @author Lasse Laasonen 2003 (lasse.laasonen-no.spam-tut.fi)
30 * @note reviewed 8 Jun 2004 by tr, jm, am, ll
31 * @note rating: red
32 */
33
34#ifndef TTA_OBJECT_STATE_HH
35#define TTA_OBJECT_STATE_HH
36
37#include <string>
38#include <vector>
39
40#include "Exception.hh"
41#include "BaseType.hh"
42
43/**
44 * Class ObjectState represents state of an object.
45 *
46 * It may contain attribute-value pairs of the object and a main
47 * value. It may be used as a node in tree structure or alone. If a
48 * class is going to be serialized to a file, it must be able to
49 * create an ObjectState object of itself. It must be able to create
50 * itself from an ObjectState object too. That is, it must implement
51 * the Serializable interface. ObjectState tree is a general
52 * structure which can be handled by many different kind of
53 * serializers, for example XMLSerializer. Serializers can read a file
54 * create an ObjectState tree according to it and they can write a
55 * file of a certain format according to a ObjectState
56 * tree. ObjectState enables an easy way to serialize an object model
57 * to different kinds of file formats.
58 */
60public:
61 /// Struct for describing an attribute of the XML element.
62 struct Attribute {
63 std::string name; ///< Name of the attribute.
64 std::string value; ///< Value of the attribute.
65 };
66
67 ObjectState(const std::string& name, ObjectState* parent=NULL);
68 ObjectState(const ObjectState& old);
70
72 std::string name() const;
73 void setName(const std::string& name);
74
75 void setValue(const std::string& value);
76 void setValue(int value);
77 void setValue(double value);
78 void setValue(bool value);
79 void setValue(UIntWord value);
80
81 std::string stringValue() const;
82 int intValue() const;
83 unsigned int unsignedIntValue() const;
84 double doubleValue() const;
85 bool boolValue() const;
86 int UIntWordValue() const;
87
88 void setAttribute(const std::string& name, const std::string& value);
89 void setAttribute(const std::string& name, int value);
90 void setAttribute(const std::string& name, unsigned int value);
91 void setAttribute(const std::string& name, double value);
92 void setAttribute(const std::string& name, bool value);
93 void setAttribute(const std::string& name, ULongWord value);
94
95 int attributeCount() const;
96 Attribute* attribute(int index) const;
97
98 bool hasAttribute(const std::string& name) const;
99 std::string stringAttribute(const std::string& name) const;
100 int intAttribute(const std::string& name) const;
101 unsigned int unsignedIntAttribute(const std::string& name) const;
102 double doubleAttribute(const std::string& name) const;
103 bool boolAttribute(const std::string& name) const;
104 UIntWord UIntWordAttribute(const std::string& name) const;
105 ULongWord uLongAttribute(const std::string& name) const;
106
107 bool hasChild(const std::string& name) const;
110 void replaceChild(ObjectState* old, ObjectState* newChild);
111
112 int childCount() const;
113 ObjectState* childByName(const std::string& name) const;
114 ObjectState* child(int index) const;
115
116 bool operator!=(const ObjectState& object);
117
118 static void dumpObjectState(
119 const ObjectState& state,
120 std::ostream& output,
121 const std::string& identation = "");
122
123private:
124 /// Table of child ObjectState.
125 typedef std::vector<ObjectState*> ChildTable;
126 /// Table of attributes.
127 typedef std::vector<Attribute> AttributeTable;
128
129 /// Assingment forbidden.
131 std::string commonErrorMessage() const;
132
133 /// Name of the element.
134 std::string name_;
135
136 /// The value of a leaf element.
137 std::string value_;
138
139 /// The parent element.
141
142 /// The child elements.
144
145 /// Contains all the attributes of the element.
147};
148
149#include "ObjectState.icc"
150
151#endif
unsigned long ULongWord
Definition BaseType.hh:51
Word UIntWord
Definition BaseType.hh:144
ChildTable children_
The child elements.
UIntWord UIntWordAttribute(const std::string &name) const
unsigned int unsignedIntValue() const
bool hasAttribute(const std::string &name) const
bool operator!=(const ObjectState &object)
std::string name_
Name of the element.
void setValue(UIntWord value)
Attribute * attribute(int index) const
ObjectState * childByName(const std::string &name) const
double doubleAttribute(const std::string &name) const
void setName(const std::string &name)
void setAttribute(const std::string &name, const std::string &value)
void setValue(const std::string &value)
int attributeCount() const
void removeChild(ObjectState *child)
int UIntWordValue() const
bool boolValue() const
bool hasChild(const std::string &name) const
static void dumpObjectState(const ObjectState &state, std::ostream &output, const std::string &identation="")
void setValue(double value)
ObjectState * child(int index) const
void addChild(ObjectState *child)
int intValue() const
std::string stringAttribute(const std::string &name) const
std::string value_
The value of a leaf element.
ObjectState * parent() const
AttributeTable attributes_
Contains all the attributes of the element.
void setValue(int value)
void replaceChild(ObjectState *old, ObjectState *newChild)
bool boolAttribute(const std::string &name) const
std::vector< ObjectState * > ChildTable
Table of child ObjectState.
ObjectState & operator=(const ObjectState &old)
Assingment forbidden.
int intAttribute(const std::string &name) const
std::string stringValue() const
unsigned int unsignedIntAttribute(const std::string &name) const
void setValue(bool value)
ULongWord uLongAttribute(const std::string &name) const
std::string commonErrorMessage() const
double doubleValue() const
ObjectState * parent_
The parent element.
std::string name() const
int childCount() const
std::vector< Attribute > AttributeTable
Table of attributes.
Struct for describing an attribute of the XML element.
std::string value
Value of the attribute.
std::string name
Name of the attribute.