OSSIM - Open Source Software Image Map  Version 1.9.0 (20180803)
Public Member Functions | Protected Attributes | List of all members
ossimDuration Class Reference

#include <ossimDuration.h>

Public Member Functions

 ossimDuration (const ossimString &iso8601Duration=ossimString(""))
 This will take an iso8601 encoded duration string and parse out the individual values. More...
 
void clearFields ()
 zero out all fields More...
 
bool readIso8601Encoding (std::istream &in)
 This will take an iso8601 encoded duration stream and parse out the individual values it will stop when a blank character or whitespace is found. More...
 
bool setByIso8601DurationString (const ossimString &iso8601Duration)
 This will take an iso8601 encoded duration stream and parse out the individual values it will stop when a blank character or whitespace is found. More...
 
void toIso8601DurationString (ossimString &result)
 Will take the field values and encode into a iso8601 string format. More...
 
ossim_float64 toSeconds () const
 this will not use the months field or the years field but will use all other fields to calculate a total value in seconds. More...
 
void setSign (ossim_int32 value)
 
ossim_int32 sign () const
 returns the sign. More...
 
void setYears (ossim_uint64 value)
 
ossim_int64 years () const
 
void setMonths (ossim_uint64 value)
 
ossim_int64 months () const
 
void setWeeks (ossim_uint64 value)
 
ossim_int64 weeks () const
 
void setDays (ossim_uint64 value)
 
ossim_int64 days () const
 
void setHours (ossim_uint64 value)
 
ossim_int64 hours () const
 
void setMinutes (ossim_uint64 value)
 
ossim_int64 minutes () const
 
void setSeconds (ossim_float64 value)
 
ossim_float64 seconds () const
 
void setAll (ossim_int32 signValue, ossim_uint64 yearsValue, ossim_uint64 monthsValue, ossim_uint64 weeksValue, ossim_uint64 daysValue, ossim_uint64 hoursValue, ossim_uint64 minutesValue, ossim_float64 secondsValue)
 Sets all values in one call. More...
 

Protected Attributes

ossim_int32 theSign
 
ossim_int64 theYears
 
ossim_int64 theMonths
 
ossim_int64 theWeeks
 
ossim_int64 theDays
 
ossim_int64 theHours
 
ossim_int64 theMinutes
 
ossim_float64 theSeconds
 

Detailed Description

Definition at line 18 of file ossimDuration.h.

Constructor & Destructor Documentation

◆ ossimDuration()

ossimDuration::ossimDuration ( const ossimString iso8601Duration = ossimString(""))

This will take an iso8601 encoded duration string and parse out the individual values.

Definition at line 15 of file ossimDuration.cpp.

References ossimString::empty(), and setByIso8601DurationString().

16 :theSign(1),
17 theYears(0),
18 theMonths(0),
19 theWeeks(0),
20 theDays(0),
21 theHours(0),
22 theMinutes(0),
23 theSeconds(0)
24 {
25  if(!iso8601Duration.empty())
26  {
27  setByIso8601DurationString(iso8601Duration);
28  }
29 }
ossim_int64 theHours
ossim_int64 theDays
ossim_int64 theYears
ossim_float64 theSeconds
ossim_int64 theMinutes
ossim_int64 theMonths
ossim_int32 theSign
bool empty() const
Definition: ossimString.h:411
ossim_int64 theWeeks
bool setByIso8601DurationString(const ossimString &iso8601Duration)
This will take an iso8601 encoded duration stream and parse out the individual values it will stop wh...

Member Function Documentation

◆ clearFields()

void ossimDuration::clearFields ( )

zero out all fields

Definition at line 31 of file ossimDuration.cpp.

References theDays, theHours, theMinutes, theMonths, theSeconds, theSign, theWeeks, and theYears.

Referenced by readIso8601Encoding(), and setByIso8601DurationString().

32 {
33  theSign = 1;
34  theYears = 0;
35  theMonths = 0;
36  theWeeks = 0;
37  theDays = 0;
38  theHours = 0;
39  theMinutes = 0;
40  theSeconds = 0;
41 }
ossim_int64 theHours
ossim_int64 theDays
ossim_int64 theYears
ossim_float64 theSeconds
ossim_int64 theMinutes
ossim_int64 theMonths
ossim_int32 theSign
ossim_int64 theWeeks

◆ days()

ossim_int64 ossimDuration::days ( ) const
inline

Definition at line 103 of file ossimDuration.h.

