Loading...
Searching...
No Matches
SimpleData.h
Go to the documentation of this file.
1/* Copyright (C) 2008 National Institute For Space Research (INPE) - Brazil.
2
3 This file is part of the TerraLib - a Framework for building GIS enabled applications.
4
5 TerraLib is free software: you can redistribute it and/or modify
6 it under the terms of the GNU Lesser General Public License as published by
7 the Free Software Foundation, either version 3 of the License,
8 or (at your option) any later version.
9
10 TerraLib is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU Lesser General Public License for more details.
14
15 You should have received a copy of the GNU Lesser General Public License
16 along with TerraLib. See COPYING. If not, write to
17 TerraLib Team at <terralib-team@terralib.org>.
18 */
19
20/*!
21 \file terralib/datatype/SimpleData.h
22
23 \brief This file contains several implementations for atomic data types (integers, floats, strings and others).
24*/
25
26#ifndef __TERRALIB_DATATYPE_INTERNAL_SIMPLEDATA_H
27#define __TERRALIB_DATATYPE_INTERNAL_SIMPLEDATA_H
28
29// TerraLib
30#include "AbstractData.h"
31#include "Enums.h"
32
33// STL
34#include <sstream>
35
36// Boost
37#include <boost/cstdint.hpp>
38#include <boost/lexical_cast.hpp>
39
40namespace te
41{
42 namespace dt
43 {
44 /*!
45 \class SimpleData
46
47 \brief A template for atomic data types (integers, floats, strings and others).
48
49 Requirements on type T:
50 <ul>
51 <li> T must be a copy constructible type.</li>
52 <li> T must be used with output streams via operator <<.</li>
53 </ul>
54
55 \ingroup datatype
56
57 \sa AbstractData, CompositeData, DataType, DateTime, ByteArray
58 */
59 template<class T, int typeCode = te::dt::UNKNOWN_TYPE> class SimpleData : public AbstractData
60 {
61 public:
62
63 /*!
64 \brief Constructor.
65
66 \param value The value associated.
67 */
68 SimpleData(T value)
69 : m_val(value)
70 {
71 }
72
73 /*!
74 \brief Copy constructor.
75
76 \param rhs The right-hand-side data.
77 */
79 : m_val(rhs.m_val)
80 {
81 }
82
83 /*! \brief Virtual destructor. */
84 virtual ~SimpleData() { }
85
86 /*!
87 \brief Copy constructor.
88
89 \param rhs The right-hand-side data.
90 */
92 {
93 if(this != &rhs)
94 {
95 m_val = rhs.m_val;
96 }
97
98 return *this;
99 }
100
101 /*!
102 \brief It returns a clone of this object.
103
104 \return A clone of this object.
105 */
107 {
108 return new SimpleData(*this);
109 }
110
111 /*!
112 \brief It returns the data type code associated to the data value.
113
114 \return The data type code associated to the data value.
115 */
116 virtual int getTypeCode() const
117 {
118 return typeCode;
119 }
120
121 /*!
122 \brief It returns the data value in a string representation.
123
124 \return The data value in a string representation.
125 */
126 virtual std::string toString() const
127 {
128 //std::stringstream stream(std::ios_base::in | std::ios_base::out);
129 //stream << m_val;
130 //return stream.str();
131 return boost::lexical_cast<std::string>(m_val);
132 }
133
134 /*!
135 \brief It returns the associated value.
136
137 \return The associated value.
138 */
139 T getValue() const
140 {
141 return m_val;
142 }
143
144 private:
145
146 T m_val; //!< The data value.
147 };
148
149 /*!
150 \class SimpleData<T*, DT>
151
152 \brief Template specialization for simple data using pointers.
153
154 Requirements on type T:
155 <ul>
156 <li> T must be a copy constructible type.</li>
157 <li> T must be used with output streams via operator <<.</li>
158 </ul>
159 */
160 template<class T, int typeCode> class SimpleData<T*, typeCode> : public AbstractData
161 {
162 public:
163
164 SimpleData(T* value)
165 : m_val(value)
166 {
167 }
168
170 {
171 m_val = rhs.m_val ? new T(rhs.m_val) : 0;
172 }
173
174 virtual ~SimpleData()
175 {
176 delete m_val;
177 }
178
180 {
181 if(this != &rhs)
182 {
183 delete m_val;
184 m_val = rhs.m_val ? new T(rhs.m_val) : 0;
185 }
186
187 return *this;
188 }
189
191 {
192 return new SimpleData(*this);
193 }
194
195 virtual int getTypeCode() const
196 {
197 return typeCode;
198 }
199
200 virtual std::string toString() const
201 {
202 std::stringstream stream(std::ios_base::in | std::ios_base::out);
203 stream << *m_val;
204 return stream.str();
205 }
206
207 T* getValue() const
208 {
209 return m_val;
210 }
211
212 private:
213
214 T* m_val; //!< The data value.
215 };
216
230
231 } // end namespace dt
232} // end namespace te
233
234#endif // __TERRALIB_DATATYPE_INTERNAL_SIMPLEDATA_H
235
A base class for objects that can be retrieved from the data access module.
A base class for values that can be retrieved from the data access module.
AbstractData * clone() const
It returns a clone of this object.
Definition SimpleData.h:190
SimpleData(const SimpleData &rhs)
Definition SimpleData.h:169
virtual int getTypeCode() const
It returns the data type code associated to the data value.
Definition SimpleData.h:195
virtual std::string toString() const
It returns the data value in a string notation.
Definition SimpleData.h:200
SimpleData & operator=(const SimpleData &rhs)
Definition SimpleData.h:179
A template for atomic data types (integers, floats, strings and others).
Definition SimpleData.h:60
T m_val
The data value.
Definition SimpleData.h:146
SimpleData & operator=(const SimpleData &rhs)
Copy constructor.
Definition SimpleData.h:91
virtual int getTypeCode() const
It returns the data type code associated to the data value.
Definition SimpleData.h:116
virtual std::string toString() const
It returns the data value in a string representation.
Definition SimpleData.h:126
T getValue() const
It returns the associated value.
Definition SimpleData.h:139
virtual ~SimpleData()
Virtual destructor.
Definition SimpleData.h:84
SimpleData(const SimpleData &rhs)
Copy constructor.
Definition SimpleData.h:78
AbstractData * clone() const
It returns a clone of this object.
Definition SimpleData.h:106
SimpleData(T value)
Constructor.
Definition SimpleData.h:68
SimpleData< boost::int16_t, INT16_TYPE > Int16
Definition SimpleData.h:219
SimpleData< boost::uint16_t, UINT16_TYPE > UInt16
Definition SimpleData.h:220
SimpleData< boost::int32_t, INT32_TYPE > Int32
Definition SimpleData.h:221
SimpleData< bool, BOOLEAN_TYPE > Boolean
Definition SimpleData.h:225
SimpleData< std::string, NUMERIC_TYPE > Numeric
Definition SimpleData.h:228
SimpleData< boost::uint64_t, UINT64_TYPE > UInt64
Definition SimpleData.h:224
SimpleData< boost::uint32_t, UINT32_TYPE > UInt32
Definition SimpleData.h:222
SimpleData< char, CHAR_TYPE > Char
Definition SimpleData.h:217
SimpleData< float, FLOAT_TYPE > Float
Definition SimpleData.h:226
SimpleData< double, DOUBLE_TYPE > Double
Definition SimpleData.h:227
SimpleData< unsigned char, UCHAR_TYPE > UChar
Definition SimpleData.h:218
SimpleData< std::string, STRING_TYPE > String
Definition SimpleData.h:229
SimpleData< boost::int64_t, INT64_TYPE > Int64
Definition SimpleData.h:223
TerraLib.
Enumerations of XML module.