annotate DEPENDENCIES/generic/include/boost/date_time/special_values_parser.hpp @ 133:4acb5d8d80b6 tip

Don't fail environmental check if README.md exists (but .txt and no-suffix don't)
author Chris Cannam
date Tue, 30 Jul 2019 12:25:44 +0100
parents 2665513ce2d3
children
rev   line source
Chris@16 1
Chris@16 2 #ifndef DATE_TIME_SPECIAL_VALUES_PARSER_HPP__
Chris@16 3 #define DATE_TIME_SPECIAL_VALUES_PARSER_HPP__
Chris@16 4
Chris@16 5 /* Copyright (c) 2005 CrystalClear Software, Inc.
Chris@16 6 * Use, modification and distribution is subject to the
Chris@16 7 * Boost Software License, Version 1.0. (See accompanying
Chris@16 8 * file LICENSE_1_0.txt or http://www.boost.org/LICENSE_1_0.txt)
Chris@16 9 * Author: Jeff Garland, Bart Garst
Chris@16 10 * $Date:
Chris@16 11 */
Chris@16 12
Chris@16 13
Chris@16 14 #include "boost/date_time/string_parse_tree.hpp"
Chris@16 15 #include "boost/date_time/special_defs.hpp"
Chris@16 16 #include <string>
Chris@16 17 #include <vector>
Chris@16 18
Chris@16 19 namespace boost { namespace date_time {
Chris@16 20
Chris@16 21 //! Class for special_value parsing
Chris@16 22 /*!
Chris@16 23 * TODO: add doc-comments for which elements can be changed
Chris@16 24 * Parses input stream for strings representing special_values.
Chris@16 25 * Special values parsed are:
Chris@16 26 * - not_a_date_time
Chris@16 27 * - neg_infin
Chris@16 28 * - pod_infin
Chris@16 29 * - min_date_time
Chris@16 30 * - max_date_time
Chris@16 31 */
Chris@16 32 template<class date_type, typename charT>
Chris@16 33 class special_values_parser
Chris@16 34 {
Chris@16 35 public:
Chris@16 36 typedef std::basic_string<charT> string_type;
Chris@16 37 //typedef std::basic_stringstream<charT> stringstream_type;
Chris@16 38 typedef std::istreambuf_iterator<charT> stream_itr_type;
Chris@16 39 //typedef typename string_type::const_iterator const_itr;
Chris@16 40 //typedef typename date_type::year_type year_type;
Chris@16 41 //typedef typename date_type::month_type month_type;
Chris@16 42 typedef typename date_type::duration_type duration_type;
Chris@16 43 //typedef typename date_type::day_of_week_type day_of_week_type;
Chris@16 44 //typedef typename date_type::day_type day_type;
Chris@16 45 typedef string_parse_tree<charT> parse_tree_type;
Chris@16 46 typedef typename parse_tree_type::parse_match_result_type match_results;
Chris@16 47 typedef std::vector<std::basic_string<charT> > collection_type;
Chris@16 48
Chris@16 49 typedef charT char_type;
Chris@16 50 static const char_type nadt_string[16];
Chris@16 51 static const char_type neg_inf_string[10];
Chris@16 52 static const char_type pos_inf_string[10];
Chris@16 53 static const char_type min_date_time_string[18];
Chris@16 54 static const char_type max_date_time_string[18];
Chris@16 55
Chris@16 56 //! Creates a special_values_parser with the default set of "sv_strings"
Chris@16 57 special_values_parser()
Chris@16 58 {
Chris@16 59 sv_strings(string_type(nadt_string),
Chris@16 60 string_type(neg_inf_string),
Chris@16 61 string_type(pos_inf_string),
Chris@16 62 string_type(min_date_time_string),
Chris@16 63 string_type(max_date_time_string));
Chris@16 64 }
Chris@16 65
Chris@16 66 //! Creates a special_values_parser using a user defined set of element strings
Chris@16 67 special_values_parser(const string_type& nadt_str,
Chris@16 68 const string_type& neg_inf_str,
Chris@16 69 const string_type& pos_inf_str,
Chris@16 70 const string_type& min_dt_str,
Chris@16 71 const string_type& max_dt_str)
Chris@16 72 {
Chris@16 73 sv_strings(nadt_str, neg_inf_str, pos_inf_str, min_dt_str, max_dt_str);
Chris@16 74 }
Chris@16 75
Chris@16 76 special_values_parser(typename collection_type::iterator beg, typename collection_type::iterator end)
Chris@16 77 {
Chris@16 78 collection_type phrases;
Chris@16 79 std::copy(beg, end, std::back_inserter(phrases));
Chris@16 80 m_sv_strings = parse_tree_type(phrases, static_cast<int>(not_a_date_time));
Chris@16 81 }
Chris@16 82
Chris@16 83 special_values_parser(const special_values_parser<date_type,charT>& svp)
Chris@16 84 {
Chris@16 85 this->m_sv_strings = svp.m_sv_strings;
Chris@16 86 }
Chris@16 87
Chris@16 88 //! Replace special value strings
Chris@16 89 void sv_strings(const string_type& nadt_str,
Chris@16 90 const string_type& neg_inf_str,
Chris@16 91 const string_type& pos_inf_str,
Chris@16 92 const string_type& min_dt_str,
Chris@16 93 const string_type& max_dt_str)
Chris@16 94 {
Chris@16 95 collection_type phrases;
Chris@16 96 phrases.push_back(nadt_str);
Chris@16 97 phrases.push_back(neg_inf_str);
Chris@16 98 phrases.push_back(pos_inf_str);
Chris@16 99 phrases.push_back(min_dt_str);
Chris@16 100 phrases.push_back(max_dt_str);
Chris@16 101 m_sv_strings = parse_tree_type(phrases, static_cast<int>(not_a_date_time));
Chris@16 102 }
Chris@16 103
Chris@16 104 /* Does not return a special_value because if the parsing fails,
Chris@16 105 * the return value will always be not_a_date_time
Chris@16 106 * (mr.current_match retains its default value of -1 on a failed
Chris@16 107 * parse and that casts to not_a_date_time). */
Chris@16 108 //! Sets match_results.current_match to the corresponding special_value or -1
Chris@16 109 bool match(stream_itr_type& sitr,
Chris@16 110 stream_itr_type& str_end,
Chris@16 111 match_results& mr) const
Chris@16 112 {
Chris@16 113 unsigned int level = 0;
Chris@16 114 m_sv_strings.match(sitr, str_end, mr, level);
Chris@16 115 return (mr.current_match != match_results::PARSE_ERROR);
Chris@16 116 }
Chris@16 117 /*special_values match(stream_itr_type& sitr,
Chris@16 118 stream_itr_type& str_end,
Chris@16 119 match_results& mr) const
Chris@16 120 {
Chris@16 121 unsigned int level = 0;
Chris@16 122 m_sv_strings.match(sitr, str_end, mr, level);
Chris@16 123 if(mr.current_match == match_results::PARSE_ERROR) {
Chris@16 124 throw std::ios_base::failure("Parse failed. No match found for '" + mr.cache + "'");
Chris@16 125 }
Chris@16 126 return static_cast<special_values>(mr.current_match);
Chris@16 127 }*/
Chris@16 128
Chris@16 129
Chris@16 130 private:
Chris@16 131 parse_tree_type m_sv_strings;
Chris@16 132
Chris@16 133 };
Chris@16 134
Chris@16 135 template<class date_type, class CharT>
Chris@16 136 const typename special_values_parser<date_type, CharT>::char_type
Chris@16 137 special_values_parser<date_type, CharT>::nadt_string[16] =
Chris@16 138 {'n','o','t','-','a','-','d','a','t','e','-','t','i','m','e'};
Chris@16 139 template<class date_type, class CharT>
Chris@16 140 const typename special_values_parser<date_type, CharT>::char_type
Chris@16 141 special_values_parser<date_type, CharT>::neg_inf_string[10] =
Chris@16 142 {'-','i','n','f','i','n','i','t','y'};
Chris@16 143 template<class date_type, class CharT>
Chris@16 144 const typename special_values_parser<date_type, CharT>::char_type
Chris@16 145 special_values_parser<date_type, CharT>::pos_inf_string[10] =
Chris@16 146 {'+','i','n','f','i','n','i','t','y'};
Chris@16 147 template<class date_type, class CharT>
Chris@16 148 const typename special_values_parser<date_type, CharT>::char_type
Chris@16 149 special_values_parser<date_type, CharT>::min_date_time_string[18] =
Chris@16 150 {'m','i','n','i','m','u','m','-','d','a','t','e','-','t','i','m','e'};
Chris@16 151 template<class date_type, class CharT>
Chris@16 152 const typename special_values_parser<date_type, CharT>::char_type
Chris@16 153 special_values_parser<date_type, CharT>::max_date_time_string[18] =
Chris@16 154 {'m','a','x','i','m','u','m','-','d','a','t','e','-','t','i','m','e'};
Chris@16 155
Chris@16 156 } } //namespace
Chris@16 157
Chris@16 158 #endif // DATE_TIME_SPECIAL_VALUES_PARSER_HPP__
Chris@16 159