Back to home page

EIC code displayed by LXR

 
 

    


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

0001 #ifndef GREG_MONTH_HPP___
0002 #define GREG_MONTH_HPP___
0003 
0004 /* Copyright (c) 2002,2003, 2020 CrystalClear Software, Inc.
0005  * Use, modification and distribution is subject to the 
0006  * Boost Software License, Version 1.0. (See accompanying
0007  * file LICENSE_1_0.txt or http://www.boost.org/LICENSE_1_0.txt)
0008  * Author: Jeff Garland, Bart Garst
0009  * $Date$
0010  */
0011 
0012 #include <boost/date_time/constrained_value.hpp>
0013 #include <boost/date_time/date_defs.hpp>
0014 #include <boost/date_time/compiler_config.hpp>
0015 #include <stdexcept>
0016 #include <string>
0017 
0018 namespace boost {
0019 namespace gregorian {
0020 
0021   typedef date_time::months_of_year months_of_year;
0022 
0023   //bring enum values into the namespace
0024   using date_time::Jan;
0025   using date_time::Feb;
0026   using date_time::Mar;
0027   using date_time::Apr;
0028   using date_time::May;
0029   using date_time::Jun;
0030   using date_time::Jul;
0031   using date_time::Aug;
0032   using date_time::Sep;
0033   using date_time::Oct;
0034   using date_time::Nov;
0035   using date_time::Dec;
0036   using date_time::NotAMonth;
0037   using date_time::NumMonths;
0038 
0039   //! Exception thrown if a greg_month is constructed with a value out of range
0040   struct BOOST_SYMBOL_VISIBLE bad_month : public std::out_of_range
0041   {
0042     bad_month() : std::out_of_range(std::string("Month number is out of range 1..12")) {}
0043   };
0044   //! Build a policy class for the greg_month_rep
0045   typedef CV::simple_exception_policy<unsigned short, 1, 12, bad_month> greg_month_policies;
0046   //! A constrained range that implements the gregorian_month rules
0047   typedef CV::constrained_value<greg_month_policies> greg_month_rep;
0048 
0049 
0050   //! Wrapper class to represent months in gregorian based calendar
0051   class BOOST_SYMBOL_VISIBLE greg_month : public greg_month_rep {
0052   public:
0053     typedef date_time::months_of_year month_enum;
0054 
0055     //! Construct a month from the months_of_year enumeration
0056     BOOST_CXX14_CONSTEXPR greg_month(month_enum theMonth) :
0057       greg_month_rep(static_cast<greg_month_rep::value_type>(theMonth)) {}
0058     //! Construct from a short value
0059     BOOST_CXX14_CONSTEXPR greg_month(value_type theMonth) : greg_month_rep(theMonth) {}
0060     //! Convert the value back to a short
0061     BOOST_CXX14_CONSTEXPR operator value_type()  const {return value_;}
0062     //! Returns month as number from 1 to 12
0063     BOOST_CXX14_CONSTEXPR value_type as_number() const {return value_;}
0064     BOOST_CXX14_CONSTEXPR month_enum as_enum() const {return static_cast<month_enum>(value_);}
0065 
0066     //! Returns 3 char english string for the month ex: Jan, Feb, Mar, Apr
0067     const char*
0068     as_short_string() const
0069     {
0070       static const char* const short_month_names[NumMonths]
0071         = {"Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec", "NAM"};
0072       return short_month_names[value_-1];
0073     }
0074 
0075     //! Returns full name of month as string in english ex: January, February
0076     const char*
0077     as_long_string() const
0078     {
0079       static const char* const long_month_names[NumMonths]
0080         = {"January","February","March","April","May","June","July","August",
0081            "September","October","November","December","NotAMonth"};
0082       return long_month_names[value_-1];
0083     }
0084 
0085 #ifndef BOOST_NO_STD_WSTRING
0086 
0087     //! Returns 3 wchar_t english string for the month ex: Jan, Feb, Mar, Apr
0088     const wchar_t*
0089     as_short_wstring() const
0090     {
0091       static const wchar_t* const w_short_month_names[NumMonths]
0092         = {L"Jan",L"Feb",L"Mar",L"Apr",L"May",L"Jun",L"Jul",L"Aug",L"Sep",L"Oct",
0093            L"Nov",L"Dec",L"NAM"};
0094       return w_short_month_names[value_-1];
0095     }
0096 
0097     //! Returns full name of month as wchar_t string in english ex: January, February
0098     const wchar_t*
0099     as_long_wstring() const
0100     {
0101       static const wchar_t* const w_long_month_names[NumMonths]
0102         = {L"January",L"February",L"March",L"April",L"May",L"June",L"July",L"August",
0103            L"September",L"October",L"November",L"December",L"NotAMonth"};
0104       return w_long_month_names[value_-1];
0105     }
0106 
0107 #endif // BOOST_NO_STD_WSTRING
0108 
0109     /* parameterized as_*_string functions are intended to be called
0110      * from a template function: "... as_short_string(charT c='\0');" */
0111     const char* as_short_string(char) const
0112     {
0113       return as_short_string();
0114     }
0115     const char* as_long_string(char) const
0116     {
0117       return as_long_string();
0118     }
0119 #ifndef BOOST_NO_STD_WSTRING
0120     const wchar_t* as_short_string(wchar_t) const
0121     {
0122       return as_short_wstring();
0123     }
0124     const wchar_t* as_long_string(wchar_t) const
0125     {
0126       return as_long_wstring();
0127     }
0128 #endif // BOOST_NO_STD_WSTRING
0129   };
0130 
0131 } } //namespace gregorian
0132 
0133 #endif