TimeSpan Class Reference

#include <timespan.h>

Inheritance diagram for TimeSpan:

CCObject SimpleCCObject List of all members.

Public Member Functions

 TimeSpan ()
 Constructs an empty TimeSpan object.
 TimeSpan (TimeSlice lower, TimeSlice upper)
 Constructs an bounded TimeSpan object.
 TimeSpan (const TimeSpan &other)
 Copy contructor for the TimeSpan object.
TimeSlice Lo () const
TimeSlice Hi () const
TimeSlice GetLowerBound () const
 Dig out the lower bound of this TimeSpan object.
TimeSlice GetUpperBound () const
 Dig out the upper bound of this TimeSpan object. It should always be greater than or equal to the lower bound, otherwise this span is invalid.
BOOL IsEmpty () const
 Check whether this time span object contains a non empty time frame. A time span becomes empty as a result of trying to perform boolean operations on time spans resulting in empty spans.
double GetRelativeTime (TimeSlice current) const
 Convert the absolute time 'current' into a relative value. If the current value is within this time span then the double result will lie between 0 and 1, otherwise it will lie somewhere on the real line.
TimeSlice GetAbsoluteTime (double current) const
 Convert the relative time 'current' into an absolute value. Performs a linear interpolation on this timespans start and end times. Hence if 0<=current<=1 then the returned time will be somewhere within this time span.
TimeSpan Union (const TimeSpan &other) const
 Find the union of this span with the other span. This union will always be valid if either or both spans are non empty.
TimeSpan Intersection (const TimeSpan &other) const
 Find the intersection of this span with 'other' span. If the intersection does not exist, either because one of the spans is empty or both spans are valid but they don't intersect then an empty timespan object is returned. Otherwise the intersection is returned.
BOOL SetBounds (TimeSlice lower, TimeSlice upper)
 Set the bounds of this time span object. The bounds are always set in the object even if they are invalid.
BOOL IsSameAs (const TimeSpan &other) const
 Check whether two TimeSpan objects are the same.
BOOL IsIntersectedWith (const TimeSpan &other) const
 Determine if this time span is intersected with the time span supplied.
BOOL Contains (const TimeSpan &other) const
 Check wether the time span expressed by 'other' is contained entirely within this time span.
BOOL InBounds (TimeSlice current) const
 Checks whether the given time slice is within the bounds of this span.
void Inflate (TimeSlice inflate)
 Inflates the bounds of this object by 'inflate'.
TimeSpan operator+ (TimeSlice shift) const
 Returns TimeSpanA = TimeSpanB + TimeSlice.
TimeSpan operator+ (const TimeSpan &other) const
 Overload operator+ to perform a union opertion.
TimeSpan operator- (TimeSlice shift) const
 Subtracts 'value' from the bounds of this timespan and returns the result as a new time span.
TimeSpan operator- (const TimeSpan &other) const
 Overload the operator- function to perform an intersection of two time spans returning the result in a new timespan.
TimeSpanoperator= (const TimeSpan &other)
 Assignment operator overload, assigns this time span with that of 'other' and returns a reference for further assignment.

Protected Member Functions

void MakeInvalid ()
 Set the lower and upper time span bounds to the view's now and the documents max time.Make this time span invalid.

Private Attributes

TimeSlice LO
TimeSlice HI

Detailed Description

Definition at line 116 of file timespan.h.


Constructor & Destructor Documentation

TimeSpan::TimeSpan  ) 
 

Constructs an empty TimeSpan object.

Author:
Mike_Kenny (Xara Group Ltd) <camelotdev@xara.com>
Date:
17/03/97

Definition at line 117 of file timespan.cpp.

00118 {
00119     LO=HI=0;
00120 }

TimeSpan::TimeSpan TimeSlice  lower,
TimeSlice  upper
 

Constructs an bounded TimeSpan object.

Author:
Mike_Kenny (Xara Group Ltd) <camelotdev@xara.com>
Date:
17/03/97
Parameters:
lower = a lower bound time to inherit [INPUTS] upper = an upper bound time to inherit

Definition at line 135 of file timespan.cpp.

00136 {
00137     if (!SetBounds(lower,upper))
00138     {
00139         ERROR3("TimeSpan() constructor called with invalid bounds")
00140     }
00141 }

TimeSpan::TimeSpan const TimeSpan other  ) 
 

Copy contructor for the TimeSpan object.

Author:
Mike_Kenny (Xara Group Ltd) <camelotdev@xara.com>
Date:
17/03/97
Parameters:
other = a reference to another time span [INPUTS]

Definition at line 155 of file timespan.cpp.

00156 {
00157     (*this)=other;
00158 }


Member Function Documentation

BOOL TimeSpan::Contains const TimeSpan other  )  const
 

Check wether the time span expressed by 'other' is contained entirely within this time span.

Author:
Mike_Kenny (Xara Group Ltd) <camelotdev@xara.com>
Date:
17/03/97
Parameters:
A reference to another timespan [INPUTS]
Returns:
TRUE then other is contained entirely within this time span FALSE if not. Other may still intersect this time span.

Definition at line 430 of file timespan.cpp.

00431 {
00432     // A.Contains(Empty(B))?  Empty(A).Contains(B)?
00433     if (IsEmpty() || other.IsEmpty())
00434         return FALSE;
00435 
00436     return (LO<=other.GetLowerBound() && HI>=other.GetUpperBound());
00437 }

TimeSlice TimeSpan::GetAbsoluteTime double  current  )  const [inline]
 

Convert the relative time 'current' into an absolute value. Performs a linear interpolation on this timespans start and end times. Hence if 0<=current<=1 then the returned time will be somewhere within this time span.

Author:
Mike_Kenny (Xara Group Ltd) <camelotdev@xara.com>
Date:
17/03/97
Parameters:
A relative time to make absolute [INPUTS]
Returns:
An absolute time

Definition at line 494 of file timespan.cpp.

00495 {
00496     ERROR3IF(IsEmpty(),"TimeSpan::GetAbsoluteTime() called on an empty span");
00497     return (LO + (TimeSlice)(0.5+current*((double)(HI-LO))));
00498 }

TimeSlice TimeSpan::GetLowerBound  )  const [inline]
 

Dig out the lower bound of this TimeSpan object.

Author:
Mike_Kenny (Xara Group Ltd) <camelotdev@xara.com>
Date:
17/03/97
Parameters:
- [INPUTS]
Returns:
The lower bound of this TimeSpan object

Errors: Generates an error3 if this object is empty

Definition at line 198 of file timespan.cpp.

00199 { 
00200     ERROR3IF(IsEmpty(), "TimeSpan::GetLowerBound() called on an empty TimeSpan");
00201     return LO;
00202 }

double TimeSpan::GetRelativeTime TimeSlice  current  )  const [inline]
 

Convert the absolute time 'current' into a relative value. If the current value is within this time span then the double result will lie between 0 and 1, otherwise it will lie somewhere on the real line.

Author:
Mike_Kenny (Xara Group Ltd) <camelotdev@xara.com>
Date:
17/03/97
Parameters:
A current time to make relative [INPUTS]
Returns:
A relative time

Definition at line 473 of file timespan.cpp.

00474 {
00475     ERROR3IF(IsEmpty(),"TimeSpan::GetRelativeTime() called on an empty span");
00476     return ((double)(LO-current)) / ((double)(HI-LO));
00477 }

TimeSlice TimeSpan::GetUpperBound  )  const [inline]
 

Dig out the upper bound of this TimeSpan object. It should always be greater than or equal to the lower bound, otherwise this span is invalid.

Author:
Mike_Kenny (Xara Group Ltd) <camelotdev@xara.com>
Date:
17/03/97
Parameters:
- [INPUTS]
Returns:
The upper bound of this TimeSpan object

Errors: Generates an error3 if this object is invalid

Definition at line 225 of file timespan.cpp.

00226 {
00227     ERROR3IF(IsEmpty(), "TimeSpan::GetUpperBound() called on an empty TimeSpan");
00228     return HI; 
00229 }

TimeSlice TimeSpan::Hi  )  const [inline]
 

Definition at line 231 of file timespan.cpp.

00232 {
00233     ERROR3IF(IsEmpty(), "TimeSpan::Hi() called on an empty TimeSpan");
00234     return HI; 
00235 }

BOOL TimeSpan::InBounds TimeSlice  current  )  const
 

Checks whether the given time slice is within the bounds of this span.

Author:
Mike_Kenny (Xara Group Ltd) <camelotdev@xara.com>
Date:
17/03/97
Parameters:
A time slice [INPUTS]
Returns:
TRUE then current is within the bounds of this time span

Definition at line 406 of file timespan.cpp.

00407 {
00408     // Although Lo>Hi will return false always, lo==hi==current will return true
00409     // on an empty time span so check this.
00410     if (IsEmpty())
00411         return FALSE;
00412 
00413     return (LO<=current && current<=HI);
00414 }

