OpenASIP 2.2
Loading...
Searching...
No Matches
DataObject.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 DataObject.hh
26 *
27 * Declaration of DataObject class.
28 *
29 * @author Jussi Nykänen 2004 (nykanen-no.spam-cs.tut.fi)
30 * @author Pekka Jääskeläinen 2006 (pjaaskel-no.spam-cs.tut.fi)
31 */
32
33#ifndef TTA_DATA_OBJECT_HH
34#define TTA_DATA_OBJECT_HH
35
36#include <string>
37
38#include "Exception.hh"
39#include "BaseType.hh"
40/**
41 * Class that represents data in different formats.
42 *
43 * Data can be represented as a string, integer, double, or float. The
44 * idea behind the data object is to cache the conversion results and
45 * to minimize conversions. The DataObject's value can be null, it is
46 * indicated with isNull() returning true. This should not be confused
47 * with NullDataObject, which is just there to indicate a DataObject
48 * reference which is null (a null reference, compares to a null pointer).
49 */
51public:
52
53 /**
54 * Models the type with which DataObject was originally initialized.
55 */
64
65 DataObject();
66 explicit DataObject(int value);
67 explicit DataObject(SLongWord value);
68 explicit DataObject(double value);
69 explicit DataObject(const std::string value);
70 virtual ~DataObject();
71
72 virtual int integerValue() const;
73 virtual void setInteger(int value);
74 virtual void setLong(SLongWord value);
75
76 virtual SLongWord longValue() const;
77
78 virtual std::string stringValue() const;
79 virtual void setString(std::string value);
80
81 virtual double doubleValue() const;
82 virtual void setDouble(double value);
83
84 virtual float floatValue() const;
85 virtual void setFloat(float value);
86
87 virtual bool boolValue() const;
88 virtual void setBool(bool value);
89
90 virtual bool isNull() const;
91 virtual void setNull();
92
93 virtual bool operator!=(const DataObject& object) const;
94
95protected:
96 OrigType type() const;
97 bool intFresh() const;
98 bool stringFresh() const;
99 bool doubleFresh() const;
100 bool floatFresh() const;
101
102private:
103 /// The type of value in which DataObject was last assigned.
105 /// Flag indicating that the value of integer is up-to-date.
106 mutable bool intFresh_;
107 /// Flag indicating that the value of string is up-to-date.
108 mutable bool stringFresh_;
109 /// Flag indicating that the value of double is up-to-date.
110 mutable bool doubleFresh_;
111 /// Flag indicating that the value of float is up-to-date.
112 mutable bool floatFresh_;
113 /// Value as integer.
115 /// Value as string.
116 mutable std::string stringValue_;
117 /// Value as double.
118 mutable double doubleValue_;
119 /// Value as float.
120 mutable float floatValue_;
121};
122
123/**
124 * Singleton class that represents a null DataObject.
125 *
126 * All methods write to error log and abort the program.
127 */
129public:
130 static NullDataObject& instance();
131
132 virtual int integerValue() const override;
133 virtual SLongWord longValue() const override;
134
135 virtual void setInteger(int value) override;
136 virtual void setLong(SLongWord value) override;
137
138 virtual std::string stringValue() const;
139 virtual void setString(std::string value) override;
140
141 virtual double doubleValue() const;
142 virtual void setDouble(double value) override;
143
144 virtual float floatValue() const;
145 virtual void setFloat(float value) override;
146
147 virtual bool isNull() const;
148 virtual void setNull() override;
149private:
150
152 virtual ~NullDataObject();
153
155
157};
158
159#include "DataObject.icc"
160
161#endif
long SLongWord
Definition BaseType.hh:52
bool doubleFresh_
Flag indicating that the value of double is up-to-date.
OrigType type_
The type of value in which DataObject was last assigned.
bool stringFresh() const
double doubleValue_
Value as double.
bool floatFresh() const
virtual void setFloat(float value)
bool doubleFresh() const
virtual void setLong(SLongWord value)
bool intFresh_
Flag indicating that the value of integer is up-to-date.
virtual void setNull()
bool stringFresh_
Flag indicating that the value of string is up-to-date.
virtual void setDouble(double value)
virtual float floatValue() const
virtual std::string stringValue() const
virtual void setBool(bool value)
virtual bool operator!=(const DataObject &object) const
float floatValue_
Value as float.
virtual bool isNull() const
OrigType type() const
SLongWord intValue_
Value as integer.
virtual double doubleValue() const
std::string stringValue_
Value as string.
virtual void setString(std::string value)
virtual bool boolValue() const
virtual int integerValue() const
bool floatFresh_
Flag indicating that the value of float is up-to-date.
bool intFresh() const
virtual void setInteger(int value)
virtual SLongWord longValue() const
virtual ~DataObject()
Definition DataObject.cc:91
virtual void setString(std::string value) override
virtual double doubleValue() const
static NullDataObject * instance_
virtual void setLong(SLongWord value) override
virtual void setNull() override
NullDataObject(const DataObject &obj)
static NullDataObject & instance()
virtual ~NullDataObject()
virtual float floatValue() const
virtual void setInteger(int value) override
virtual bool isNull() const
virtual void setFloat(float value) override
virtual void setDouble(double value) override
virtual std::string stringValue() const
virtual int integerValue() const override
virtual SLongWord longValue() const override