Boost  v1.57.0
doxygen for www.boost.org
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
boost::date_time::period< point_rep, duration_rep > Class Template Reference

Provides generalized period type useful in date-time systems. More...

#include <period.hpp>

Inheritance diagram for boost::date_time::period< point_rep, duration_rep >:
Collaboration diagram for boost::date_time::period< point_rep, duration_rep >:

Public Types

typedef point_rep point_type
 
typedef duration_rep duration_type
 

Public Member Functions

 period (point_rep first_point, point_rep end_point)
 create a period from begin to last eg: [begin,end) More...
 
 period (point_rep first_point, duration_rep len)
 create a period as [begin, begin+len) More...
 
point_rep begin () const
 Return the first element in the period. More...
 
point_rep end () const
 Return one past the last element. More...
 
point_rep last () const
 Return the last item in the period. More...
 
duration_rep length () const
 Return the length of the period. More...
 
bool is_null () const
 True if period is ill formed (length is zero or less) More...
 
bool operator== (const period &rhs) const
 Equality operator. More...
 
bool operator< (const period &rhs) const
 Strict as defined by rhs.last <= lhs.last. More...
 
void shift (const duration_rep &d)
 Shift the start and end by the specified amount. More...
 
void expand (const duration_rep &d)
 Expands the size of the period by the duration on both ends. More...
 
bool contains (const point_rep &point) const
 True if the point is inside the period, zero length periods contain no points. More...
 
bool contains (const period &other) const
 True if this period fully contains (or equals) the other period. More...
 
bool intersects (const period &other) const
 True if the periods overlap in any way. More...
 
bool is_adjacent (const period &other) const
 True if periods are next to each other without a gap. More...
 
bool is_before (const point_rep &point) const
 True if all of the period is prior to the passed point or end <= t. More...
 
bool is_after (const point_rep &point) const
 True if all of the period is prior or t < start. More...
 
period intersection (const period &other) const
 Returns the period of intersection or invalid range no intersection. More...
 
period merge (const period &other) const
 Returns the union of intersecting periods – or null period. More...
 
period span (const period &other) const
 Combine two periods with earliest start and latest end. More...
 

Detailed Description

template<class point_rep, class duration_rep>
class boost::date_time::period< point_rep, duration_rep >

Provides generalized period type useful in date-time systems.

This template uses a class to represent a time point within the period and another class to represent a duration. As a result, this class is not appropriate for use when the number and duration representation are the same (eg: in the regular number domain).

A period can be specified by providing either the begining point and a duration or the begining point and the end point( end is NOT part of the period but 1 unit past it. A period will be "invalid" if either end_point <= begin_point or the given duration is <= 0. Any valid period will return false for is_null().

Zero length periods are also considered invalid. Zero length periods are periods where the begining and end points are the same, or, the given duration is zero. For a zero length period, the last point will be one unit less than the begining point.

In the case that the begin and last are the same, the period has a length of one unit.

The best way to handle periods is usually to provide a begining point and a duration. So, day1 + 7 days is a week period which includes all of the first day and 6 more days (eg: Sun to Sat).

Member Typedef Documentation

template<class point_rep, class duration_rep>
typedef duration_rep boost::date_time::period< point_rep, duration_rep >::duration_type
template<class point_rep, class duration_rep>
typedef point_rep boost::date_time::period< point_rep, duration_rep >::point_type

Constructor & Destructor Documentation

template<class point_rep , class duration_rep >
boost::date_time::period< point_rep, duration_rep >::period ( point_rep  first_point,
point_rep  end_point 
)
inline

create a period from begin to last eg: [begin,end)

If end <= begin then the period will be invalid

template<class point_rep , class duration_rep >
boost::date_time::period< point_rep, duration_rep >::period ( point_rep  first_point,
duration_rep  len 
)
inline

create a period as [begin, begin+len)

If len is <= 0 then the period will be invalid

Member Function Documentation

template<class point_rep , class duration_rep >
bool boost::date_time::period< point_rep, duration_rep >::contains ( const point_rep &  point) const
inline

True if the point is inside the period, zero length periods contain no points.

References boost::msm::front::euml::begin_.

Referenced by boost::date_time::period< point_rep, duration_rep >::intersects().

template<class point_rep , class duration_rep >
bool boost::date_time::period< point_rep, duration_rep >::contains ( const period< point_rep, duration_rep > &  other) const
inline

True if this period fully contains (or equals) the other period.

References boost::msm::front::euml::begin_.

template<class point_rep , class duration_rep >
void boost::date_time::period< point_rep, duration_rep >::expand ( const duration_rep &  d)
inline

Expands the size of the period by the duration on both ends.

So before expand

[-------]
^ ^ ^ ^ ^ ^ ^
1 2 3 4 5 6 7

After expand(2)

[----------------------]
^ ^ ^ ^ ^ ^ ^
1 2 3 4 5 6 7

References boost::msm::front::euml::begin_.

template<class point_rep , class duration_rep >
period< point_rep, duration_rep > boost::date_time::period< point_rep, duration_rep >::intersection ( const period< point_rep, duration_rep > &  other) const
inline

Returns the period of intersection or invalid range no intersection.

References boost::msm::front::euml::begin_, boost::date_time::period< point_rep, duration_rep >::end(), boost::end, and boost::spirit::x3::unicode::other.

template<class point_rep , class duration_rep >
bool boost::date_time::period< point_rep, duration_rep >::intersects ( const period< point_rep, duration_rep > &  other) const
inline
template<class point_rep , class duration_rep >
bool boost::date_time::period< point_rep, duration_rep >::is_adjacent ( const period< point_rep, duration_rep > &  other) const
inline
template<class point_rep , class duration_rep >
bool boost::date_time::period< point_rep, duration_rep >::is_after ( const point_rep &  point) const
inline

True if all of the period is prior or t < start.

References boost::msm::front::euml::begin_, and boost::is_null().

template<class point_rep , class duration_rep >
bool boost::date_time::period< point_rep, duration_rep >::is_before ( const point_rep &  point) const
inline

True if all of the period is prior to the passed point or end <= t.

References boost::is_null(), and boost::flyweights::t.

template<class point_rep , class duration_rep >
bool boost::date_time::period< point_rep, duration_rep >::is_null ( ) const
inline

True if period is ill formed (length is zero or less)

References boost::msm::front::euml::begin_, and boost::end.

template<class point_rep , class duration_rep >
point_rep boost::date_time::period< point_rep, duration_rep >::last ( ) const
inline
template<class point_rep , class duration_rep >
duration_rep boost::date_time::period< point_rep, duration_rep >::length ( ) const
inline

Return the length of the period.

References boost::msm::front::euml::begin_, and boost::end.

template<class point_rep , class duration_rep >
period< point_rep, duration_rep > boost::date_time::period< point_rep, duration_rep >::merge ( const period< point_rep, duration_rep > &  other) const
inline

Returns the union of intersecting periods – or null period.

References boost::msm::front::euml::begin_, boost::date_time::period< point_rep, duration_rep >::end(), boost::end, and boost::intersects().

template<class point_rep , class duration_rep >
bool boost::date_time::period< point_rep, duration_rep >::operator< ( const period< point_rep, duration_rep > &  rhs) const
inline

Strict as defined by rhs.last <= lhs.last.

template<class point_rep , class duration_rep >
bool boost::date_time::period< point_rep, duration_rep >::operator== ( const period< point_rep, duration_rep > &  rhs) const
inline

Equality operator.

References boost::msm::front::euml::begin_.

template<class point_rep , class duration_rep >
void boost::date_time::period< point_rep, duration_rep >::shift ( const duration_rep &  d)
inline

Shift the start and end by the specified amount.

References boost::msm::front::euml::begin_.

template<class point_rep , class duration_rep >
period< point_rep, duration_rep > boost::date_time::period< point_rep, duration_rep >::span ( const period< point_rep, duration_rep > &  other) const
inline

Combine two periods with earliest start and latest end.

Combines two periods and any gap between them such that start = min(p1.start, p2.start) end = max(p1.end , p2.end)

[---p1---)
[---p2---)
[-----------p3----------)

References boost::date_time::period< point_rep, duration_rep >::begin(), boost::asio::begin, boost::msm::front::euml::begin_, boost::date_time::period< point_rep, duration_rep >::end(), and boost::end.


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