Duration.cpp

Go to the documentation of this file.
00001 
00009 #include "Duration.h"
00010 #include "PKIFTime.h"
00011 
00012 
00014 
00015 struct CPKIFDurationImpl
00016 {
00017   double m_duration;
00018 };
00019 
00021 
00029 CPKIFDuration::CPKIFDuration()
00030   :m_impl (new CPKIFDurationImpl)
00031 {
00032     m_impl->m_duration = 0;
00033 }
00041 CPKIFDuration::CPKIFDuration(
00044     const CPKIFDuration& duration_)
00045   :m_impl (new CPKIFDurationImpl)
00046 {
00047     m_impl->m_duration = duration_.m_impl->m_duration;
00048 }
00056 CPKIFDuration::~CPKIFDuration()
00057 {
00058     if(m_impl)
00059     {
00060         m_impl->m_duration = 0;
00061     
00062         delete m_impl;
00063         m_impl = 0;
00064     }
00065 }
00066 
00067 //------------------------------------------------------------------
00068 // Properties
00069 //------------------------------------------------------------------
00077 double CPKIFDuration::asSeconds() const
00078 {
00079     double tmp = m_impl->m_duration * 86400.0;
00080     return tmp;
00081 }
00089 double CPKIFDuration::asDays() const
00090 {
00091     return m_impl->m_duration;
00092 }
00093 //bool nearsSecond( double durationInSeconds_, double precision_=0.5 )
00094 //{
00095 //  double result = asSeconds() - durationInSeconds_;
00096 //  if( result <= precision_ && result >= -precision_ )
00097 //  {
00098 //      return true;
00099 //  }
00100 //  return false;
00101 //}
00102 //bool nearsDay( double durationInDays_, double precision_=0.5 )
00103 //{
00104 //  double result = asDays() - durationInDays_;
00105 //  if( result <= precision_ && result >= -precision_ )
00106 //  {
00107 //      return true;
00108 //  }
00109 //  return false;
00110 //}
00111 
00112 //------------------------------------------------------------------
00113 // Operations
00114 //------------------------------------------------------------------
00122 void CPKIFDuration::setSeconds(
00124     double seconds_)
00125 {
00126     m_impl->m_duration = seconds_ / 86400.0;
00127 }
00135 void CPKIFDuration::setDays(
00137     double days_)
00138 {
00139     m_impl->m_duration = days_;
00140 }
00141 
00142 //------------------------------------------------------------------
00143 // Operators
00144 //------------------------------------------------------------------
00152 CPKIFDuration& CPKIFDuration::operator=(
00154     const CPKIFDuration& duration_)
00155 {
00156     m_impl->m_duration = duration_.m_impl->m_duration;
00157     return *this;
00158 }
00168 bool CPKIFDuration::operator==(
00170     const CPKIFDuration& duration_) const
00171 {
00172     return( m_impl->m_duration == duration_.m_impl->m_duration );
00173 }
00183 bool CPKIFDuration::operator!=(
00185     const CPKIFDuration& duration_) const
00186 {
00187     return( m_impl->m_duration != duration_.m_impl->m_duration );
00188 }
00198 bool CPKIFDuration::operator>(
00200     const CPKIFDuration& duration_) const
00201 {
00202     return( m_impl->m_duration > duration_.m_impl->m_duration );
00203 }
00213 bool CPKIFDuration::operator>=(
00215     const CPKIFDuration& duration_) const
00216 {
00217     return( m_impl->m_duration >= duration_.m_impl->m_duration );
00218 }
00228 bool CPKIFDuration::operator<(
00230     const CPKIFDuration& duration_) const
00231 {
00232     return( m_impl->m_duration < duration_.m_impl->m_duration );
00233 }
00243 bool CPKIFDuration::operator<=(
00245     const CPKIFDuration& duration_) const
00246 {
00247     return( m_impl->m_duration <= duration_.m_impl->m_duration );
00248 }
00256 CPKIFDuration& CPKIFDuration::operator+=(
00258     const CPKIFDuration& duration_)
00259 {
00260     double sum = m_impl->m_duration + duration_.m_impl->m_duration;
00261     m_impl->m_duration = sum;
00262     return *this;
00263 }
00271 CPKIFDuration& CPKIFDuration::operator-=(
00273     const CPKIFDuration& duration_)
00274 {
00275     double diff = m_impl->m_duration - duration_.m_impl->m_duration;
00276     m_impl->m_duration = diff;
00277     return *this;
00278 }
00287 CPKIFDuration CPKIFDuration::operator+(
00289     const CPKIFDuration& duration_) const
00290 {
00291     CPKIFDuration result(*this);
00292     result.m_impl->m_duration += duration_.m_impl->m_duration;
00293     return result;
00294 }
00302 CPKIFDuration CPKIFDuration::operator-(
00304     const CPKIFDuration& duration_) const
00305 {
00306     CPKIFDuration result(*this);
00307     result.m_impl->m_duration -= duration_.m_impl->m_duration;
00308     return result;
00309 }
00318 CPKIFTime CPKIFDuration::operator+(
00320     const CPKIFTime& time_)
00321 {
00322     CPKIFTime aTime(time_);
00323     aTime = aTime + *this;
00324     return aTime;
00325 }
00326 

Generated on Mon Nov 15 11:15:50 2010 for PublicKeyInfrastructureFramework(PKIF) by  doxygen 1.5.6