Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:30:39

0001 
0002 #ifndef DATETIME_SPECIAL_VALUE_FORMATTER_HPP___
0003 #define DATETIME_SPECIAL_VALUE_FORMATTER_HPP___
0004 
0005 /* Copyright (c) 2004 CrystalClear Software, Inc.
0006  * Use, modification and distribution is subject to the 
0007  * Boost Software License, Version 1.0. (See accompanying
0008  * file LICENSE_1_0.txt or http://www.boost.org/LICENSE_1_0.txt)
0009  * Author: Jeff Garland
0010  * $Date$
0011  */
0012 
0013 #include <vector>
0014 #include <string>
0015 #include <iterator>
0016 #include "boost/date_time/special_defs.hpp"
0017 
0018 namespace boost { namespace date_time {
0019 
0020 
0021   //! Class that provides generic formmatting ostream formatting for special values
0022   /*! This class provides for the formmating of special values to an output stream.
0023    *  In particular, it produces strings for the values of negative and positive
0024    *  infinity as well as not_a_date_time.  
0025    *
0026    *  While not a facet, this class is used by the date and time facets for formatting
0027    *  special value types.
0028    *
0029    */
0030   template <class CharT, class OutItrT = std::ostreambuf_iterator<CharT, std::char_traits<CharT> > >
0031   class special_values_formatter  
0032   {
0033   public:
0034     typedef std::basic_string<CharT> string_type;
0035     typedef CharT                    char_type;
0036     typedef std::vector<string_type> collection_type;
0037     static const char_type default_special_value_names[3][17];
0038 
0039     //! Construct special values formatter using default strings.
0040     /*! Default strings are not-a-date-time -infinity +infinity
0041      */
0042     special_values_formatter() 
0043     {
0044       std::copy(&default_special_value_names[0], 
0045                 &default_special_value_names[3], 
0046                 std::back_inserter(m_special_value_names));      
0047     }
0048 
0049     //! Construct special values formatter from array of strings
0050     /*! This constructor will take pair of iterators from an array of strings
0051      *  that represent the special values and copy them for use in formatting
0052      *  special values.  
0053      *@code
0054      *  const char* const special_value_names[]={"nadt","-inf","+inf" };
0055      *
0056      *  special_value_formatter svf(&special_value_names[0], &special_value_names[3]);
0057      *@endcode
0058      */
0059     special_values_formatter(const char_type* const* begin, const char_type* const* end) 
0060     {
0061       std::copy(begin, end, std::back_inserter(m_special_value_names));
0062     }
0063     special_values_formatter(typename collection_type::iterator beg, typename collection_type::iterator end)
0064     {
0065       std::copy(beg, end, std::back_inserter(m_special_value_names));
0066     }
0067 
0068     OutItrT put_special(OutItrT next, 
0069                         const boost::date_time::special_values& value) const 
0070     {
0071       
0072       unsigned int index = value;
0073       if (index < m_special_value_names.size()) {
0074         std::copy(m_special_value_names[index].begin(), 
0075                   m_special_value_names[index].end(),
0076                   next);
0077       }
0078       return next;
0079     }
0080   protected:
0081     collection_type m_special_value_names;
0082   };
0083 
0084   //! Storage for the strings used to indicate special values 
0085   /* using c_strings to initialize these worked fine in testing, however,
0086    * a project that compiled its objects separately, then linked in a separate
0087    * step wound up with redefinition errors for the values in this array.
0088    * Initializing individual characters eliminated this problem */
0089   template <class CharT, class OutItrT>  
0090   const typename special_values_formatter<CharT, OutItrT>::char_type special_values_formatter<CharT, OutItrT>::default_special_value_names[3][17] = { 
0091     {'n','o','t','-','a','-','d','a','t','e','-','t','i','m','e'},
0092     {'-','i','n','f','i','n','i','t','y'},
0093     {'+','i','n','f','i','n','i','t','y'} };
0094 
0095  } } //namespace boost::date_time
0096 
0097 #endif