OpenASIP  2.0
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  */
50 class DataObject {
51 public:
52 
53  /**
54  * Models the type with which DataObject was originally initialized.
55  */
56  enum OrigType {
63  };
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 
95 protected:
96  OrigType type() const;
97  bool intFresh() const;
98  bool stringFresh() const;
99  bool doubleFresh() const;
100  bool floatFresh() const;
101 
102 private:
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  */
128 class NullDataObject : public DataObject {
129 public:
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;
149 private:
150 
151  NullDataObject();
152  virtual ~NullDataObject();
153 
154  NullDataObject(const DataObject& obj);
155 
157 };
158 
159 #include "DataObject.icc"
160 
161 #endif
NullDataObject::setString
virtual void setString(std::string value) override
Definition: DataObject.cc:565
DataObject::TYPE_STRING
@ TYPE_STRING
Definition: DataObject.hh:58
NullDataObject::setNull
virtual void setNull() override
Definition: DataObject.cc:580
BaseType.hh
DataObject.icc
Exception.hh
DataObject::setDouble
virtual void setDouble(double value)
Definition: DataObject.cc:145
DataObject::longValue
virtual SLongWord longValue() const
Definition: DataObject.cc:273
DataObject::TYPE_INT
@ TYPE_INT
Definition: DataObject.hh:57
DataObject
Definition: DataObject.hh:50
DataObject::stringValue
virtual std::string stringValue() const
Definition: DataObject.cc:344
DataObject::type_
OrigType type_
The type of value in which DataObject was last assigned.
Definition: DataObject.hh:104
DataObject::TYPE_NOTYPE
@ TYPE_NOTYPE
Definition: DataObject.hh:62
DataObject::~DataObject
virtual ~DataObject()
Definition: DataObject.cc:91
DataObject::setInteger
virtual void setInteger(int value)
Definition: DataObject.cc:115
DataObject::floatValue
virtual float floatValue() const
Definition: DataObject.cc:428
NullDataObject
Definition: DataObject.hh:128
DataObject::OrigType
OrigType
Definition: DataObject.hh:56
DataObject::floatFresh_
bool floatFresh_
Flag indicating that the value of float is up-to-date.
Definition: DataObject.hh:112
NullDataObject::stringValue
virtual std::string stringValue() const
Definition: DataObject.cc:597
NullDataObject::floatValue
virtual float floatValue() const
Definition: DataObject.cc:609
DataObject::intFresh
bool intFresh() const
DataObject::intFresh_
bool intFresh_
Flag indicating that the value of integer is up-to-date.
Definition: DataObject.hh:106
DataObject::stringFresh
bool stringFresh() const
DataObject::floatValue_
float floatValue_
Value as float.
Definition: DataObject.hh:120
DataObject::TYPE_DOUBLE
@ TYPE_DOUBLE
Definition: DataObject.hh:59
DataObject::doubleValue
virtual double doubleValue() const
Definition: DataObject.cc:386
DataObject::integerValue
virtual int integerValue() const
Definition: DataObject.cc:204
DataObject::doubleFresh
bool doubleFresh() const
NullDataObject::setFloat
virtual void setFloat(float value) override
Definition: DataObject.cc:575
DataObject::setLong
virtual void setLong(SLongWord value)
Definition: DataObject.cc:100
DataObject::floatFresh
bool floatFresh() const
DataObject::setFloat
virtual void setFloat(float value)
Definition: DataObject.cc:160
DataObject::intValue_
SLongWord intValue_
Value as integer.
Definition: DataObject.hh:114
DataObject::isNull
virtual bool isNull() const
Definition: DataObject.cc:491
NullDataObject::setLong
virtual void setLong(SLongWord value) override
Definition: DataObject.cc:560
DataObject::type
OrigType type() const
DataObject::stringFresh_
bool stringFresh_
Flag indicating that the value of string is up-to-date.
Definition: DataObject.hh:108
DataObject::TYPE_FLOAT
@ TYPE_FLOAT
Definition: DataObject.hh:60
DataObject::setNull
virtual void setNull()
Definition: DataObject.cc:184
DataObject::doubleFresh_
bool doubleFresh_
Flag indicating that the value of double is up-to-date.
Definition: DataObject.hh:110
DataObject::TYPE_NULL
@ TYPE_NULL
Definition: DataObject.hh:61
NullDataObject::NullDataObject
NullDataObject()
Definition: DataObject.cc:526
DataObject::operator!=
virtual bool operator!=(const DataObject &object) const
Definition: DataObject.cc:503
NullDataObject::setInteger
virtual void setInteger(int value) override
Definition: DataObject.cc:555
NullDataObject::integerValue
virtual int integerValue() const override
Definition: DataObject.cc:585
NullDataObject::longValue
virtual SLongWord longValue() const override
Definition: DataObject.cc:591
DataObject::stringValue_
std::string stringValue_
Value as string.
Definition: DataObject.hh:116
NullDataObject::instance_
static NullDataObject * instance_
Definition: DataObject.hh:156
DataObject::setBool
virtual void setBool(bool value)
Definition: DataObject.cc:175
NullDataObject::doubleValue
virtual double doubleValue() const
Definition: DataObject.cc:603
NullDataObject::~NullDataObject
virtual ~NullDataObject()
Definition: DataObject.cc:532
DataObject::boolValue
virtual bool boolValue() const
Definition: DataObject.cc:470
DataObject::setString
virtual void setString(std::string value)
Definition: DataObject.cc:130
NullDataObject::setDouble
virtual void setDouble(double value) override
Definition: DataObject.cc:570
NullDataObject::isNull
virtual bool isNull() const
Definition: DataObject.cc:615
DataObject::doubleValue_
double doubleValue_
Value as double.
Definition: DataObject.hh:118
SLongWord
long SLongWord
Definition: BaseType.hh:52
NullDataObject::instance
static NullDataObject & instance()
Definition: DataObject.cc:542
DataObject::DataObject
DataObject()
Definition: DataObject.cc:46