BDE 4.14.0 Production release
|
Provide a repository for accessing timetable information.
This component provides a value-semantic class, 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.
Default-constructed timetables are empty, and have an empty valid range. Timetables can also be constructed with an initial (non-empty) valid range. The 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.
Timetables are value-semantic objects, and, as such, necessarily support all of the standard value-semantic operations, such as default construction, copy construction and copy assignment, and equality comparison.
All methods of 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.
All methods of bdlt::TimetableTransition
are exception-safe.
This section illustrates intended use of this component.
Suppose we want to track the open and close times for an exchange. Most Mondays (and Tuesdays, Wednesdays, etc.) will have the same schedule, although some may differ. We can use bdlt::Timetable
to efficiently store this data.
First, we create an instance of bdlt::Timetable
with the desired valid range:
Then, we define the codes for start-of-trading and end-of-trading and populate the typical transitions into the timetable:
Next, we add a holiday on January 19, 2018:
Then, we add a half-day on November 23, 2018:
Finally, we verify the transition code in effect at a few datetimes.