Period.cpp

Go to the documentation of this file.
00001 
00009 #include "Period.h"
00010 #include "PKIFTime.h"
00011 #include "Duration.h"
00012 
00013 #include "components.h"
00014 #include "PKIFCommonErrors.h"
00015 #include "ASN1Errors.h"
00016 #include "PKIFException.h"
00017 
00025 CPKIFPeriod::CPKIFPeriod()
00026 {
00027     impl() = new _CPKIFPeriodImpl;
00028     impl()->m_end->set(6666,6,6,6,06,06);
00029 }
00030 
00031 
00042 CPKIFPeriod::CPKIFPeriod(
00044     CPKIFTimePtr& start_, 
00046     CPKIFTimePtr& end_)
00047 {
00048     // Check start and end times
00049     if( *start_ > *end_ )
00050     {
00051         throw CPKIFException(TOOLKIT_ASN, ASN1_INVALID_PERIOD);
00052     }
00053 
00054     impl() = new _CPKIFPeriodImpl;
00055     impl()->m_start = start_;
00056     impl()->m_end = end_;
00057 }
00058 
00068 CPKIFPeriod::CPKIFPeriod(
00070     CPKIFTimePtr& start_, 
00073     CPKIFDurationPtr& duration_)
00074 {
00075     // Compute end time
00076     CPKIFTimePtr end(new CPKIFTime(*start_ + *duration_));
00077 
00078     // Check start and end times
00079     if( *start_ > *end )
00080     {
00081         throw CPKIFException(TOOLKIT_ASN, ASN1_INVALID_PERIOD);
00082     }
00083 
00084     impl() = new _CPKIFPeriodImpl;
00085     impl()->m_start = start_;
00086     impl()->m_end = end;
00087 }
00088 
00096 CPKIFPeriod::CPKIFPeriod(
00098     CPKIFPeriod& time_)
00099 {
00100     impl() = new _CPKIFPeriodImpl( *(time_.impl()) );
00101 }
00102 
00103 //
00104 // destructor
00105 //
00113 CPKIFPeriod::~CPKIFPeriod()
00114 {
00115     delete impl();
00116     impl() = NULL;
00117 }
00118 
00119 //-----------------------------------------------------------------------
00120 // Properties
00121 //-----------------------------------------------------------------------
00122 
00123 //
00124 // start - returns start time property
00125 //
00133 CPKIFTimePtr CPKIFPeriod::start() const
00134 {
00135     return impl()->m_start;
00136 }
00137 
00138 //
00139 // start - sets start time property
00140 //
00150 void CPKIFPeriod::start(
00152     CPKIFTimePtr& start_)
00153 {
00154     // Check start and end times
00155     if( *start_ > *impl()->m_end )
00156     {
00157         throw CPKIFException(TOOLKIT_ASN, ASN1_INVALID_PERIOD);
00158     }
00159 
00160     impl()->m_start = start_;
00161 }
00162 
00163 //
00164 // end - returns end time property
00165 //
00173 CPKIFTimePtr CPKIFPeriod::end() const
00174 {
00175     return impl()->m_end;
00176 }
00177 
00178 //
00179 // end - sets end time property
00180 //
00190 void CPKIFPeriod::end(
00192     CPKIFTimePtr& end_)
00193 {
00194     // Check start and end times
00195     if( *impl()->m_start > *end_ )
00196     {
00197         throw CPKIFException(TOOLKIT_ASN, ASN1_INVALID_PERIOD);
00198     }
00199 
00200     impl()->m_end = end_;
00201 }
00202 
00203 //
00204 // duration - returns duration property
00205 //
00213 CPKIFDurationPtr CPKIFPeriod::duration() const
00214 {
00215     return CPKIFDurationPtr(new CPKIFDuration((*impl()->m_end - *impl()->m_start)));
00216 }
00217 
00218 //
00219 // contains - returns true if the given time falls within the receiving period
00220 //
00229 bool CPKIFPeriod::contains(
00231     CPKIFTimePtr& time_) const
00232 {
00233     return ( (*impl()->m_start <= *time_) 
00234           && (*time_ <= *impl()->m_end) );
00235 }
00236 
00237 //
00238 // contains - returns true if the given time falls within the receiving period, including
00239 // the skew error
00240 //
00249 bool CPKIFPeriod::contains(
00251     CPKIFTimePtr& time_,
00254     CPKIFDurationPtr& skew_) const
00255 {
00256     CPKIFTime skewedStart = *impl()->m_start - *skew_;
00257     CPKIFTime skewedEnd = *impl()->m_end + *skew_;
00258 
00259     return ( (skewedStart <= *time_) 
00260           && (*time_ <= skewedEnd) );
00261 }
00269 CPKIFPeriod& CPKIFPeriod::operator=(
00271     const CPKIFPeriod& period_)
00272 {
00273     // Check against self
00274     if( this != &period_ )
00275     {
00276         *impl() = *(period_.impl());
00277     }
00278 
00279     return *this;
00280 }
00281 
00291 struct _CPKIFPeriodImpl*& CPKIFPeriod::impl() const
00292 {
00293     return ((_CPKIFPeriodImpl*&)m_pData); 
00294 }

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