| Home | Libraries | People | FAQ | More

## Class template date_generator_parser

boost::date_time::date_generator_parser — Class for date_generator parsing.

## Synopsis

    // In header: <boost/date_time/date_generator_parser.hpp>

    template<typename date_type, typename charT>
    class date_generator_parser {
    public:
      // types
      typedef std::basic_string< charT >                string_type;
      typedef std::istreambuf_iterator< charT >         stream_itr_type;
      typedef date_type::month_type                     month_type;
      typedef date_type::day_of_week_type               day_of_week_type;
      typedef date_type::day_type                       day_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;
      typedef partial_date< date_type >                 partial_date_type;
      typedef nth_kday_of_month< date_type >            nth_kday_type;
      typedef first_kday_of_month< date_type >          first_kday_type;
      typedef last_kday_of_month< date_type >           last_kday_type;
      typedef first_kday_after< date_type >             kday_after_type;
      typedef first_kday_before< date_type >            kday_before_type;
      typedef charT                                     char_type;

      enum phrase_elements { first = 0, second, third, fourth, fifth, last,
                             before, after, of, number_of_phrase_elements };

      // construct/copy/destruct
      date_generator_parser();
      date_generator_parser(const string_type &, const string_type &,
                            const string_type &, const string_type &,
                            const string_type &, const string_type &,
                            const string_type &, const string_type &,
                            const string_type &);

      // public member functions
      void element_strings(const string_type &, const string_type &,
                           const string_type &, const string_type &,
                           const string_type &, const string_type &,
                           const string_type &, const string_type &,
                           const string_type &);
      void element_strings(const collection_type &);
      template<typename facet_type>
        partial_date_type
        get_partial_date_type(stream_itr_type &, stream_itr_type &,
                              std::ios_base &, const facet_type &) const;
      template<typename facet_type>
        nth_kday_type
        get_nth_kday_type(stream_itr_type &, stream_itr_type &, std::ios_base &,
                          const facet_type &) const;
      template<typename facet_type>
        first_kday_type
        get_first_kday_type(stream_itr_type &, stream_itr_type &, std::ios_base &,
                            const facet_type &) const;
      template<typename facet_type>
        last_kday_type
        get_last_kday_type(stream_itr_type &, stream_itr_type &, std::ios_base &,
                           const facet_type &) const;
      template<typename facet_type>
        kday_before_type
        get_kday_before_type(stream_itr_type &, stream_itr_type &,
                             std::ios_base &, const facet_type &) const;
      template<typename facet_type>
        kday_after_type
        get_kday_after_type(stream_itr_type &, stream_itr_type &, std::ios_base &,
                            const facet_type &) const;

      // private member functions
      void extract_element(stream_itr_type &, stream_itr_type &,
                           typename date_generator_parser::phrase_elements) const;
      static const char_type first_string;
      static const char_type second_string;
      static const char_type third_string;
      static const char_type fourth_string;
      static const char_type fifth_string;
      static const char_type last_string;
      static const char_type before_string;
      static const char_type after_string;
      static const char_type of_string;
    };

## Description

The elements of a date_generator "phrase" are parsed from the input stream in a particular order. All elements are required and the order in which they appear cannot change, however, the elements themselves can be changed. The default elements and their order are as follows:

- partial_date => "dd Month"

- nth_day_of_the_week_in_month => "nth weekday of month"

- first_day_of_the_week_in_month => "first weekday of month"

- last_day_of_the_week_in_month => "last weekday of month"

- first_day_of_the_week_after => "weekday after"

- first_day_of_the_week_before => "weekday before"

Weekday and Month names and formats are handled via the date_input_facet.

### `date_generator_parser` public construct/copy/destruct

1.     date_generator_parser();

   Creates a date_generator_parser with the default set of "element_strings".

2.     date_generator_parser(const string_type & first_str,
                             const string_type & second_str,
                             const string_type & third_str,
                             const string_type & fourth_str,
                             const string_type & fifth_str,
                             const string_type & last_str,
                             const string_type & before_str,
                             const string_type & after_str,
                             const string_type & of_str);

   Creates a date_generator_parser using a user defined set of element strings.

### `date_generator_parser` public member functions

1.     void element_strings(const string_type & first_str,
                            const string_type & second_str,
                            const string_type & third_str,
                            const string_type & fourth_str,
                            const string_type & fifth_str,
                            const string_type & last_str,
                            const string_type & before_str,
                            const string_type & after_str,
                            const string_type & of_str);

   Replace strings that determine nth week for generator.

2.     void element_strings(const collection_type & col);

3.     template<typename facet_type>
         partial_date_type
         get_partial_date_type(stream_itr_type & sitr, stream_itr_type & stream_end,
                               std::ios_base & a_ios, const facet_type & facet) const;

   returns partial_date parsed from stream

4.     template<typename facet_type>
         nth_kday_type
         get_nth_kday_type(stream_itr_type & sitr, stream_itr_type & stream_end,
                           std::ios_base & a_ios, const facet_type & facet) const;

   returns nth_kday_of_week parsed from stream

5.     template<typename facet_type>
         first_kday_type
         get_first_kday_type(stream_itr_type & sitr, stream_itr_type & stream_end,
                             std::ios_base & a_ios, const facet_type & facet) const;

   returns first_kday_of_week parsed from stream

6.     template<typename facet_type>
         last_kday_type
         get_last_kday_type(stream_itr_type & sitr, stream_itr_type & stream_end,
                            std::ios_base & a_ios, const facet_type & facet) const;

   returns last_kday_of_week parsed from stream

7.     template<typename facet_type>
         kday_before_type
         get_kday_before_type(stream_itr_type & sitr, stream_itr_type & stream_end,
                              std::ios_base & a_ios, const facet_type & facet) const;

   returns first_kday_of_week parsed from stream

8.     template<typename facet_type>
         kday_after_type
         get_kday_after_type(stream_itr_type & sitr, stream_itr_type & stream_end,
                             std::ios_base & a_ios, const facet_type & facet) const;

   returns first_kday_of_week parsed from stream

### `date_generator_parser` private member functions

1.     void extract_element(stream_itr_type & sitr, stream_itr_type & stream_end,
                            typename date_generator_parser::phrase_elements ele) const;

   Extracts phrase element from input. Throws ios_base::failure on error.