OSSIM - Open Source Software Image Map  Version 1.9.0 (20180803)
ossimNumericProperty.cpp
Go to the documentation of this file.
1 //*******************************************************************
2 //
3 // License: See top level LICENSE.txt file.
4 //
5 // Author: Garrett Potts (gpotts@imagelinks.com)
6 //
7 //*************************************************************************
8 // $Id: ossimNumericProperty.cpp 9963 2006-11-28 21:11:01Z gpotts $
9 #include <algorithm>
11 
12 
13 RTTI_DEF1(ossimNumericProperty, "ossimNumericProperty", ossimProperty);
14 
16  const ossimString& value)
17  :ossimProperty(name),
18  theValue(value),
19  theType(ossimNumericPropertyType_FLOAT64)
20 {
21 }
22 
24  const ossimString& value,
25  double minValue,
26  double maxValue)
27  :ossimProperty(name),
28  theValue(value),
29  theType(ossimNumericPropertyType_FLOAT64)
30 {
31  setConstraints(minValue,
32  maxValue);
33 }
34 
36  :ossimProperty(rhs),
37  theValue(rhs.theValue),
38  theType(rhs.theType),
39  theRangeConstraint(rhs.theRangeConstraint)
40 {
41 }
42 
44 {
45  return new ossimNumericProperty(*this);
46 }
47 
49 {
51 
52  const ossimNumericProperty* numericProperty = dynamic_cast<const ossimNumericProperty*>(&rhs);
53  if(numericProperty)
54  {
55  theValue = numericProperty->theValue;
56  theType = numericProperty->theType;
57  theRangeConstraint = numericProperty->theRangeConstraint;
58  }
59  else
60  {
61  ossimString value;
62  rhs.valueToString(value);
63  setValue(value);
64  }
65  return *this;
66 }
67 
69 {
70  return (theRangeConstraint.size() == 2);
71 }
72 
74 {
75  if(hasConstraints())
76  {
77  return theRangeConstraint[0];
78  }
79 
80  return 0.0;
81 }
82 
84 {
85  if(hasConstraints())
86  {
87  return theRangeConstraint[1];
88  }
89 
90  return 0.0;
91 }
92 
94 {
95  theRangeConstraint.clear();
96 }
97 
99  double maxValue)
100 {
101  theRangeConstraint.resize(2);
102  theRangeConstraint[0] = minValue;
103  theRangeConstraint[1] = maxValue;
104 
105  if(minValue > maxValue)
106  {
107  std::swap(theRangeConstraint[0],
108  theRangeConstraint[1]);
109  }
110 }
111 
113 {
114  bool result = true;
115  if(hasConstraints())
116  {
117  ossim_float64 tempV = (ossim_float64)value.toDouble();
118  if((tempV >= theRangeConstraint[0])&&
119  (tempV <= theRangeConstraint[1]))
120  {
121  theValue = value;
122  }
123  }
124  else
125  {
126  theValue = value;
127  }
128 
129  return result;
130 }
131 
133 {
134  switch(theType)
135  {
137  {
138  valueResult = ossimString::toString(asInt32());
139  break;
140  }
142  {
143  valueResult = ossimString::toString(asUInt32());
144  break;
145  }
147  {
148  valueResult = ossimString::toString(asFloat32());
149 
150  break;
151  }
153  {
154  valueResult = ossimString::toString(asFloat64());
155  break;
156  }
157  };
158 }
159 
160 
162 {
163  return theType;
164 }
165 
167 {
168  theType = type;
169 }
170 
172 {
173  return (ossim_float64)theValue.toDouble();
174 }
175 
177 {
178  return (ossim_float32)theValue.toDouble();
179 }
180 
182 {
183  return theValue.toUInt32();
184 }
185 
187 {
188  return (ossim_uint16)theValue.toUInt32();
189 }
190 
192 {
193  return (ossim_uint8)theValue.toUInt32();
194 }
195 
197 {
198  return (ossim_int32)theValue.toInt32();
199 }
200 
202 {
203  return (ossim_int16)theValue.toInt32();
204 }
205 
207 {
208  return (ossim_int8)theValue.toInt32();
209 }
virtual void valueToString(ossimString &valueResult) const =0
char ossim_int8
Previous DLL import export section.
float ossim_float32
virtual ossimNumericPropertyType getNumericType() const
static ossimString toString(bool aValue)
Numeric to string methods.
RTTI_DEF1(ossimNumericProperty, "ossimNumericProperty", ossimProperty)
ossimNumericPropertyType theType
signed char ossim_sint8
ossim_uint32 toUInt32() const
virtual const ossimProperty & assign(const ossimProperty &rhs)
unsigned short ossim_uint16
virtual ossimString valueToString() const
virtual ossim_uint8 asUInt8() const
ossim_int32 toInt32() const
double ossim_float64
virtual void setConstraints(double minValue, double maxValue)
virtual void setNumericType(ossimNumericPropertyType type)
virtual ossimObject * dup() const
signed short ossim_sint16
unsigned int ossim_uint32
double toDouble() const
signed int ossim_sint32
virtual ossim_uint32 asUInt32() const
std::vector< double > theRangeConstraint
virtual ossim_sint32 asInt32() const
virtual bool setValue(const ossimString &value)
short ossim_int16
virtual const ossimProperty & assign(const ossimProperty &rhs)
ossimNumericProperty(const ossimString &name=ossimString(""), const ossimString &value=ossimString("0"))
virtual ossim_uint16 asUInt16() const
virtual ossim_float32 asFloat32() const
virtual ossim_float64 asFloat64() const
virtual ossim_sint8 asInt8() const
unsigned char ossim_uint8
virtual bool hasConstraints() const
int ossim_int32
virtual ossim_sint16 asInt16() const