From 1ad704ead59a7535c2c866019c7ae60ed69ccacd Mon Sep 17 00:00:00 2001 From: Guillaume Pasero <guillaume.pasero@c-s.fr> Date: Mon, 5 May 2014 19:20:53 +0200 Subject: [PATCH] ADD: adapter for ossimLocalTm class --- .../OssimAdapters/otbDateTimeAdapter.cxx | 88 +++++++++++++++++ .../OssimAdapters/otbDateTimeAdapter.h | 96 +++++++++++++++++++ 2 files changed, 184 insertions(+) create mode 100644 Code/UtilitiesAdapters/OssimAdapters/otbDateTimeAdapter.cxx create mode 100644 Code/UtilitiesAdapters/OssimAdapters/otbDateTimeAdapter.h diff --git a/Code/UtilitiesAdapters/OssimAdapters/otbDateTimeAdapter.cxx b/Code/UtilitiesAdapters/OssimAdapters/otbDateTimeAdapter.cxx new file mode 100644 index 0000000000..8e63e84ca8 --- /dev/null +++ b/Code/UtilitiesAdapters/OssimAdapters/otbDateTimeAdapter.cxx @@ -0,0 +1,88 @@ +/*========================================================================= + + Program: ORFEO Toolbox + Language: C++ + Date: $Date$ + Version: $Revision$ + + + Copyright (c) Centre National d'Etudes Spatiales. All rights reserved. + See OTBCopyright.txt for details. + + + This software is distributed WITHOUT ANY WARRANTY; without even + the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + PURPOSE. See the above copyright notices for more information. + + =========================================================================*/ +#include "otbDateTimeAdapter.h" + +#include "ossim/base/ossimDate.h" + +namespace otb +{ + +DateTimeAdapter::DateTimeAdapter() +{ + m_LocalTm = new ossimLocalTm(0); +} + +DateTimeAdapter::~DateTimeAdapter() +{ + if (m_LocalTm != NULL) + { + delete m_LocalTm; + } +} + +int +DateTimeAdapter::GetYear() +{ + return m_LocalTm->getYear(); +} + +int +DateTimeAdapter::GetMonth() +{ + return m_LocalTm->getMonth(); +} + +int +DateTimeAdapter::GetDay() +{ + return m_LocalTm->getDay(); +} + +int +DateTimeAdapter::GetHour() +{ + return m_LocalTm->getHour(); +} + +int +DateTimeAdapter::GetMinute() +{ + return m_LocalTm->getMin(); +} + +double +DateTimeAdapter::GetSeconds() +{ + return static_cast<double>(m_LocalTm->getSec()) + + m_LocalTm->getFractionalSecond(); +} + +bool +DateTimeAdapter::SetFromIso8601(const std::string &date) +{ + return m_LocalTm->setIso8601(date); +} + +double +DateTimeAdapter::GetDeltaInSeconds(const DateTimeAdapter *pastDate) +{ + return m_LocalTm->deltaInSeconds(*(pastDate->m_LocalTm)); +} + + +} // namespace otb diff --git a/Code/UtilitiesAdapters/OssimAdapters/otbDateTimeAdapter.h b/Code/UtilitiesAdapters/OssimAdapters/otbDateTimeAdapter.h new file mode 100644 index 0000000000..cc75219893 --- /dev/null +++ b/Code/UtilitiesAdapters/OssimAdapters/otbDateTimeAdapter.h @@ -0,0 +1,96 @@ +/*========================================================================= + + Program: ORFEO Toolbox + Language: C++ + Date: $Date$ + Version: $Revision$ + + + Copyright (c) Centre National d'Etudes Spatiales. All rights reserved. + See OTBCopyright.txt for details. + + + This software is distributed WITHOUT ANY WARRANTY; without even + the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + PURPOSE. See the above copyright notices for more information. + + =========================================================================*/ +#ifndef __otbDateTimeAdapter_h +#define __otbDateTimeAdapter_h + +#include "itkObject.h" +#include "itkObjectFactory.h" + +class ossimLocalTm; +//class ossimDate; +//class ossimTime; + +namespace otb +{ + +/** \class DateTimeAdapter + * \brief This is a dummy class to the ossimLocalTm class + * + * This class provide functions to define, compare and measure times and dates. + * + **/ +class DateTimeAdapter : public itk::Object +{ +public: + /** Standard class typedefs. */ + typedef DateTimeAdapter Self; + typedef itk::Object Superclass; + typedef itk::SmartPointer<Self> Pointer; + typedef itk::SmartPointer<const Self> ConstPointer; + + /** Method for creation through the object factory. */ + itkNewMacro(Self); + + /** Run-time type information (and related methods). */ + itkTypeMacro(DateTimeAdapter, itk::Object); + + /** Year Accessor*/ + int GetYear(); + + /** Month Accessor*/ + int GetMonth(); + + /** Day Accessor*/ + int GetDay(); + + /** Hour Accessor*/ + int GetHour(); + + /** Minute Accessor*/ + int GetMinute(); + + /** Seconds Accessor*/ + double GetSeconds(); + + /** Set the date and time from an Iso8601 string + * Return true if the date is valid + */ + bool SetFromIso8601(const std::string &date); + + /** Return the delta with an other date, expressed in seconds */ + double GetDeltaInSeconds(const DateTimeAdapter *pastDate); + + // TODO : add print self function + +protected: + DateTimeAdapter(); + virtual ~DateTimeAdapter(); + +private: + DateTimeAdapter(const Self &); //purposely not implemented + void operator =(const Self&); //purposely not implemented + + ossimLocalTm *m_LocalTm; + +}; + +// TODO add extern '<<' function + +} // namespace otb + +#endif -- GitLab