Home | Libraries | People | FAQ | More |
boost::date_time::period_parser — Not a facet, but a class used to specify and control period parsing.
// In header: <boost/date_time/period_parser.hpp> template<typename date_type, typename CharT> class period_parser { public: // types typedef std::basic_string< CharT > string_type; typedef CharT char_type; typedef std::istreambuf_iterator< CharT > stream_itr_type; typedef string_parse_tree< CharT > parse_tree_type; typedef parse_tree_type::parse_match_result_type match_results; typedef std::vector< std::basic_string< CharT > > collection_type; enum period_range_option { AS_OPEN_RANGE, AS_CLOSED_RANGE }; // construct/copy/destruct period_parser(period_range_option = AS_CLOSED_RANGE, const char_type *const = default_period_separator, const char_type *const = default_period_start_delimeter, const char_type *const = default_period_open_range_end_delimeter, const char_type *const = default_period_closed_range_end_delimeter); period_parser(const period_parser< date_type, CharT > &); // public member functions period_range_option range_option() const; void range_option(period_range_option); collection_type delimiter_strings() const; void delimiter_strings(const string_type &, const string_type &, const string_type &, const string_type &); template<typename period_type, typename duration_type, typename facet_type> period_type get_period(stream_itr_type &, stream_itr_type &, std::ios_base &, const period_type &, const duration_type &, const facet_type &) const; // private member functions void consume_delim(stream_itr_type &, stream_itr_type &, const string_type &) const; // public data members static const char_type default_period_separator; static const char_type default_period_start_delimeter; static const char_type default_period_open_range_end_delimeter; static const char_type default_period_closed_range_end_delimeter; };
Provides settings for the following:
period_separator -- default '/'
period_open_start_delimeter -- default '['
period_open_range_end_delimeter -- default ')'
period_closed_range_end_delimeter -- default ']'
display_as_open_range, display_as_closed_range -- default closed_range
For a typical date_period, the contents of the input stream would be
[2004-Jan-04/2004-Feb-01] *
where the date format is controlled by the date facet
period_parser
public
construct/copy/destructperiod_parser(period_range_option range_opt = AS_CLOSED_RANGE, const char_type *const period_separator = default_period_separator, const char_type *const period_start_delimeter = default_period_start_delimeter, const char_type *const period_open_range_end_delimeter = default_period_open_range_end_delimeter, const char_type *const period_closed_range_end_delimeter = default_period_closed_range_end_delimeter);Constructor that sets up period parser options.
period_parser(const period_parser< date_type, CharT > & p_parser);
period_parser
public member functionsperiod_range_option range_option() const;
void range_option(period_range_option option);
collection_type delimiter_strings() const;
void delimiter_strings(const string_type & separator, const string_type & start_delim, const string_type & open_end_delim, const string_type & closed_end_delim);
template<typename period_type, typename duration_type, typename facet_type> period_type get_period(stream_itr_type & sitr, stream_itr_type & stream_end, std::ios_base & a_ios, const period_type &, const duration_type & dur_unit, const facet_type & facet) const;Generic code to parse a period -- no matter the period type.
This generic code will parse any period using a facet to to get the 'elements'. For example, in the case of a date_period the elements will be instances of a date which will be parsed according the to setup in the passed facet parameter.
The steps for parsing a period are always the same:
consume the start delimiter
get start element
consume the separator
get either last or end element depending on range settings
consume the end delimeter depending on range settings
Thus for a typical date period the contents of the input stream might look like this:
[March 01, 2004/June 07, 2004] <-- closed range [March 01, 2004/June 08, 2004) <-- open range *