GeoTessCPP: include/GeoTessDataValue.h Source File

GeoTessCPP 2.1 Software to facilitate storage and retrieval of 3D information about the Earth.

- Main Page
- Namespaces
- Classes
- Files

- File List
- File Members

All Classes Namespaces Files Functions Variables Typedefs Friends Macros
GeoTessDataValue.h
Go to the documentation of this file.
1 //- ****************************************************************************
2 //-
3 //- Copyright 2009 Sandia Corporation. Under the terms of Contract
4 //- DE-AC04-94AL85000 with Sandia Corporation, the U.S. Government
5 //- retains certain rights in this software.
6 //-
7 //- BSD Open Source License.
8 //- All rights reserved.
9 //-
10 //- Redistribution and use in source and binary forms, with or without
11 //- modification, are permitted provided that the following conditions are met:
12 //-
13 //- * Redistributions of source code must retain the above copyright notice,
14 //- this list of conditions and the following disclaimer.
15 //- * Redistributions in binary form must reproduce the above copyright
16 //- notice, this list of conditions and the following disclaimer in the
17 //- documentation and/or other materials provided with the distribution.
18 //- * Neither the name of Sandia National Laboratories nor the names of its
19 //- contributors may be used to endorse or promote products derived from
20 //- this software without specific prior written permission.
21 //-
22 //- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
23 //- AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24 //- IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
25 //- ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
26 //- LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
27 //- CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
28 //- SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
29 //- INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
30 //- CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
31 //- ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
32 //- POSSIBILITY OF SUCH DAMAGE.
33 //-
34 //- ****************************************************************************
35
36 #ifndef DATAVALUE_OBJECT_H
37 #define DATAVALUE_OBJECT_H
38
39 // **** _SYSTEM INCLUDES_ ******************************************************
40
41 #include <iostream>
42 #include <fstream>
43 #include <string>
44 #include <climits>
45
46 // use standard library objects
47 using namespace std;
48
49 // **** _LOCAL INCLUDES_ *******************************************************
50
51 #include "GeoTessDataType.h"
52 #include "GeoTessData.h"
53 #include "IFStreamAscii.h"
54 #include "IFStreamBinary.h"
55 #include "GeoTessUtils.h"
56 #include "GeoTessDataArray.h"
57
58 // **** _BEGIN GEOTESS NAMESPACE_ *********************************************
59
60 namespace geotess {
61
62 // **** _FORWARD REFERENCES_ ***************************************************
63
64 // **** _CLASS DEFINITION_ *****************************************************
65
73 template<typename T>
74 class GEOTESS_EXP_IMP GeoTessDataValue : public GeoTessData
75 {
76 private:
77
81 T value;
82
83 public:
84
88 GeoTessDataValue(T v) : GeoTessData(), value(v) {};
89
93 GeoTessDataValue() : GeoTessData(), value(0) {};
94
96
100 GeoTessDataValue(IFStreamBinary& ifs) : GeoTessData(), value(0)
101 { ifs.readType(value); };
102
106 GeoTessDataValue(IFStreamAscii& ifs) : GeoTessData(), value(0)
107 { ifs.readType(value); };
108
112 GeoTessDataValue(IFStreamBinary& ifs, vector<int>& filter) : GeoTessData(), value(0)
113 {
114 T val;
115 for (int i=0; i<(int)filter.size(); ++i)
116 {
117 ifs.readType(val);
118 if (filter[i] == 0)
119 value = val;
120 }
121 }
122
126 GeoTessDataValue(IFStreamAscii& ifs, vector<int>& filter) : GeoTessData(), value(0)
127 {
128 T val;
129 for (int i=0; i<(int)filter.size(); ++i)
130 {
131 ifs.readType(val);
132 if (filter[i] == 0)
133 value = val;
134 }
135 }
136
140 virtual ~GeoTessDataValue() {};
141
142 virtual LONG_INT getMemory() { return (LONG_INT)sizeof(GeoTessDataValue<T>); }
143
147 virtual void write(IFStreamAscii& ofs)
148 { ofs.writeString(" "); ofs.writeType(value); };
149
153 virtual void write(IFStreamBinary& ofs) { ofs.writeType(value); };
154
156
157 /*
158 * Return DataType.
159 */
160 virtual const GeoTessDataType& getDataType() const { return GeoTessDataType::NONE; };
161
165 virtual int size() const { return 1; };
166
171 bool operator == (const GeoTessDataValue<T>& d) const
172 { return (GeoTessData::operator==(d) && ((value == d.value) || (isNaN(0) && d.isNaN(0)))); }
173
178 virtual bool operator == (const GeoTessData& d) const { return operator==(*((const GeoTessDataValue<T>*) &d)); }
179
183 virtual double getDouble(int attributeIndex) const
184 { return attributeIndex == 0 ? (double) value : NaN_DOUBLE; }
185
186 virtual float getFloat(int attributeIndex) const
187 { return attributeIndex == 0 ? (float) value : NaN_FLOAT; };
188
189 virtual LONG_INT getLong(int attributeIndex) const
190 { return attributeIndex == 0 ? (LONG_INT) value : LONG_MIN; };
191
192 virtual int getInt(int attributeIndex) const
193 { return attributeIndex == 0 ? (int) value : INT_MIN; };
194
195 virtual short getShort(int attributeIndex) const
196 { return attributeIndex == 0 ? (short) value : SHRT_MIN; };
197
198 virtual byte getByte(int attributeIndex) const
199 { return attributeIndex == 0 ? (byte) value : SCHAR_MIN; };
200
201
205 virtual void getValue(int attributeIndex, double& val) const
206 { val = attributeIndex == 0 ? (double) value : NaN_DOUBLE; };
207
211 virtual void getValue(int attributeIndex, float& val) const
212 { val = attributeIndex == 0 ? (float) value : NaN_FLOAT; };
213
217 virtual void getValue(int attributeIndex, LONG_INT& val) const
218 { val = attributeIndex == 0 ? (LONG_INT) value : LONG_MIN; };
219
223 virtual void getValue(int attributeIndex, int& val) const
224 { val = attributeIndex == 0 ? (int) value : INT_MIN; };
225
229 virtual void getValue(int attributeIndex, short& val) const
230 { val = attributeIndex == 0 ? (short) value : SHRT_MIN; };
231
235 virtual void getValue(int attributeIndex, byte& val) const
236 { val = attributeIndex == 0 ? (byte) value : SCHAR_MIN; };
237
241 virtual void getValues(double values[], const int& n) { values[0] = (double) value; }
242
246 virtual void getValues(float values[], const int& n) { values[0] = (float) value; }
247
251 virtual void getValues(LONG_INT values[], const int& n) { values[0] = (LONG_INT) value; }
252
256 virtual void getValues(int values[], const int& n) { values[0] = (int) value; }
257
261 virtual void getValues(short values[], const int& n) { values[0] = (short) value; }
262
266 virtual void getValues(byte values[], const int& n) { values[0] = (byte) value; }
267
271 virtual GeoTessData& setValue(int attributeIndex, double v)
272 { if (attributeIndex == 0) value = (T) v; return *this; };
273
274 virtual GeoTessData& setValue(int attributeIndex, float v)
275 { if (attributeIndex == 0) value = (T) v; return *this; };
276
277 virtual GeoTessData& setValue(int attributeIndex, LONG_INT v)
278 { if (attributeIndex == 0) value = (T) v; return *this; };
279
280 virtual GeoTessData& setValue(int attributeIndex, int v)
281 { if (attributeIndex == 0) value = (T) v; return *this; };
282
283 virtual GeoTessData& setValue(int attributeIndex, short v)
284 { if (attributeIndex == 0) value = (T) v; return *this; };
285
286 virtual GeoTessData& setValue(int attributeIndex, byte v)
287 { if (attributeIndex == 0) value = (T) v; return *this; };
288
300 virtual bool isNaN(int attributeIndex) const {return false;};
301
305 virtual GeoTessData* copy()
306 {
307 return new GeoTessDataValue<T>(value);
308 }
309
310 }; // end class DataValue
311
313
317 template<>
318 inline bool GeoTessDataValue<double>::isNaN(int attributeIndex) const
319 {
320 return (isnan(value));
321 }
322
326 template<>
327 inline bool GeoTessDataValue<float>::isNaN(int attributeIndex) const
328 {
329 double v = (double) value;
330 return (isnan(v));
331 }
332
336 template<>
337 inline const GeoTessDataType& GeoTessDataValue<double>::getDataType() const
338 {
339 return GeoTessDataType::DOUBLE;
340 }
341
345 template<>
346 inline const GeoTessDataType& GeoTessDataValue<float>::getDataType() const
347 {
348 return GeoTessDataType::FLOAT;
349 }
350
354 template<>
355 inline const GeoTessDataType& GeoTessDataValue<LONG_INT>::getDataType() const
356 {
357 return GeoTessDataType::LONG;
358 }
359
363 template<>
364 inline const GeoTessDataType& GeoTessDataValue<int>::getDataType() const
365 {
366 return GeoTessDataType::INT;
367 }
368
372 template<>
373 inline const GeoTessDataType& GeoTessDataValue<short>::getDataType() const
374 {
375 return GeoTessDataType::SHORT;
376 }
377
381 template<>
382 inline const GeoTessDataType& GeoTessDataValue<byte>::getDataType() const
383 {
384 return GeoTessDataType::BYTE;
385 }
386
388
389 } // end namespace geotess
390
391 #endif // DATAVALUE_OBJECT_H