Quick Links: |
Provide a repository for accessing timetable information. More...
Namespaces | |
namespace | bdlt |
bdlt::Timetable | repository for accessing timetable information |
bdlt::TimetableTransition | datetime and transition code value |
bdlt::Timetable
, that represents a timetable of state transitions over a valid range of dates, an associated iterator, bdlt::Timetable::const_iterator
, that provides non-modifiable access to the timetable's state transitions, and a class, bdlt::TimetableTransition
, that represents a change of state at a datetime. bdlt::Timetable
is designed to be especially efficient at determining the state in effect at a given bdlt::Datetime
value (within the valid range for a particular bdlt::Timetable
object), and iterating through the state transitions. bdlt::TimetableTransition
consists of a bdlt::Datetime
and a (single) non-negative integral code (of type int
) that defines the "state" that becomes effective at that datetime. The meaning of the integral code ascribed to each transition is defined by the client. There can be at most one bdlt::TimetableTransition
defined for any datetime value within the range of a bdlt::Timetable
. Consequently, there is at most one (client-defined) state in effect at any datetime in a timetable. setValidRange
method modifies the valid range of a timetable, and a suite of "add" methods can be used to populate a timetable with state transitions. bdlt::Timetable
are exception-safe, but in general provide only the basic guarantee (i.e., no guarantee of rollback): If an exception occurs (i.e., while attempting to allocate memory), the timetable object is left in a coherent state, but (unless otherwise specified) its value is undefined. bdlt::TimetableTransition
are exception-safe. bdlt::Timetable
to efficiently store this data. bdlt::Timetable
with the desired valid range: bdlt::Timetable timetable(bdlt::Date(2018, 1, 1), bdlt::Date(2018, 12, 31));
const int k_TRADING = 0; const int k_NO_TRADING = 1; timetable.setInitialTransitionCode(k_NO_TRADING); for (int i = 0; i < 5; ++ i) { timetable.addTransitions(static_cast<bdlt::DayOfWeek::Enum>( bdlt::DayOfWeek::e_MON + i), bdlt::Time(8, 30), k_TRADING, timetable.firstDate(), timetable.lastDate()); timetable.addTransitions(static_cast<bdlt::DayOfWeek::Enum>( bdlt::DayOfWeek::e_MON + i), bdlt::Time(16, 30), k_NO_TRADING, timetable.firstDate(), timetable.lastDate()); }
timetable.removeTransitions(bdlt::Date(2018, 1, 19));
timetable.addTransition(bdlt::Datetime(2018, 11, 23, 12, 30), k_NO_TRADING); timetable.removeTransition(bdlt::Datetime(2018, 11, 23, 16, 30));
assert(k_NO_TRADING == timetable.transitionCodeInEffect( bdlt::Datetime(2018, 1, 15, 8, 0))); assert(k_TRADING == timetable.transitionCodeInEffect( bdlt::Datetime(2018, 1, 15, 8, 30))); assert(k_TRADING == timetable.transitionCodeInEffect( bdlt::Datetime(2018, 1, 15, 16, 0))); assert(k_NO_TRADING == timetable.transitionCodeInEffect( bdlt::Datetime(2018, 1, 15, 16, 30))); assert(k_NO_TRADING == timetable.transitionCodeInEffect( bdlt::Datetime(2018, 11, 23, 8, 0))); assert(k_TRADING == timetable.transitionCodeInEffect( bdlt::Datetime(2018, 11, 23, 8, 30))); assert(k_TRADING == timetable.transitionCodeInEffect( bdlt::Datetime(2018, 11, 23, 12, 0))); assert(k_NO_TRADING == timetable.transitionCodeInEffect( bdlt::Datetime(2018, 11, 23, 12, 30)));