104  {
105  return theDays;
106  }
ossim_int64 theDays

◆ hours()

ossim_int64 ossimDuration::hours ( ) const
inline

Definition at line 111 of file ossimDuration.h.

112  {
113  return theHours;
114  }
ossim_int64 theHours

◆ minutes()

ossim_int64 ossimDuration::minutes ( ) const
inline

Definition at line 119 of file ossimDuration.h.

120  {
121  return theMinutes;
122  }
ossim_int64 theMinutes

◆ months()

ossim_int64 ossimDuration::months ( ) const
inline

Definition at line 87 of file ossimDuration.h.

88  {
89  return theMonths;
90  }
ossim_int64 theMonths

◆ readIso8601Encoding()

bool ossimDuration::readIso8601Encoding ( std::istream &  in)

This will take an iso8601 encoded duration stream and parse out the individual values it will stop when a blank character or whitespace is found.

Definition at line 51 of file ossimDuration.cpp.

References clearFields(), and theSign.

Referenced by setByIso8601DurationString().

52 {
53  clearFields();
54 
55  if(in.peek()=='-')
56  {
57  theSign = -1;
58  in.ignore();
59  }
60  if(in.peek()!='P')
61  {
62  return false;
63  }
64  // skip the period indicater
65  in.ignore();
66 
67  // now we start parsing the date portion and the time portion
68  ossimString value;
69  bool doneFlag = false;
70  bool badParseFlag = false;
71  bool doingTimeFlag = false;
72  while(!doneFlag)
73  {
74  int c = in.peek();
75  if(!in)
76  {
77  doneFlag = true;
78  }
79  else
80  {
81  if(isWhiteSpace(c))
82  {
83  doneFlag = true; // parse til blank character is met
84  }
85  else if(isalpha(c))
86  {
87  // we are done with current value
88  //
89  // check to see if was a Time seaprator of value
90  // 'T'
91  if(c == 'T')
92  {
93  // then it was a time separator so do nothing
94  value = ""; // go ahead and null it out for now
95  doingTimeFlag = true; // now in time parsing portion
96  }
97  else
98  {
99  if(doingTimeFlag)
100  {
101  // check time values
102  if(c == 'H')
103  {
104  theHours = value.toUInt64();
105  }
106  else if(c == 'M')
107  {
108  theMinutes = value.toUInt64();
109  }
110  else if(c == 'S')
111  {
112  theSeconds = value.toFloat64();
113  }
114  else
115  {
116  doneFlag = true;
117  badParseFlag = true;
118  }
119  value = ""; // reset the value
120  }
121  else // check date characters instead
122  {
123  if(c == 'Y')
124  {
125  theYears = value.toUInt64();
126  }
127  else if(c == 'M')
128  {
129  theMonths = value.toUInt64();
130  }
131  else if(c == 'W')
132  {
133  theWeeks = value.toUInt64();
134  }
135  else if(c == 'D')
136  {
137  theDays = value.toUInt64();
138  }
139  else
140  {
141  doneFlag = true;
142  badParseFlag = true;
143  }
144  value = ""; // reset the value
145  }
146  }
147  }
148  else if(isdigit(c)||(c=='.'))// not an alphabetic character so add it to the value string
149  {
150  value += static_cast<char>(c);
151  }
152  else
153  {
154  doneFlag = true;
155  badParseFlag = true;
156  }
157  }
158  if(!doneFlag)
159  {
160  in.ignore();
161  }
162  }
163 
164  return badParseFlag;
165 }
ossim_int64 theHours
ossim_int64 theDays
ossim_int64 theYears
void clearFields()
zero out all fields
ossim_float64 theSeconds
ossim_float64 toFloat64() const
ossim_int64 theMinutes
ossim_int64 theMonths
ossim_uint64 toUInt64() const
ossim_int32 theSign
ossim_int64 theWeeks
OSSIM_DLL bool isWhiteSpace(int c)
Definition: ossimCommon.cpp:49

◆ seconds()

ossim_float64 ossimDuration::seconds ( ) const
inline

Definition at line 127 of file ossimDuration.h.

128  {
129  return theSeconds;
130  }
ossim_float64 theSeconds

◆ setAll()

void ossimDuration::setAll ( ossim_int32  signValue,
ossim_uint64  yearsValue,
ossim_uint64  monthsValue,
ossim_uint64  weeksValue,
ossim_uint64  daysValue,
ossim_uint64  hoursValue,
ossim_uint64  minutesValue,
ossim_float64  secondsValue 
)
inline

