GeoTessCPP  2.0.0
Software to facilitate storage and retrieval of 3D information about the Earth.
 All Classes Namespaces Files Functions Variables Typedefs Friends Defines
include/GeoTessDataValue.h
Go to the documentation of this file.
00001 //- ****************************************************************************
00002 //- 
00003 //- Copyright 2009 Sandia Corporation. Under the terms of Contract
00004 //- DE-AC04-94AL85000 with Sandia Corporation, the U.S. Government
00005 //- retains certain rights in this software.
00006 //- 
00007 //- BSD Open Source License.
00008 //- All rights reserved.
00009 //- 
00010 //- Redistribution and use in source and binary forms, with or without
00011 //- modification, are permitted provided that the following conditions are met:
00012 //- 
00013 //-    * Redistributions of source code must retain the above copyright notice,
00014 //-      this list of conditions and the following disclaimer.
00015 //-    * Redistributions in binary form must reproduce the above copyright
00016 //-      notice, this list of conditions and the following disclaimer in the
00017 //-      documentation and/or other materials provided with the distribution.
00018 //-    * Neither the name of Sandia National Laboratories nor the names of its
00019 //-      contributors may be used to endorse or promote products derived from
00020 //-      this software without specific prior written permission.
00021 //- 
00022 //- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
00023 //- AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00024 //- IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
00025 //- ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
00026 //- LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
00027 //- CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
00028 //- SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
00029 //- INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
00030 //- CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
00031 //- ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
00032 //- POSSIBILITY OF SUCH DAMAGE.
00033 //-
00034 //- ****************************************************************************
00035 
00036 #ifndef DATAVALUE_OBJECT_H
00037 #define DATAVALUE_OBJECT_H
00038 
00039 // **** _SYSTEM INCLUDES_ ******************************************************
00040 
00041 #include <iostream>
00042 #include <fstream>
00043 #include <string>
00044 #include <climits>
00045 
00046 // use standard library objects
00047 using namespace std;
00048 
00049 // **** _LOCAL INCLUDES_ *******************************************************
00050 
00051 #include "GeoTessDataType.h"
00052 #include "GeoTessData.h"
00053 #include "IFStreamAscii.h"
00054 #include "IFStreamBinary.h"
00055 #include "GeoTessUtils.h"
00056 #include "GeoTessDataArray.h"
00057 
00058 // **** _BEGIN GEOTESS NAMESPACE_ *********************************************
00059 
00060 namespace geotess {
00061 
00062 // **** _FORWARD REFERENCES_ ***************************************************
00063 
00064 // **** _CLASS DEFINITION_ *****************************************************
00065 
00073 template<typename T>
00074 class GEOTESS_EXP_IMP GeoTessDataValue : public GeoTessData
00075 {
00076 private:
00077 
00081         T                                                                                               value;
00082 
00083 public:
00084 
00088         GeoTessDataValue(T v) : GeoTessData(), value(v) {};
00089 
00093         GeoTessDataValue() : GeoTessData(), value(0) {};
00094 
00096 
00100         GeoTessDataValue(IFStreamBinary& ifs) : GeoTessData(), value(0)
00101         { ifs.readType(value); };
00102 
00106         GeoTessDataValue(IFStreamAscii& ifs) : GeoTessData(), value(0)
00107         { ifs.readType(value); };
00108 
00112         GeoTessDataValue(IFStreamBinary& ifs, vector<int>& filter) : GeoTessData(), value(0)
00113         {
00114                 T val;
00115                 for (int i=0; i<(int)filter.size(); ++i)
00116                 {
00117                         ifs.readType(val);
00118                         if (filter[i] == 0)
00119                                 value = val;
00120                 }
00121         }
00122 
00126         GeoTessDataValue(IFStreamAscii& ifs, vector<int>& filter) : GeoTessData(), value(0)
00127         {
00128                 T val;
00129                 for (int i=0; i<(int)filter.size(); ++i)
00130                 {
00131                         ifs.readType(val);
00132                         if (filter[i] == 0)
00133                                 value = val;
00134                 }
00135         }
00136 
00140         virtual                                                                 ~GeoTessDataValue() {};
00141 
00145         virtual void                                            write(IFStreamAscii& ofs)
00146         { ofs.writeString(" "); ofs.writeType(value); };
00147 
00151         virtual void                                            write(IFStreamBinary& ofs) { ofs.writeType(value); };
00152 
00154 
00155         /*
00156          * Return DataType.
00157          */
00158         virtual const GeoTessDataType&  getDataType() const { return GeoTessDataType::NONE; };
00159 
00163         virtual int                                                     size() const { return 1; };
00164 
00169         bool operator == (const GeoTessDataValue<T>& d) const
00170         { return (GeoTessData::operator==(d) && ((value == d.value) || (isNaN(0) && d.isNaN(0)))); }
00171 
00176         virtual bool operator == (const GeoTessData& d) const { return operator==(*((const GeoTessDataValue<T>*) &d)); }
00177 
00181         virtual double                                  getDouble(int attributeIndex) const
00182         { return attributeIndex == 0 ? (double) value : NaN_DOUBLE; }
00183 
00184         virtual float                                           getFloat(int attributeIndex) const
00185         { return attributeIndex == 0 ? (float) value : NaN_FLOAT; };
00186 
00187         virtual LONG_INT                                                getLong(int attributeIndex) const
00188         { return attributeIndex == 0 ? (LONG_INT) value : LONG_MIN; };
00189 
00190         virtual int                                                     getInt(int attributeIndex) const
00191         { return attributeIndex == 0 ? (int) value : INT_MIN; };
00192 
00193         virtual short                                           getShort(int attributeIndex) const
00194         { return attributeIndex == 0 ? (short) value : SHRT_MIN; };
00195 
00196         virtual byte                                            getByte(int attributeIndex) const
00197         { return attributeIndex == 0 ? (byte) value : SCHAR_MIN; };
00198 
00199 
00203         virtual void                    getValue(int attributeIndex, double& val) const
00204         { val = attributeIndex == 0 ? (double) value : NaN_DOUBLE; };
00205 
00209         virtual void                    getValue(int attributeIndex, float& val) const
00210         { val = attributeIndex == 0 ? (float) value : NaN_FLOAT; };
00211 
00215         virtual void                    getValue(int attributeIndex, LONG_INT& val) const
00216         { val = attributeIndex == 0 ? (LONG_INT) value : LONG_MIN; };
00217 
00221         virtual void                    getValue(int attributeIndex, int& val) const
00222         { val = attributeIndex == 0 ? (int) value : INT_MIN; };
00223 
00227         virtual void                    getValue(int attributeIndex, short& val) const
00228         { val = attributeIndex == 0 ? (short) value : SHRT_MIN; };
00229 
00233         virtual void                    getValue(int attributeIndex, byte& val) const
00234         { val = attributeIndex == 0 ? (byte) value : SCHAR_MIN; };
00235 
00239         virtual void            getValues(double values[], const int& n) { values[0] = (double) value; }
00240 
00244         virtual void            getValues(float values[], const int& n) { values[0] = (float) value; }
00245 
00249         virtual void            getValues(LONG_INT values[], const int& n) { values[0] = (LONG_INT) value; }
00250 
00254         virtual void            getValues(int values[], const int& n) { values[0] = (int) value; }
00255 
00259         virtual void            getValues(short values[], const int& n) { values[0] = (short) value; }
00260 
00264         virtual void            getValues(byte values[], const int& n) { values[0] = (byte) value; }
00265 
00269         virtual GeoTessData&                                            setValue(int attributeIndex, double v)
00270         { if (attributeIndex == 0) value = (T) v; return *this; };
00271 
00272         virtual GeoTessData&                                            setValue(int attributeIndex, float v)
00273         { if (attributeIndex == 0) value = (T) v; return *this; };
00274 
00275         virtual GeoTessData&                                            setValue(int attributeIndex, LONG_INT v)
00276         { if (attributeIndex == 0) value = (T) v; return *this; };
00277 
00278         virtual GeoTessData&                                            setValue(int attributeIndex, int v)
00279         { if (attributeIndex == 0) value = (T) v; return *this; };
00280 
00281         virtual GeoTessData&                                            setValue(int attributeIndex, short v)
00282         { if (attributeIndex == 0) value = (T) v; return *this; };
00283 
00284         virtual GeoTessData&                                            setValue(int attributeIndex, byte v)
00285         { if (attributeIndex == 0) value = (T) v; return *this; };
00286 
00298         virtual bool            isNaN(int attributeIndex) const {return false;};
00299 
00303         virtual GeoTessData*           copy()
00304         {
00305                 return new GeoTessDataValue<T>(value);
00306         }
00307 
00308 }; // end class DataValue
00309 
00311 
00315 template<>
00316 inline bool     GeoTessDataValue<double>::isNaN(int attributeIndex) const
00317 {
00318         return (isnan(value));
00319 }
00320 
00324 template<>
00325 inline bool     GeoTessDataValue<float>::isNaN(int attributeIndex) const
00326 {
00327         double v = (double) value;
00328         return (isnan(v));
00329 }
00330 
00334 template<>
00335 inline const GeoTessDataType&   GeoTessDataValue<double>::getDataType() const
00336 {
00337         return GeoTessDataType::DOUBLE;
00338 }
00339 
00343 template<>
00344 inline const GeoTessDataType&   GeoTessDataValue<float>::getDataType() const
00345 {
00346         return GeoTessDataType::FLOAT;
00347 }
00348 
00352 template<>
00353 inline const GeoTessDataType&   GeoTessDataValue<LONG_INT>::getDataType() const
00354 {
00355         return GeoTessDataType::LONG;
00356 }
00357 
00361 template<>
00362 inline const GeoTessDataType&   GeoTessDataValue<int>::getDataType() const
00363 {
00364         return GeoTessDataType::INT;
00365 }
00366 
00370 template<>
00371 inline const GeoTessDataType&   GeoTessDataValue<short>::getDataType() const
00372 {
00373         return GeoTessDataType::SHORT;
00374 }
00375 
00379 template<>
00380 inline const GeoTessDataType&   GeoTessDataValue<byte>::getDataType() const
00381 {
00382         return GeoTessDataType::BYTE;
00383 }
00384 
00386 
00387 } // end namespace geotess
00388 
00389 #endif  // DATAVALUE_OBJECT_H