Chris@16: Chris@16: #ifndef DATETIME_SPECIAL_VALUE_FORMATTER_HPP___ Chris@16: #define DATETIME_SPECIAL_VALUE_FORMATTER_HPP___ Chris@16: Chris@16: /* Copyright (c) 2004 CrystalClear Software, Inc. Chris@16: * Use, modification and distribution is subject to the Chris@16: * Boost Software License, Version 1.0. (See accompanying Chris@16: * file LICENSE_1_0.txt or http://www.boost.org/LICENSE_1_0.txt) Chris@16: * Author: Jeff Garland Chris@101: * $Date$ Chris@16: */ Chris@16: Chris@16: #include Chris@16: #include Chris@16: #include "boost/date_time/special_defs.hpp" Chris@16: Chris@16: namespace boost { namespace date_time { Chris@16: Chris@16: Chris@16: //! Class that provides generic formmatting ostream formatting for special values Chris@16: /*! This class provides for the formmating of special values to an output stream. Chris@16: * In particular, it produces strings for the values of negative and positive Chris@16: * infinity as well as not_a_date_time. Chris@16: * Chris@16: * While not a facet, this class is used by the date and time facets for formatting Chris@16: * special value types. Chris@16: * Chris@16: */ Chris@16: template > > Chris@16: class special_values_formatter Chris@16: { Chris@16: public: Chris@16: typedef std::basic_string string_type; Chris@16: typedef CharT char_type; Chris@16: typedef std::vector collection_type; Chris@16: static const char_type default_special_value_names[3][17]; Chris@16: Chris@16: //! Construct special values formatter using default strings. Chris@16: /*! Default strings are not-a-date-time -infinity +infinity Chris@16: */ Chris@16: special_values_formatter() Chris@16: { Chris@16: std::copy(&default_special_value_names[0], Chris@16: &default_special_value_names[3], Chris@16: std::back_inserter(m_special_value_names)); Chris@16: } Chris@16: Chris@16: //! Construct special values formatter from array of strings Chris@16: /*! This constructor will take pair of iterators from an array of strings Chris@16: * that represent the special values and copy them for use in formatting Chris@16: * special values. Chris@16: *@code Chris@16: * const char* const special_value_names[]={"nadt","-inf","+inf" }; Chris@16: * Chris@16: * special_value_formatter svf(&special_value_names[0], &special_value_names[3]); Chris@16: *@endcode Chris@16: */ Chris@16: special_values_formatter(const char_type* const* begin, const char_type* const* end) Chris@16: { Chris@16: std::copy(begin, end, std::back_inserter(m_special_value_names)); Chris@16: } Chris@16: special_values_formatter(typename collection_type::iterator beg, typename collection_type::iterator end) Chris@16: { Chris@16: std::copy(beg, end, std::back_inserter(m_special_value_names)); Chris@16: } Chris@16: Chris@16: OutItrT put_special(OutItrT next, Chris@16: const boost::date_time::special_values& value) const Chris@16: { Chris@16: Chris@16: unsigned int index = value; Chris@16: if (index < m_special_value_names.size()) { Chris@16: std::copy(m_special_value_names[index].begin(), Chris@16: m_special_value_names[index].end(), Chris@16: next); Chris@16: } Chris@16: return next; Chris@16: } Chris@16: protected: Chris@16: collection_type m_special_value_names; Chris@16: }; Chris@16: Chris@16: //! Storage for the strings used to indicate special values Chris@16: /* using c_strings to initialize these worked fine in testing, however, Chris@16: * a project that compiled its objects separately, then linked in a separate Chris@16: * step wound up with redefinition errors for the values in this array. Chris@16: * Initializing individual characters eliminated this problem */ Chris@16: template Chris@16: const typename special_values_formatter::char_type special_values_formatter::default_special_value_names[3][17] = { Chris@16: {'n','o','t','-','a','-','d','a','t','e','-','t','i','m','e'}, Chris@16: {'-','i','n','f','i','n','i','t','y'}, Chris@16: {'+','i','n','f','i','n','i','t','y'} }; Chris@16: Chris@16: } } //namespace boost::date_time Chris@16: Chris@16: #endif