Sets all values in one call.

Definition at line 135 of file ossimDuration.h.

143  {
144  theSign = ((signValue < 0)?-1:1);
145  theYears = yearsValue;
146  theMonths = monthsValue;
147  theWeeks = weeksValue;
148  theDays = daysValue;
149  theHours = hoursValue;
150  theMinutes = minutesValue;
151  theSeconds = secondsValue;
152  }
ossim_int64 theHours
ossim_int64 theDays
ossim_int64 theYears
ossim_float64 theSeconds
ossim_int64 theMinutes
ossim_int64 theMonths
ossim_int32 theSign
ossim_int64 theWeeks

◆ setByIso8601DurationString()

bool ossimDuration::setByIso8601DurationString ( const ossimString iso8601Duration)

This will take an iso8601 encoded duration stream and parse out the individual values it will stop when a blank character or whitespace is found.

Definition at line 167 of file ossimDuration.cpp.

References clearFields(), ossimString::empty(), and readIso8601Encoding().

Referenced by ossimDuration().

168 {
169  if(iso8601Duration.empty())
170  {
171  clearFields();
172  return true;
173  }
174  std::istringstream in(iso8601Duration);
175  return readIso8601Encoding(in);
176 }
void clearFields()
zero out all fields
bool readIso8601Encoding(std::istream &in)
This will take an iso8601 encoded duration stream and parse out the individual values it will stop wh...
bool empty() const
Definition: ossimString.h:411
std::basic_istringstream< char > istringstream
Class for char input memory streams.
Definition: ossimIosFwd.h:32

◆ setDays()

void ossimDuration::setDays ( ossim_uint64  value)
inline

Definition at line 99 of file ossimDuration.h.

100  {
101  theDays = value;
102  }
ossim_int64 theDays

◆ setHours()

void ossimDuration::setHours ( ossim_uint64  value)
inline

Definition at line 107 of file ossimDuration.h.

108  {
109  theHours = value;
110  }
ossim_int64 theHours

◆ setMinutes()

void ossimDuration::setMinutes ( ossim_uint64  value)
inline

Definition at line 115 of file ossimDuration.h.

116  {
117  theMinutes = value;
118  }
ossim_int64 theMinutes

◆ setMonths()

void ossimDuration::setMonths ( ossim_uint64  value)
inline

Definition at line 83 of file ossimDuration.h.

84  {
85  theMonths = value;
86  }
ossim_int64 theMonths

◆ setSeconds()

void ossimDuration::setSeconds ( ossim_float64  value)
inline

Definition at line 123 of file ossimDuration.h.

124  {
125  theSeconds = value;
126  }
ossim_float64 theSeconds

◆ setSign()

void ossimDuration::setSign ( ossim_int32  value)
inline

Definition at line 64 of file ossimDuration.h.

65  {
66  theSign = ((value < 0)?-1:1);
67  }
ossim_int32 theSign

◆ setWeeks()

void ossimDuration::setWeeks ( ossim_uint64  value)
inline

Definition at line 91 of file ossimDuration.h.

92  {
93  theWeeks = value;
94  }
ossim_int64 theWeeks

◆ setYears()

void ossimDuration::setYears ( ossim_uint64  value)
inline

Definition at line 75 of file ossimDuration.h.

76  {
77  theYears = value;
78  }
ossim_int64 theYears

◆ sign()

ossim_int32 ossimDuration::sign ( ) const
inline

returns the sign.

Should be either -1 or 1 for the return

Definition at line 71 of file ossimDuration.h.

72  {
73  return theSign;
74  }
ossim_int32 theSign

◆ toIso8601DurationString()

void ossimDuration::toIso8601DurationString ( ossimString result)

Will take the field values and encode into a iso8601 string format.

Note, anything that is 0 will not be output.

Definition at line 178 of file ossimDuration.cpp.

References ossim::almostEqual(), theDays, theHours, theMinutes, theMonths, theSeconds, theSign, theWeeks, theYears, and ossimString::toString().

179 {
180  result = "";
181  bool hasDatePeriod = ((theYears!=0)||
182  (theMonths!=0)||
183  (theWeeks!=0)||
184  (theDays!=0));
185  bool hasTimePeriod = ((theHours!=0)||
186  (theMinutes!=0)||
187  (!ossim::almostEqual(theSeconds, 0.0, .00000000001)));
188  // if no time or date period present then return empty
189  if(!(hasDatePeriod || hasTimePeriod))
190  {
191  return;
192  }
193  if(theSign < 0)
194  {
195  result += "-";
196  }
197  result += "P";
198  if(hasDatePeriod)
199  {
200  if(theYears > 0)
201  {
203  result+="Y";
204  }
205  if(theMonths>0)
206  {
208  result+="M";
209  }
210  if(theWeeks>0)
211  {
213  result+="W";
214  }
215  if(theDays>0)
216  {
218  result+="D";
219  }
220  }
221  if(hasTimePeriod)
222  {
223  result+="T";
224  if(theHours>0)
225  {
227  result+="H";
228  }
229  if(theMinutes>0)
230  {
232  result+="M";
233  }
234  if(theSeconds>0)
235  {
236  result+=ossimString::toString(theSeconds, 15);
237  result+="S";
238  }
239  }
240 }
ossim_int64 theHours
ossim_int64 theDays
ossim_int64 theYears
bool almostEqual(T x, T y, T tolerance=FLT_EPSILON)
Definition: ossimCommon.h:53
static ossimString toString(bool aValue)
Numeric to string methods.
ossim_float64 theSeconds
ossim_int64 theMinutes
ossim_int64 theMonths
ossim_int32 theSign
ossim_int64 theWeeks

◆ toSeconds()

ossim_float64 ossimDuration::toSeconds ( ) const

this will not use the months field or the years field but will use all other fields to calculate a total value in seconds.

We can not determine leap years and how many days are in a month so those are omitted and so this serves as a utility method to just calculate the total seconds if you give a duration string that contains only one or all or any of the following: weeks, days, minutes, hours, and/or seconds.

If the sign is set to negative it will return a negative value.

Definition at line 242 of file ossimDuration.cpp.

References theDays, theHours, theMinutes, theSeconds, theSign, and theWeeks.

243 {
244  ossim_float64 result = theSeconds;
245 
246  if(theMinutes > 0)
247  {
248  result += theMinutes*60.0;
249  }
250  if(theHours > 0)
251  {
252  result += theHours*3600.0;
253  }
254  if(theDays > 0)
255  {
256  result += theDays*86400.0;
257  }
258  if(theWeeks > 0)
259  {
260  result += theWeeks*604800;
261  }
262  if(theSign < 0)
263  {
264  result *= -1.0;
265  }
266  return result;
267 }
ossim_int64 theHours
ossim_int64 theDays
double ossim_float64
ossim_float64 theSeconds
ossim_int64 theMinutes
ossim_int32 theSign
ossim_int64 theWeeks

◆ weeks()

ossim_int64 ossimDuration::weeks ( ) const
inline

Definition at line 95 of file ossimDuration.h.

96  {
97  return theWeeks;
98  }
ossim_int64 theWeeks

◆ years()

ossim_int64 ossimDuration::years ( ) const
inline

Definition at line 79 of file ossimDuration.h.

80  {
81  return theYears;
82  }
ossim_int64 theYears

Member Data Documentation

◆ theDays

ossim_int64 ossimDuration::theDays
protected

Definition at line 160 of file ossimDuration.h.

Referenced by clearFields(), toIso8601DurationString(), and toSeconds().

◆ theHours

ossim_int64 ossimDuration::theHours
protected

Definition at line 161 of file ossimDuration.h.

Referenced by clearFields(), toIso8601DurationString(), and toSeconds().

◆ theMinutes

ossim_int64 ossimDuration::theMinutes
protected

Definition at line 162 of file ossimDuration.h.

Referenced by clearFields(), toIso8601DurationString(), and toSeconds().

◆ theMonths

ossim_int64 ossimDuration::theMonths
protected

Definition at line 158 of file ossimDuration.h.

Referenced by clearFields(), and toIso8601DurationString().

◆ theSeconds

ossim_float64 ossimDuration::theSeconds
protected

Definition at line 163 of file ossimDuration.h.

Referenced by clearFields(), toIso8601DurationString(), and toSeconds().

◆ theSign

ossim_int32 ossimDuration::theSign
protected

◆ theWeeks

ossim_int64 ossimDuration::theWeeks
protected

Definition at line 159 of file ossimDuration.h.

Referenced by clearFields(), toIso8601DurationString(), and toSeconds().

◆ theYears

ossim_int64 ossimDuration::theYears
protected

Definition at line 157 of file ossimDuration.h.

Referenced by clearFields(), and toIso8601DurationString().


The documentation for this class was generated from the following files: