Quick Links:

bal | bbl | bdl | bsl

Public Types | Public Member Functions | Friends

bdlt::Timetable Class Reference

#include <bdlt_timetable.h>

List of all members.

Public Types

enum  { k_UNSET_TRANSITION_CODE }
typedef Timetable_ConstIterator const_iterator

Public Member Functions

 Timetable (bslma::Allocator *basicAllocator=0)
 Timetable (const Date &firstDate, const Date &lastDate, int initialTransitionCode=k_UNSET_TRANSITION_CODE, bslma::Allocator *basicAllocator=0)
 Timetable (const Timetable &original, bslma::Allocator *basicAllocator=0)
 ~Timetable ()
Timetableoperator= (const Timetable &rhs)
void addTransition (const Date &date, const Time &time, int code)
void addTransition (const Datetime &datetime, int code)
void addTransitions (const DayOfWeek::Enum &dayOfWeek, const Time &time, int code, const Date &firstDate, const Date &lastDate)
void removeAllTransitions ()
void removeTransition (const Date &date, const Time &time)
void removeTransition (const Datetime &datetime)
void removeTransitions (const Date &date)
void removeTransitions (const DayOfWeek::Enum &dayOfWeek, const Time &time, const Date &firstDate, const Date &lastDate)
void reset ()
void setInitialTransitionCode (int code)
void setValidRange (const Date &firstDate, const Date &lastDate)
void swap (Timetable &other)
const_iterator begin () const
const_iterator end () const
const DatefirstDate () const
int initialTransitionCode () const
bool isInRange (const Date &date) const
const DatelastDate () const
int length () const
int transitionCodeInEffect (const Date &date, const Time &time) const
int transitionCodeInEffect (const Datetime &datetime) const
bslma::Allocatorallocator () const
bsl::ostream & print (bsl::ostream &stream, int level=0, int spacesPerLevel=4) const

Friends

class Timetable_ConstIterator
bool operator== (const Timetable &, const Timetable &)
bool operator!= (const Timetable &, const Timetable &)
template<class HASHALG >
void hashAppend (HASHALG &, const Timetable &)

Detailed Description

This class implements a value-semantic repository of datetime-indexed state transitions over a valid range of dates. This valid range, [firstDate() .. lastDate()], spans the first and last dates of a timetable's accessible contents. A timetable can be "populated" with state transitions via a suite of "add" methods. Note that the behavior of requesting any timetable information for a supplied date whose value is outside the current valid range for that timetable is undefined.

See Component bdlt_timetable


Member Typedef Documentation


Member Enumeration Documentation

anonymous enum
Enumerator:
k_UNSET_TRANSITION_CODE 

Constructor & Destructor Documentation

bdlt::Timetable::Timetable ( bslma::Allocator basicAllocator = 0  )  [explicit]

Create an empty Timetable (i.e., a timetable having no transitions) whose initial transition code is k_UNSET_TRANSITION_CODE. Optionally specify a basicAllocator used to supply memory. If basicAllocator is 0, the currently installed default allocator is used.

bdlt::Timetable::Timetable ( const Date firstDate,
const Date lastDate,
int  initialTransitionCode = k_UNSET_TRANSITION_CODE,
bslma::Allocator basicAllocator = 0 
)

Create a timetable having a valid range from the specified firstDate through the specified lastDate and having the optionally specified initialTransitionCode. If initialTransitionCode is not specified, the initial transition code is set to k_UNSET_TRANSITION_CODE. Optionally specify a basicAllocator used to supply memory. If basicAllocator is 0, the currently installed default allocator is used. The behavior is undefined unless firstDate <= lastDate, and 0 <= initialTransitionCode or k_UNSET_TRANSITION_CODE == initialTransitionCode.

bdlt::Timetable::Timetable ( const Timetable original,
bslma::Allocator basicAllocator = 0 
)

Create a timetable having the value of the specified original timetable. Optionally specify a basicAllocator used to supply memory. If basicAllocator is 0, the currently installed default allocator is used.

bdlt::Timetable::~Timetable (  ) 

Destroy this object.


Member Function Documentation

Timetable& bdlt::Timetable::operator= ( const Timetable rhs  ) 

Assign to this timetable the value of the specified rhs timetable, and return a reference providing modifiable access to this timetable. This operation invalidates all iterators.

void bdlt::Timetable::addTransition ( const Date date,
const Time time,
int  code 
)

Add a transition to this timetable on the specified date at the specified time having the specified code. If time is already a transition point on date, replace the existing code with code. The addition of a transition, but not the replacement of the code of an existing transition, invalidates all iterators. The behavior is undefined unless 24 > time.hour(), date is within the valid range of this timetable, and 0 <= code || k_UNSET_TRANSITION_CODE == code.

void bdlt::Timetable::addTransition ( const Datetime datetime,
int  code 
)

Add a transition to this timetable at the specified datetime having the specified code. If datetime is already a transition point, replace the existing code with code. The addition of a transition, but not the replacement of the code of an existing transition, invalidates all iterators. The behavior is undefined unless 24 > datetime.hour(), datetime.date() is within the valid range of this timetable, and 0 <= code || k_UNSET_TRANSITION_CODE == code.

void bdlt::Timetable::addTransitions ( const DayOfWeek::Enum dayOfWeek,
const Time time,
int  code,
const Date firstDate,
const Date lastDate 
)

Add transitions to this timetable that occur at the specified time, having the specified code, on all dates that are of the specified dayOfWeek within the closed interval of dates from the specified firstDate to the specified lastDate. For every date on which this transition will occur, if time is already a transition point, replace the existing code with code. The addition of a transition, but not the replacement of the code of an existing transition, invalidates all iterators. The behavior is undefined unless 24 > time.hour(), firstDate <= lastDate, firstDate and lastDate are within the valid range of this timetable, and 0 <= code || k_UNSET_TRANSITION_CODE == code.

void bdlt::Timetable::removeAllTransitions (  ) 

Remove all transitions from this timetable. The removal of a transition invalidates all iterators.

void bdlt::Timetable::removeTransition ( const Date date,
const Time time 
)

If a transition occurs on the specified date at the specified time, remove the transition from this timetable. Otherwise, return without modifying this timetable. The removal of a transition invalidates all iterators. The behavior is undefined unless 24 > time.hour() and date is within the valid range of this timetable.

void bdlt::Timetable::removeTransition ( const Datetime datetime  ) 

If a transition occurs at the specified datetime, remove the transition from this timetable. Otherwise, return without modifying this timetable. The removal of a transition invalidates all iterators. The behavior is undefined unless 24 > datetime.hour() and datetime.date() is within the valid range of this timetable.

void bdlt::Timetable::removeTransitions ( const Date date  ) 

Remove all transitions from this timetable that occur on the specified date. The removal of a transition invalidates all iterators. The behavior is undefined unless date is within the valid range of this timetable.

void bdlt::Timetable::removeTransitions ( const DayOfWeek::Enum dayOfWeek,
const Time time,
const Date firstDate,
const Date lastDate 
)

Remove all transitions from this timetable that occur at the specified time on all dates that are of the specified dayOfWeek within the closed interval of dates from the specified firstDate to the specified lastDate. The removal of a transition invalidates all iterators. The behavior is undefined unless 24 > time.hour(), firstDate <= lastDate, and firstDate and lastDate are within the valid range of this timetable.

void bdlt::Timetable::reset (  ) 

Reset this timetable to the default constructed (empty) state. All associated iterators are invalidated.

void bdlt::Timetable::setInitialTransitionCode ( int  code  ) 

Set the transition code in effect at the start of this timetable to the specified code. The behavior is undefined unless 0 <= code || k_UNSET_TRANSITION_CODE == code.

void bdlt::Timetable::setValidRange ( const Date firstDate,
const Date lastDate 
)

Set the range of this timetable using the specified firstDate and lastDate as, respectively, the first date and the last date of the timetable. Any transitions, and associated transition codes, that are outside of the new range are removed. The removal of a transition invalidates all iterators. The behavior is undefined unless firstDate <= lastDate.

