annotate DEPENDENCIES/generic/include/boost/date_time/special_values_formatter.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 c530137014c0
children
rev   line source
Chris@16 1
Chris@16 2 #ifndef DATETIME_SPECIAL_VALUE_FORMATTER_HPP___
Chris@16 3 #define DATETIME_SPECIAL_VALUE_FORMATTER_HPP___
Chris@16 4
Chris@16 5 /* Copyright (c) 2004 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
Chris@101 10 * $Date$
Chris@16 11 */
Chris@16 12
Chris@16 13 #include <vector>
Chris@16 14 #include <string>
Chris@16 15 #include "boost/date_time/special_defs.hpp"
Chris@16 16
Chris@16 17 namespace boost { namespace date_time {
Chris@16 18
Chris@16 19
Chris@16 20 //! Class that provides generic formmatting ostream formatting for special values
Chris@16 21 /*! This class provides for the formmating of special values to an output stream.
Chris@16 22 * In particular, it produces strings for the values of negative and positive
Chris@16 23 * infinity as well as not_a_date_time.
Chris@16 24 *
Chris@16 25 * While not a facet, this class is used by the date and time facets for formatting
Chris@16 26 * special value types.
Chris@16 27 *
Chris@16 28 */
Chris@16 29 template <class CharT, class OutItrT = std::ostreambuf_iterator<CharT, std::char_traits<CharT> > >
Chris@16 30 class special_values_formatter
Chris@16 31 {
Chris@16 32 public:
Chris@16 33 typedef std::basic_string<CharT> string_type;
Chris@16 34 typedef CharT char_type;
Chris@16 35 typedef std::vector<string_type> collection_type;
Chris@16 36 static const char_type default_special_value_names[3][17];
Chris@16 37
Chris@16 38 //! Construct special values formatter using default strings.
Chris@16 39 /*! Default strings are not-a-date-time -infinity +infinity
Chris@16 40 */
Chris@16 41 special_values_formatter()
Chris@16 42 {
Chris@16 43 std::copy(&default_special_value_names[0],
Chris@16 44 &default_special_value_names[3],
Chris@16 45 std::back_inserter(m_special_value_names));
Chris@16 46 }
Chris@16 47
Chris@16 48 //! Construct special values formatter from array of strings
Chris@16 49 /*! This constructor will take pair of iterators from an array of strings
Chris@16 50 * that represent the special values and copy them for use in formatting
Chris@16 51 * special values.
Chris@16 52 *@code
Chris@16 53 * const char* const special_value_names[]={"nadt","-inf","+inf" };
Chris@16 54 *
Chris@16 55 * special_value_formatter svf(&special_value_names[0], &special_value_names[3]);
Chris@16 56 *@endcode
Chris@16 57 */
Chris@16 58 special_values_formatter(const char_type* const* begin, const char_type* const* end)
Chris@16 59 {
Chris@16 60 std::copy(begin, end, std::back_inserter(m_special_value_names));
Chris@16 61 }
Chris@16 62 special_values_formatter(typename collection_type::iterator beg, typename collection_type::iterator end)
Chris@16 63 {
Chris@16 64 std::copy(beg, end, std::back_inserter(m_special_value_names));
Chris@16 65 }
Chris@16 66
Chris@16 67 OutItrT put_special(OutItrT next,
Chris@16 68 const boost::date_time::special_values& value) const
Chris@16 69 {
Chris@16 70
Chris@16 71 unsigned int index = value;
Chris@16 72 if (index < m_special_value_names.size()) {
Chris@16 73 std::copy(m_special_value_names[index].begin(),
Chris@16 74 m_special_value_names[index].end(),
Chris@16 75 next);
Chris@16 76 }
Chris@16 77 return next;
Chris@16 78 }
Chris@16 79 protected:
Chris@16 80 collection_type m_special_value_names;
Chris@16 81 };
Chris@16 82
Chris@16 83 //! Storage for the strings used to indicate special values
Chris@16 84 /* using c_strings to initialize these worked fine in testing, however,
Chris@16 85 * a project that compiled its objects separately, then linked in a separate
Chris@16 86 * step wound up with redefinition errors for the values in this array.
Chris@16 87 * Initializing individual characters eliminated this problem */
Chris@16 88 template <class CharT, class OutItrT>
Chris@16 89 const typename special_values_formatter<CharT, OutItrT>::char_type special_values_formatter<CharT, OutItrT>::default_special_value_names[3][17] = {
Chris@16 90 {'n','o','t','-','a','-','d','a','t','e','-','t','i','m','e'},
Chris@16 91 {'-','i','n','f','i','n','i','t','y'},
Chris@16 92 {'+','i','n','f','i','n','i','t','y'} };
Chris@16 93
Chris@16 94 } } //namespace boost::date_time
Chris@16 95
Chris@16 96 #endif