GeoTessCPP  2.1
Software to facilitate storage and retrieval of 3D information about the Earth.
 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 
145  virtual void write(IFStreamAscii& ofs)
146  { ofs.writeString(" "); ofs.writeType(value); };
147 
151  virtual void write(IFStreamBinary& ofs) { ofs.writeType(value); };
152 
154 
155  /*
156  * Return DataType.
157  */
158  virtual const GeoTessDataType& getDataType() const { return GeoTessDataType::NONE; };
159 
163  virtual int size() const { return 1; };
164 
169  bool operator == (const GeoTessDataValue<T>& d) const
170  { return (GeoTessData::operator==(d) && ((value == d.value) || (isNaN(0) && d.isNaN(0)))); }
171 
176  virtual bool operator == (const GeoTessData& d) const { return operator==(*((const GeoTessDataValue<T>*) &d)); }
177 
181  virtual double getDouble(int attributeIndex) const
182  { return attributeIndex == 0 ? (double) value : NaN_DOUBLE; }
183 
184  virtual float getFloat(int attributeIndex) const
185  { return attributeIndex == 0 ? (float) value : NaN_FLOAT; };
186 
187  virtual LONG_INT getLong(int attributeIndex) const
188  { return attributeIndex == 0 ? (LONG_INT) value : LONG_MIN; };
189 
190  virtual int getInt(int attributeIndex) const
191  { return attributeIndex == 0 ? (int) value : INT_MIN; };
192 
193  virtual short getShort(int attributeIndex) const
194  { return attributeIndex == 0 ? (short) value : SHRT_MIN; };
195 
196  virtual byte getByte(int attributeIndex) const
197  { return attributeIndex == 0 ? (byte) value : SCHAR_MIN; };
198 
199 
203  virtual void getValue(int attributeIndex, double& val) const
204  { val = attributeIndex == 0 ? (double) value : NaN_DOUBLE; };
205 
209  virtual void getValue(int attributeIndex, float& val) const
210  { val = attributeIndex == 0 ? (float) value : NaN_FLOAT; };
211 
215  virtual void getValue(int attributeIndex, LONG_INT& val) const
216  { val = attributeIndex == 0 ? (LONG_INT) value : LONG_MIN; };
217 
221  virtual void getValue(int attributeIndex, int& val) const
222  { val = attributeIndex == 0 ? (int) value : INT_MIN; };
223 
227  virtual void getValue(int attributeIndex, short& val) const
228  { val = attributeIndex == 0 ? (short) value : SHRT_MIN; };
229 
233  virtual void getValue(int attributeIndex, byte& val) const
234  { val = attributeIndex == 0 ? (byte) value : SCHAR_MIN; };
235 
239  virtual void getValues(double values[], const int& n) { values[0] = (double) value; }
240 
244  virtual void getValues(float values[], const int& n) { values[0] = (float) value; }
245 
249  virtual void getValues(LONG_INT values[], const int& n) { values[0] = (LONG_INT) value; }
250 
254  virtual void getValues(int values[], const int& n) { values[0] = (int) value; }
255 
259  virtual void getValues(short values[], const int& n) { values[0] = (short) value; }
260 
264  virtual void getValues(byte values[], const int& n) { values[0] = (byte) value; }
265 
269  virtual GeoTessData& setValue(int attributeIndex, double v)
270  { if (attributeIndex == 0) value = (T) v; return *this; };
271 
272  virtual GeoTessData& setValue(int attributeIndex, float v)
273  { if (attributeIndex == 0) value = (T) v; return *this; };
274 
275  virtual GeoTessData& setValue(int attributeIndex, LONG_INT v)
276  { if (attributeIndex == 0) value = (T) v; return *this; };
277 
278  virtual GeoTessData& setValue(int attributeIndex, int v)
279  { if (attributeIndex == 0) value = (T) v; return *this; };
280 
281  virtual GeoTessData& setValue(int attributeIndex, short v)
282  { if (attributeIndex == 0) value = (T) v; return *this; };
283 
284  virtual GeoTessData& setValue(int attributeIndex, byte v)
285  { if (attributeIndex == 0) value = (T) v; return *this; };
286 
298  virtual bool isNaN(int attributeIndex) const {return false;};
299 
303  virtual GeoTessData* copy()
304  {
305  return new GeoTessDataValue<T>(value);
306  }
307 
308 }; // end class DataValue
309 
311 
315 template<>
316 inline bool GeoTessDataValue<double>::isNaN(int attributeIndex) const
317 {
318  return (isnan(value));
319 }
320 
324 template<>
325 inline bool GeoTessDataValue<float>::isNaN(int attributeIndex) const
326 {
327  double v = (double) value;
328  return (isnan(v));
329 }
330 
334 template<>
335 inline const GeoTessDataType& GeoTessDataValue<double>::getDataType() const
336 {
337  return GeoTessDataType::DOUBLE;
338 }
339 
343 template<>
344 inline const GeoTessDataType& GeoTessDataValue<float>::getDataType() const
345 {
346  return GeoTessDataType::FLOAT;
347 }
348 
352 template<>
353 inline const GeoTessDataType& GeoTessDataValue<LONG_INT>::getDataType() const
354 {
355  return GeoTessDataType::LONG;
356 }
357 
361 template<>
362 inline const GeoTessDataType& GeoTessDataValue<int>::getDataType() const
363 {
364  return GeoTessDataType::INT;
365 }
366 
370 template<>
371 inline const GeoTessDataType& GeoTessDataValue<short>::getDataType() const
372 {
373  return GeoTessDataType::SHORT;
374 }
375 
379 template<>
380 inline const GeoTessDataType& GeoTessDataValue<byte>::getDataType() const
381 {
382  return GeoTessDataType::BYTE;
383 }
384 
386 
387 } // end namespace geotess
388 
389 #endif // DATAVALUE_OBJECT_H
virtual bool operator==(const GeoTessData &d) const
Definition: GeoTessDataValue.h:176
virtual void getValues(LONG_INT values[], const int &n)
Definition: GeoTessDataValue.h:249
virtual byte getByte(int attributeIndex) const
Definition: GeoTessDataValue.h:196
virtual LONG_INT getLong(int attributeIndex) const
Definition: GeoTessDataValue.h:187
virtual void getValue(int attributeIndex, float &val) const
Definition: GeoTessDataValue.h:209
virtual void getValue(int attributeIndex, LONG_INT &val) const
Definition: GeoTessDataValue.h:215
Opens a file for binary read and write access.
Definition: IFStreamBinary.h:79
virtual void getValues(short values[], const int &n)
Definition: GeoTessDataValue.h:259
virtual GeoTessData & setValue(int attributeIndex, double v)
Definition: GeoTessDataValue.h:269
virtual void getValue(int attributeIndex, double &val) const
Definition: GeoTessDataValue.h:203
virtual GeoTessData & setValue(int attributeIndex, int v)
Definition: GeoTessDataValue.h:278
void readType(string &s)
Definition: IFStreamBinary.h:764
Enumeration of supported DataType including DOUBLE, FLOAT, LONG, INT, SHORT and BYTE.
Definition: GeoTessDataType.h:67
virtual short getShort(int attributeIndex) const
Definition: GeoTessDataValue.h:193
Manages a single data value attached to a grid node.
Definition: GeoTessData.h:63
virtual GeoTessData & setValue(int attributeIndex, float v)
Definition: GeoTessDataValue.h:272
virtual void getValue(int attributeIndex, byte &val) const
Definition: GeoTessDataValue.h:233
virtual void getValue(int attributeIndex, short &val) const
Definition: GeoTessDataValue.h:227
virtual void getValues(byte values[], const int &n)
Definition: GeoTessDataValue.h:264
virtual const GeoTessDataType & getDataType() const
Definition: GeoTessDataValue.h:158
#define byte
signed-byte typedef
Definition: CPPGlobals.h:94
virtual GeoTessData & setValue(int attributeIndex, LONG_INT v)
Definition: GeoTessDataValue.h:275
virtual void getValue(int attributeIndex, int &val) const
Definition: GeoTessDataValue.h:221
virtual int size() const
Definition: GeoTessDataValue.h:163
GeoTessDataValue(T v)
Definition: GeoTessDataValue.h:88
#define LONG_INT
Definition: CPPGlobals.h:111
Abstract base class that manages the data values attached to a single grid point. ...
Definition: GeoTessData.h:75
virtual void getValues(int values[], const int &n)
Definition: GeoTessDataValue.h:254
virtual double getDouble(int attributeIndex) const
Definition: GeoTessDataValue.h:181
virtual GeoTessData & setValue(int attributeIndex, short v)
Definition: GeoTessDataValue.h:281
GeoTessDataValue()
Definition: GeoTessDataValue.h:93
virtual void getValues(double values[], const int &n)
Definition: GeoTessDataValue.h:239
#define GEOTESS_EXP_IMP
Definition: CPPGlobals.h:71
virtual int getInt(int attributeIndex) const
Definition: GeoTessDataValue.h:190
virtual bool isNaN(int attributeIndex) const
Definition: GeoTessDataValue.h:298
virtual GeoTessData * copy()
Definition: GeoTessDataValue.h:303
virtual void getValues(float values[], const int &n)
Definition: GeoTessDataValue.h:244
virtual GeoTessData & setValue(int attributeIndex, byte v)
Definition: GeoTessDataValue.h:284
virtual float getFloat(int attributeIndex) const
Definition: GeoTessDataValue.h:184