void TimeSpan::Inflate TimeSlice  inflate  ) 
 

Inflates the bounds of this object by 'inflate'.

Author:
Mike_Kenny (Xara Group Ltd) <camelotdev@xara.com>
Date:
17/03/97
Parameters:
A reference to the inflation value [INPUTS]
Returns:
-

Definition at line 452 of file timespan.cpp.

00453 {
00454     ERROR3IF(IsEmpty(),"TimeSpan::Inflate() called on an empty span");
00455     LO-=inflate;
00456     HI+=inflate;
00457 }

TimeSpan TimeSpan::Intersection const TimeSpan other  )  const
 

Find the intersection of this span with 'other' span. If the intersection does not exist, either because one of the spans is empty or both spans are valid but they don't intersect then an empty timespan object is returned. Otherwise the intersection is returned.

Author:
Mike_Kenny (Xara Group Ltd) <camelotdev@xara.com>
Date:
17/03/97
Parameters:
other = a reference to another TimeSpan object [INPUTS]
Returns:
the intersection of the two time spans

Definition at line 363 of file timespan.cpp.

00364 {
00365     return (*this)-other;
00366 }

BOOL TimeSpan::IsEmpty  )  const [inline]
 

Check whether this time span object contains a non empty time frame. A time span becomes empty as a result of trying to perform boolean operations on time spans resulting in empty spans.

Author:
Mike_Kenny (Xara Group Ltd) <camelotdev@xara.com>
Date:
17/03/97
Parameters:
- [INPUTS]
Returns:
TRUE if this time span object is empty, i.e. it contains a lower and upper time such that lower>=upper. FALSE if these conditions are not met.

Definition at line 297 of file timespan.cpp.

00298 {
00299     return (LO>=HI);
00300 }

BOOL TimeSpan::IsIntersectedWith const TimeSpan other  )  const
 

Determine if this time span is intersected with the time span supplied.

Author:
Mike_Kenny (Xara Group Ltd) <camelotdev@xara.com>
Date:
17/03/97
Parameters:
other = a reference to another TimeSpan [INPUTS]
Returns:
TRUE if this time span does intersect with the 'other' time span
See also:
TimeSpan::Intersection()

Definition at line 381 of file timespan.cpp.

00382 {
00383     // both bounds must be valid for an intersection
00384     if (IsEmpty() || other.IsEmpty())
00385         return FALSE;
00386 
00387     // check for none intersection case
00388     TimeSlice lower = other.GetLowerBound();
00389     TimeSlice upper = other.GetUpperBound();
00390     return !(upper<LO || lower>HI);
00391 }

BOOL TimeSpan::IsSameAs const TimeSpan other  )  const
 

Check whether two TimeSpan objects are the same.

Author:
Mike_Kenny (Xara Group Ltd) <camelotdev@xara.com>
Date:
17/03/97
Parameters:
other = a reference to another TimeSpan object [INPUTS]
Returns:
TRUE if other contains the same time span as this and they are both none empty TRUE if other and this object are both empty FALSE if neither of these conditions hold

Definition at line 318 of file timespan.cpp.

00319 {
00320     BOOL same = (IsEmpty() == other.IsEmpty());
00321     if (!IsEmpty() && same)
00322     {   
00323         same = same && (LO == other.GetLowerBound());
00324         same = same && (HI == other.GetUpperBound());
00325     }
00326     return same;
00327 }

TimeSlice TimeSpan::Lo  )  const [inline]
 

Definition at line 204 of file timespan.cpp.

00205 { 
00206     ERROR3IF(IsEmpty(), "TimeSpan::Lo() called on an empty TimeSpan");
00207     return LO;
00208 }

void TimeSpan::MakeInvalid  )  [protected]
 

Set the lower and upper time span bounds to the view's now and the documents max time.Make this time span invalid.

Author:
Mike_Kenny (Xara Group Ltd) <camelotdev@xara.com>
Date:
17/03/97
Parameters:
- [INPUTS]

Definition at line 275 of file timespan.cpp.

00276 {
00277     LO=HI;
00278 }

TimeSpan TimeSpan::operator+ const TimeSpan other  )  const
 

Overload operator+ to perform a union opertion.

Author:
Mike_Kenny (Xara Group Ltd) <camelotdev@xara.com>
Date:
17/03/97
Parameters:
A reference to a rhs TimeSpan value to add to this time span [INPUTS]
Returns:
A new time span holding the result of the addition ( a union )

Definition at line 532 of file timespan.cpp.

00533 {
00534     // is this empty?
00535     if (IsEmpty())
00536         return other;
00537 
00538     if (other.IsEmpty())
00539         return (*this);
00540 
00541     // make a union out of the bounds
00542     TimeSlice lower = other.GetLowerBound();
00543     TimeSlice upper = other.GetUpperBound();
00544     if (LO<lower) lower=LO;
00545     if (HI>upper) upper=HI;
00546     
00547     return TimeSpan(lower,upper);
00548 }

TimeSpan TimeSpan::operator+ TimeSlice  value  )  const
 

Returns TimeSpanA = TimeSpanB + TimeSlice.

Author:
Mike_Kenny (Xara Group Ltd) <camelotdev@xara.com>
Date:
17/03/97
Parameters:
A reference to the TimeSlice value to add to both lower and upper bounds [INPUTS]
Returns:
The new shifted time span

Definition at line 514 of file timespan.cpp.

00515 {
00516     return TimeSpan(LO+value, HI+value);
00517 }

TimeSpan TimeSpan::operator- const TimeSpan other  )  const
 

Overload the operator- function to perform an intersection of two time spans returning the result in a new timespan.

Author:
Mike_Kenny (Xara Group Ltd) <camelotdev@xara.com>
Date:
17/03/97
Parameters:
A reference to a rhs TimeSpan value to subtract from this time span [INPUTS]
Returns:
The result of subtracting other from this

Definition at line 586 of file timespan.cpp.

00587 {
00588     // both bounds must be valid for an intersection
00589     if (IsEmpty() || other.IsEmpty())
00590         return (*this);
00591 
00592     // check for none intersection case
00593     TimeSlice lower = other.GetLowerBound();
00594     TimeSlice upper = other.GetUpperBound();
00595     if (upper<LO || lower>HI)
00596         return (*this);
00597 
00598     // make an intersection now we know the two actually do intersect
00599     if (HI<upper) upper=HI;
00600     if (LO>lower) lower=LO;
00601     
00602     return TimeSpan(lower,upper);
00603 }

TimeSpan TimeSpan::operator- TimeSlice  value  )  const
 

Subtracts 'value' from the bounds of this timespan and returns the result as a new time span.

Author:
Mike_Kenny (Xara Group Ltd) <camelotdev@xara.com>
Date:
17/03/97
Parameters:
A reference to the TimeSlice value to add to both lower and upper bounds [INPUTS]
Returns:
A resulting time span

Definition at line 567 of file timespan.cpp.

00568 {
00569     return TimeSpan(LO-value, HI-value);
00570 }

TimeSpan & TimeSpan::operator= const TimeSpan other  ) 
 

Assignment operator overload, assigns this time span with that of 'other' and returns a reference for further assignment.

Author:
Mike_Kenny (Xara Group Ltd) <camelotdev@xara.com>
Date:
17/03/97
Parameters:
A reference to another time span [INPUTS]
Returns:
A reference to this time span

Definition at line 620 of file timespan.cpp.

00621 {
00622     LO = other.GetLowerBound();
00623     HI = other.GetUpperBound();
00624     return (*this);
00625 }

BOOL TimeSpan::SetBounds TimeSlice  lower,
TimeSlice  upper
 

Set the bounds of this time span object. The bounds are always set in the object even if they are invalid.

Author:
Mike_Kenny (Xara Group Ltd) <camelotdev@xara.com>
Date:
17/03/97
Parameters:
lower = a lower bound time to inherit [INPUTS] upper = an upper bound time to inherit
Returns:
TRUE if the bounds we valid, FALSE if not. (invalid bounds means lower>=upper indicating an empty span)

Definition at line 176 of file timespan.cpp.

00177 {
00178     LO = lower;
00179     HI = upper;
00180     return (lower<upper);
00181 }

TimeSpan TimeSpan::Union const TimeSpan other  )  const
 

Find the union of this span with the other span. This union will always be valid if either or both spans are non empty.

Author:
Mike_Kenny (Xara Group Ltd) <camelotdev@xara.com>
Date:
17/03/97
Parameters:
other = a reference to another TimeSpan object [INPUTS]
Returns:
the union of the two time spans

Definition at line 343 of file timespan.cpp.

00344 {
00345     return (*this)+other;
00346 }


Member Data Documentation

TimeSlice TimeSpan::HI [private]
 

Definition at line 158 of file timespan.h.

TimeSlice TimeSpan::LO [private]
 

Definition at line 157 of file timespan.h.


The documentation for this class was generated from the following files:
Generated on Sat Nov 10 04:01:56 2007 for Camelot by  doxygen 1.4.4