| Home | Libraries | People | FAQ | More

## Struct template string_parse_tree

boost::date_time::string_parse_tree — Recursive data structure to allow efficient parsing of various strings.

## Synopsis

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

    template<typename charT>
    struct string_parse_tree {
      // types
      typedef std::multimap< charT, string_parse_tree< charT > > ptree_coll;
      typedef std::multimap< charT, string_parse_tree >          ptree_coll;
      typedef ptree_coll::value_type                             value_type;
      typedef ptree_coll::iterator                               iterator;
      typedef ptree_coll::const_iterator                         const_iterator;
      typedef std::basic_string< charT >                         string_type;
      typedef std::vector< std::basic_string< charT > >          collection_type;
      typedef parse_match_result< charT >                        parse_match_result_type;

      // construct/copy/destruct
      string_parse_tree(collection_type, unsigned int = 0);
      string_parse_tree(short = -1);

      // public member functions
      void insert(const string_type &, unsigned short) ;
      short match(std::istreambuf_iterator< charT > &,
                  std::istreambuf_iterator< charT > &, parse_match_result_type &,
                  unsigned int &) const;
      parse_match_result_type
      match(std::istreambuf_iterator< charT > &,
            std::istreambuf_iterator< charT > &) const;
      void printme(std::ostream &, int &) ;
      void print(std::ostream &) ;
      void printmatch(std::ostream &, charT) ;
      ptree_coll m_next_chars;
      short m_value;
    };

## Description

This class provides a quick lookup by building what amounts to a tree data structure. It also features a match function which can can handle nasty input interators by caching values as it recurses the tree so that it can backtrack as needed.

### `string_parse_tree` public construct/copy/destruct

1.     string_parse_tree(collection_type names, unsigned int starting_point = 0);

   Parameter "starting_point" designates where the numbering begins. A starting_point of zero will start the numbering at zero (Sun=0, Mon=1, ...) were a starting_point of one starts the numbering at one (Jan=1, Feb=2, ...). The default is zero, negative vaules are not allowed

2.     string_parse_tree(short value = -1);

### `string_parse_tree` public member functions

1.     void insert(const string_type & s, unsigned short value) ;

2.     short match(std::istreambuf_iterator< charT > & sitr,
                   std::istreambuf_iterator< charT > & stream_end,
                   parse_match_result_type & result, unsigned int & level) const;

   Recursive function that finds a matching string in the tree.

   Must check match_results::has_remaining() after match() is called. This is required so the user can determine if stream iterator is already pointing to the expected character or not (match() might advance sitr to next char in stream).

   A parse_match_result that has been returned from a failed match attempt can be sent in to the match function of a different string_parse_tree to attempt a match there. Use the iterators for the partially consumed stream, the parse_match_result object, and '0' for the level parameter.

3.     parse_match_result_type
       match(std::istreambuf_iterator< charT > & sitr,
             std::istreambuf_iterator< charT > & stream_end) const;

   Must check match_results::has_remaining() after match() is called. This is required so the user can determine if stream iterator is already pointing to the expected character or not (match() might advance sitr to next char in stream).

4.     void printme(std::ostream & os, int & level) ;

5.     void print(std::ostream & os) ;

6.     void printmatch(std::ostream & os, charT c) ;