void bdlt::Timetable::swap ( Timetable other  ) 

Efficiently exchange the value of this object with the value of the specified other object. This method provides the no-throw exception-safety guarantee. The behavior is undefined unless this object was created with the same allocator as other.

const_iterator bdlt::Timetable::begin (  )  const

Return an iterator referring to the first transition in this timetable, or the past-the-end iterator if this timetable is empty. The iterator remains valid as long as this timetable exists, and the number of transitions within this timetable does not change.

const_iterator bdlt::Timetable::end (  )  const

Return the past-the-end iterator for this timetable. The iterator remains valid as long as this timetable exists, and the number of transitions within this timetable does not change.

const Date& bdlt::Timetable::firstDate (  )  const

Return a const reference to the earliest date in the valid range of this timetable. The behavior is undefined if this timetable does not have a valid range (i.e., it is in the default constructed (empty) state).

int bdlt::Timetable::initialTransitionCode (  )  const

Return the transition code that is in effect at the start of this timetable (see setInitialTransitionCode).

bool bdlt::Timetable::isInRange ( const Date date  )  const

Return true if the specified date is within the valid range of this timetable, and false otherwise.

const Date& bdlt::Timetable::lastDate (  )  const

Return a const reference to the latest date in the valid range of this timetable. The behavior is undefined if this timetable does not have a valid range (i.e., it is in the default constructed (empty) state).

int bdlt::Timetable::length (  )  const

Return the number of days in the valid range of this timetable, which is defined to be 0 if this timetable is empty, and lastDate() - firstDate() + 1 otherwise.

int bdlt::Timetable::transitionCodeInEffect ( const Date date,
const Time time 
) const

Return the transition code associated with the latest transition that occurs on or before the specified date and time in this timetable. If this timetable has no such transition, return initialTransitionCode(). The behavior is undefined unless 24 > time.hour() and date is within the valid range of this timetable.

int bdlt::Timetable::transitionCodeInEffect ( const Datetime datetime  )  const

Return the transition code associated with the latest transition that occurs on or before the specified datetime in this timetable. If this timetable has no such transition, return initialTransitionCode(). The behavior is undefined unless 24 > datetime.hour() and datetime.date() is within the valid range of this timetable.

bslma::Allocator* bdlt::Timetable::allocator (  )  const

Return the allocator used by this object to supply memory.

bsl::ostream& bdlt::Timetable::print ( bsl::ostream &  stream,
int  level = 0,
int  spacesPerLevel = 4 
) const

Format this object to the specified output stream at the (absolute value of) the optionally specified indentation level and return a reference to the modifiable stream. If level is specified, optionally specify spacesPerLevel, the number of spaces per indentation level for this and all of its nested objects. If level is negative, suppress indentation of the first line. If spacesPerLevel is negative, format the entire output on one line, suppressing all but the initial indentation (as governed by level). If stream is not valid on entry, this operation has no effect.


Friends And Related Function Documentation

friend class Timetable_ConstIterator [friend]
bool operator== ( const Timetable ,
const Timetable  
) [friend]

Return true if the specified lhs and rhs timetables have the same value, and false otherwise. Two timetables have the same value if they have the same initial transition code, the same valid range (or are both empty), the same number of transitions, and each corresponding pair of transitions have the same value.

bool operator!= ( const Timetable ,
const Timetable  
) [friend]

Return true if the specified lhs and rhs timetables do not have the same value, and false otherwise. Two timetables do not have the same value if they do not have the same initial transition code, do not have the same valid range (and are not both empty), do not have the same number of transitions, or, for at least one corresponding pair of transitions, do not have the same value.

template<class HASHALG >
void hashAppend ( HASHALG &  ,
const Timetable  
) [friend]

Pass the specified object to the specified hashAlg. This function integrates with the bslh modular hashing system and effectively provides a bsl::hash specialization for Timetable.


The documentation for this class was generated from the following file: