OSSIM - Open Source Software Image Map  Version 1.9.0 (20180803)
ossimDateProperty.cpp
Go to the documentation of this file.
1 //*******************************************************************
2 // Copyright (C) 2000 ImageLinks Inc.
3 //
4 // LICENSE: LGPL see top level license.txt
5 //
6 // Author: Garrett Potts (gpotts@imagelinks.com)
7 //
8 //*************************************************************************
9 // $Id: ossimDateProperty.cpp 9094 2006-06-13 19:12:40Z dburken $
10 //
11 
12 #include <iostream>
13 #include <iomanip>
14 #include <sstream>
16 
17 
18 RTTI_DEF1(ossimDateProperty, "ossimDateProperty", ossimProperty);
19 
21  :ossimProperty("")
22 {
23  setDate(ossimDate());
24 }
25 
27  const ossimString& value)
28  :ossimProperty(name)
29 {
30  setValue(value);
31 }
32 
34  const ossimLocalTm& value)
35  :ossimProperty(name),
36  theValue(value)
37 {
38 }
39 
41  :ossimProperty(src),
42  theValue(src.theValue)
43 {
44 }
45 
47 {
48  return new ossimDateProperty(*this);
49 }
50 
52 {
53  theValue = localTm;
54 }
55 
57 {
58  return theValue;
59 }
60 
62 {
63  if(value.trim() == "")
64  {
65  theValue = ossimDate();
66  return true;
67  }
68  bool result = value.size() == 14;
69 
70  ossimString year;
71  ossimString month;
72  ossimString day;
73  ossimString hour;
75  ossimString sec;
76 
77  if(value.size() == 14)
78  {
79  year = ossimString(value.begin(),
80  value.begin()+4);
81  month = ossimString(value.begin()+4,
82  value.begin()+6);
83  day = ossimString(value.begin()+6,
84  value.begin()+8);
85  hour = ossimString(value.begin()+8,
86  value.begin()+10);
87  min = ossimString(value.begin()+10,
88  value.begin()+12);
89  sec = ossimString(value.begin()+12,
90  value.begin()+14);
91 
92  theValue.setYear(year.toUInt32());
93  theValue.setMonth(month.toUInt32());
94  theValue.setDay(day.toUInt32());
95  theValue.setHour(hour.toUInt32());
96  theValue.setMin(min.toUInt32());
97  theValue.setSec(sec.toUInt32());
98  }
99 
100  return result;
101 }
102 
104 {
105  std::ostringstream out;
106 
107  out << std::setw(4)
108  << std::setfill('0')
109  << theValue.getYear()
110  << std::setw(2)
111  << std::setfill('0')
112  << theValue.getMonth()
113  << std::setw(2)
114  << std::setfill('0')
115  << theValue.getDay()
116  << std::setw(2)
117  << std::setfill('0')
118  << theValue.getHour()
119  << std::setw(2)
120  << std::setfill('0')
121  << theValue.getMin()
122  << std::setw(2)
123  << std::setfill('0')
124  << theValue.getSec();
125 
126  valueResult = out.str();
127 
128 }
129 
131 {
133 
134  const ossimDateProperty* rhsPtr = dynamic_cast<const ossimDateProperty*>(&rhs);
135  if(rhsPtr)
136  {
137  theValue = rhsPtr->theValue;
138  }
139  else
140  {
141  setValue(rhs.valueToString());
142  }
143 
144  return *this;
145 }
virtual void valueToString(ossimString &valueResult) const =0
ossimLocalTm & setDay(int day)
Definition: ossimDate.cpp:476
void setDate(const ossimLocalTm &localTm)
std::basic_ostringstream< char > ostringstream
Class for char output memory streams.
Definition: ossimIosFwd.h:35
ossimLocalTm theValue
int getSec() const
Definition: ossimDate.cpp:580
virtual const ossimProperty & assign(const ossimProperty &rhs)
int getYear() const
Definition: ossimDate.cpp:433
int getMin() const
Definition: ossimDate.cpp:575
ossim_uint32 toUInt32() const
virtual const ossimProperty & assign(const ossimProperty &rhs)
virtual ossimString valueToString() const
const ossimLocalTm & getDate() const
std::string::size_type size() const
Definition: ossimString.h:405
std::string::iterator begin()
Definition: ossimString.h:420
ossimLocalTm & setMonth(int month)
Definition: ossimDate.cpp:483
ossimString trim(const ossimString &valueToTrim=ossimString(" \\)) const
this will strip lead and trailing character passed in.
ossimLocalTm & setYear(int year)
Definition: ossimDate.cpp:490
ossimLocalTm & setHour(int h)
Definition: ossimDate.cpp:590
ossimLocalTm & setSec(int s)
Definition: ossimDate.cpp:604
RTTI_DEF1(ossimDateProperty, "ossimDateProperty", ossimProperty)
int getMonth() const
Definition: ossimDate.cpp:448
int getDay() const
Definition: ossimDate.cpp:453
ossimLocalTm & setMin(int m)
Definition: ossimDate.cpp:597
virtual ossimObject * dup() const
int getHour() const
Definition: ossimDate.cpp:570
virtual bool setValue(const ossimString &value)
#define min(a, b)
Definition: auxiliary.h:75