GeoTessCPP  2.2.3
Software to facilitate storage and retrieval of 3D information about the Earth.
GeoTessDataValue.h
Go to the documentation of this file.
1 //- ****************************************************************************
2 //-
3 //- Copyright 2009 National Technology & Engineering Solutions of Sandia, LLC
4 //- (NTESS). Under the terms of Contract DE-NA0003525 with NTESS, the U.S.
5 //- Government 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 //- 1. Redistributions of source code must retain the above copyright notice,
14 //- this list of conditions and the following disclaimer.
15 //-
16 //- 2. Redistributions in binary form must reproduce the above copyright
17 //- notice, this list of conditions and the following disclaimer in the
18 //- documentation and/or other materials provided with the distribution.
19 //-
20 //- 3. Neither the name of the copyright holder nor the names of its
21 //- contributors may be used to endorse or promote products derived from
22 //- this software without specific prior written permission.
23 //-
24 //- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
25 //- AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
26 //- IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
27 //- ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
28 //- LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
29 //- CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
30 //- SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
31 //- INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
32 //- CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
33 //- ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
34 //- POSSIBILITY OF SUCH DAMAGE.
35 //-
36 //- ****************************************************************************
37 
38 #ifndef DATAVALUE_OBJECT_H
39 #define DATAVALUE_OBJECT_H
40 
41 // **** _SYSTEM INCLUDES_ ******************************************************
42 
43 #include <iostream>
44 #include <fstream>
45 #include <string>
46 #include <climits>
47 
48 // use standard library objects
49 using namespace std;
50 
51 // **** _LOCAL INCLUDES_ *******************************************************
52 
53 #include "GeoTessDataType.h"
54 #include "GeoTessData.h"
55 #include "IFStreamAscii.h"
56 #include "IFStreamBinary.h"
57 #include "GeoTessUtils.h"
58 #include "GeoTessDataArray.h"
59 
60 // **** _BEGIN GEOTESS NAMESPACE_ *********************************************
61 
62 namespace geotess {
63 
64 // **** _FORWARD REFERENCES_ ***************************************************
65 
66 // **** _CLASS DEFINITION_ *****************************************************
67 
75 template<typename T>
76 class GEOTESS_EXP_IMP GeoTessDataValue : public GeoTessData
77 {
78 private:
79 
83  T value;
84 
85 public:
86 
90  GeoTessDataValue(T v) : GeoTessData(), value(v) {};
91 
95  GeoTessDataValue() : GeoTessData(), value(0) {};
96 
98 
102  GeoTessDataValue(IFStreamBinary& ifs) : GeoTessData(), value(0)
103  { ifs.readType(value); };
104 
108  GeoTessDataValue(IFStreamAscii& ifs) : GeoTessData(), value(0)
109  { ifs.readType(value); };
110 
114  GeoTessDataValue(IFStreamBinary& ifs, vector<int>& filter) : GeoTessData(), value(0)
115  {
116  T val;
117  for (int i=0; i<(int)filter.size(); ++i)
118  {
119  ifs.readType(val);
120  if (filter[i] == 0)
121  value = val;
122  }
123  }
124 
128  GeoTessDataValue(IFStreamAscii& ifs, vector<int>& filter) : GeoTessData(), value(0)
129  {
130  T val;
131  for (int i=0; i<(int)filter.size(); ++i)
132  {
133  ifs.readType(val);
134  if (filter[i] == 0)
135  value = val;
136  }
137  }
138 
142  virtual ~GeoTessDataValue() {};
143 
144  virtual LONG_INT getMemory() { return (LONG_INT)sizeof(GeoTessDataValue<T>); }
145 
149  virtual void write(IFStreamAscii& ofs)
150  { ofs.writeString(" "); ofs.writeType(value); };
151 
155  virtual void write(IFStreamBinary& ofs) { ofs.writeType(value); };
156 
158 
159  /*
160  * Return DataType.
161  */
162  virtual const GeoTessDataType& getDataType() const { return GeoTessDataType::NONE; };
163 
167  virtual int size() const { return 1; };
168 
173  bool operator == (const GeoTessDataValue<T>& d) const
174  { return (GeoTessData::operator==(d) && ((value == d.value) || (isNaN(0) && d.isNaN(0)))); }
175 
180  virtual bool operator == (const GeoTessData& d) const { return operator==(*((const GeoTessDataValue<T>*) &d)); }
181 
185  virtual double getDouble(int attributeIndex) const
186  { return attributeIndex == 0 ? (double) value : NaN_DOUBLE; }
187 
188  virtual float getFloat(int attributeIndex) const
189  { return attributeIndex == 0 ? (float) value : NaN_FLOAT; };
190 
191  virtual LONG_INT getLong(int attributeIndex) const
192  { return attributeIndex == 0 ? (LONG_INT) value : LONG_MIN; };
193 
194  virtual int getInt(int attributeIndex) const
195  { return attributeIndex == 0 ? (int) value : INT_MIN; };
196 
197  virtual short getShort(int attributeIndex) const
198  { return attributeIndex == 0 ? (short) value : SHRT_MIN; };
199 
200  virtual byte getByte(int attributeIndex) const
201  { return attributeIndex == 0 ? (byte) value : SCHAR_MIN; };
202 
203 
207  virtual void getValue(int attributeIndex, double& val) const
208  { val = attributeIndex == 0 ? (double) value : NaN_DOUBLE; };
209 
213  virtual void getValue(int attributeIndex, float& val) const
214  { val = attributeIndex == 0 ? (float) value : NaN_FLOAT; };
215 
219  virtual void getValue(int attributeIndex, LONG_INT& val) const
220  { val = attributeIndex == 0 ? (LONG_INT) value : LONG_MIN; };
221 
225  virtual void getValue(int attributeIndex, int& val) const
226  { val = attributeIndex == 0 ? (int) value : INT_MIN; };
227 
231  virtual void getValue(int attributeIndex, short& val) const
232  { val = attributeIndex == 0 ? (short) value : SHRT_MIN; };
233 
237  virtual void getValue(int attributeIndex, byte& val) const
238  { val = attributeIndex == 0 ? (byte) value : SCHAR_MIN; };
239 
243  virtual void getValues(double values[], const int& n) { values[0] = (double) value; }
244 
248  virtual void getValues(float values[], const int& n) { values[0] = (float) value; }
249 
253  virtual void getValues(LONG_INT values[], const int& n) { values[0] = (LONG_INT) value; }
254 
258  virtual void getValues(int values[], const int& n) { values[0] = (int) value; }
259 
263  virtual void getValues(short values[], const int& n) { values[0] = (short) value; }
264 
268  virtual void getValues(byte values[], const int& n) { values[0] = (byte) value; }
269 
273  virtual GeoTessData& setValue(int attributeIndex, double v)
274  { if (attributeIndex == 0) value = (T) v; return *this; };
275 
276  virtual GeoTessData& setValue(int attributeIndex, float v)
277  { if (attributeIndex == 0) value = (T) v; return *this; };
278 
279  virtual GeoTessData& setValue(int attributeIndex, LONG_INT v)
280  { if (attributeIndex == 0) value = (T) v; return *this; };
281 
282  virtual GeoTessData& setValue(int attributeIndex, int v)
283  { if (attributeIndex == 0) value = (T) v; return *this; };
284 
285  virtual GeoTessData& setValue(int attributeIndex, short v)
286  { if (attributeIndex == 0) value = (T) v; return *this; };
287 
288  virtual GeoTessData& setValue(int attributeIndex, byte v)
289  { if (attributeIndex == 0) value = (T) v; return *this; };
290 
302  virtual bool isNaN(int attributeIndex) const {return false;};
303 
307  virtual GeoTessData* copy()
308  {
309  return new GeoTessDataValue<T>(value);
310  }
311 
312 }; // end class DataValue
313 
315 
319 template<>
320 inline bool GeoTessDataValue<double>::isNaN(int attributeIndex) const
321 {
322  return (isnan(value));
323 }
324 
328 template<>
329 inline bool GeoTessDataValue<float>::isNaN(int attributeIndex) const
330 {
331  double v = (double) value;
332  return (isnan(v));
333 }
334 
338 template<>
339 inline const GeoTessDataType& GeoTessDataValue<double>::getDataType() const
340 {
341  return GeoTessDataType::DOUBLE;
342 }
343 
347 template<>
348 inline const GeoTessDataType& GeoTessDataValue<float>::getDataType() const
349 {
350  return GeoTessDataType::FLOAT;
351 }
352 
356 template<>
357 inline const GeoTessDataType& GeoTessDataValue<LONG_INT>::getDataType() const
358 {
359  return GeoTessDataType::LONG;
360 }
361 
365 template<>
366 inline const GeoTessDataType& GeoTessDataValue<int>::getDataType() const
367 {
368  return GeoTessDataType::INT;
369 }
370 
374 template<>
375 inline const GeoTessDataType& GeoTessDataValue<short>::getDataType() const
376 {
377  return GeoTessDataType::SHORT;
378 }
379 
383 template<>
384 inline const GeoTessDataType& GeoTessDataValue<byte>::getDataType() const
385 {
386  return GeoTessDataType::BYTE;
387 }
388 
390 
391 } // end namespace geotess
392 
393 #endif // DATAVALUE_OBJECT_H
geotess::GeoTessDataValue::getValue
virtual void getValue(int attributeIndex, LONG_INT &val) const
Definition: GeoTessDataValue.h:219
geotess
Definition: ArrayReuse.h:57
geotess::GeoTessDataValue::setValue
virtual GeoTessData & setValue(int attributeIndex, LONG_INT v)
Definition: GeoTessDataValue.h:279
IFStreamBinary.h
GeoTessData.h
geotess::GeoTessDataValue::getValues
virtual void getValues(double values[], const int &n)
Definition: GeoTessDataValue.h:243
geotess::GeoTessDataValue::getDouble
virtual double getDouble(int attributeIndex) const
Definition: GeoTessDataValue.h:185
geotess::GeoTessDataValue::getValues
virtual void getValues(LONG_INT values[], const int &n)
Definition: GeoTessDataValue.h:253
geotess::GeoTessDataValue
Manages a single data value attached to a grid node.
Definition: GeoTessData.h:65
geotess::GeoTessDataValue::getValue
virtual void getValue(int attributeIndex, int &val) const
Definition: GeoTessDataValue.h:225
geotess::GeoTessDataValue::getValue
virtual void getValue(int attributeIndex, double &val) const
Definition: GeoTessDataValue.h:207
geotess::GeoTessDataValue::getValues
virtual void getValues(float values[], const int &n)
Definition: GeoTessDataValue.h:248
geotess::GeoTessDataValue::copy
virtual GeoTessData * copy()
Definition: GeoTessDataValue.h:307
geotess::GeoTessDataValue::getDataType
virtual const GeoTessDataType & getDataType() const
Definition: GeoTessDataValue.h:162
GeoTessDataArray.h
geotess::GeoTessDataValue::getByte
virtual byte getByte(int attributeIndex) const
Definition: GeoTessDataValue.h:200
geotess::GeoTessDataValue::setValue
virtual GeoTessData & setValue(int attributeIndex, float v)
Definition: GeoTessDataValue.h:276
geotess::IFStreamBinary::readType
void readType(string &s)
Definition: IFStreamBinary.h:802
GeoTessUtils.h
geotess::GeoTessDataValue::setValue
virtual GeoTessData & setValue(int attributeIndex, int v)
Definition: GeoTessDataValue.h:282
geotess::GeoTessDataValue::getShort
virtual short getShort(int attributeIndex) const
Definition: GeoTessDataValue.h:197
geotess::GeoTessDataType
Enumeration of supported DataType including DOUBLE, FLOAT, LONG, INT, SHORT and BYTE.
Definition: GeoTessDataType.h:70
geotess::GeoTessDataValue::getValues
virtual void getValues(short values[], const int &n)
Definition: GeoTessDataValue.h:263
LONG_INT
#define LONG_INT
Definition: CPPGlobals.h:113
geotess::GeoTessDataValue::getInt
virtual int getInt(int attributeIndex) const
Definition: GeoTessDataValue.h:194
geotess::GeoTessData
Abstract base class that manages the data values attached to a single grid point.
Definition: GeoTessData.h:78
geotess::GeoTessDataValue::setValue
virtual GeoTessData & setValue(int attributeIndex, byte v)
Definition: GeoTessDataValue.h:288
GEOTESS_EXP_IMP
#define GEOTESS_EXP_IMP
Definition: CPPGlobals.h:73
geotess::GeoTessDataValue::GeoTessDataValue
GeoTessDataValue()
Definition: GeoTessDataValue.h:95
IFStreamAscii.h
geotess::GeoTessDataValue::getLong
virtual LONG_INT getLong(int attributeIndex) const
Definition: GeoTessDataValue.h:191
geotess::GeoTessDataValue::setValue
virtual GeoTessData & setValue(int attributeIndex, double v)
Definition: GeoTessDataValue.h:273
geotess::GeoTessDataValue::getFloat
virtual float getFloat(int attributeIndex) const
Definition: GeoTessDataValue.h:188
byte
#define byte
signed-byte typedef
Definition: CPPGlobals.h:96
geotess::IFStreamBinary
Opens a file for binary read and write access.
Definition: IFStreamBinary.h:82
geotess::GeoTessDataValue::size
virtual int size() const
Definition: GeoTessDataValue.h:167
geotess::GeoTessDataValue::getValues
virtual void getValues(byte values[], const int &n)
Definition: GeoTessDataValue.h:268
geotess::GeoTessDataValue::operator==
virtual bool operator==(const GeoTessData &d) const
Definition: GeoTessDataValue.h:180
geotess::GeoTessDataValue::isNaN
virtual bool isNaN(int attributeIndex) const
Definition: GeoTessDataValue.h:302
GeoTessDataType.h
geotess::GeoTessDataValue::getValue
virtual void getValue(int attributeIndex, float &val) const
Definition: GeoTessDataValue.h:213
geotess::GeoTessDataValue::getValue
virtual void getValue(int attributeIndex, byte &val) const
Definition: GeoTessDataValue.h:237
geotess::GeoTessDataValue::setValue
virtual GeoTessData & setValue(int attributeIndex, short v)
Definition: GeoTessDataValue.h:285
geotess::GeoTessDataValue::getValues
virtual void getValues(int values[], const int &n)
Definition: GeoTessDataValue.h:258
geotess::GeoTessDataValue::getValue
virtual void getValue(int attributeIndex, short &val) const
Definition: GeoTessDataValue.h:231
geotess::GeoTessDataValue::GeoTessDataValue
GeoTessDataValue(T v)
Definition: GeoTessDataValue.h:90