1 #ifndef GREG_MONTH_HPP___
2 #define GREG_MONTH_HPP___
4 /* Copyright (c) 2002,2003 CrystalClear Software, Inc.
5 * Use, modification and distribution is subject to the
6 * Boost Software License, Version 1.0. (See accompanying
7 * file LICENSE_1_0.txt or http://www.boost.org/LICENSE_1_0.txt)
8 * Author: Jeff Garland, Bart Garst
12 #include "boost/date_time/constrained_value.hpp"
13 #include "boost/date_time/date_defs.hpp"
14 #include "boost/shared_ptr.hpp"
15 #include "boost/date_time/compiler_config.hpp"
25 typedef date_time::months_of_year months_of_year;
27 //bring enum values into the namespace
40 using date_time::NotAMonth;
41 using date_time::NumMonths;
43 //! Exception thrown if a greg_month is constructed with a value out of range
44 struct bad_month : public std::out_of_range
46 bad_month() : std::out_of_range(std::string("Month number is out of range 1..12")) {}
48 //! Build a policy class for the greg_month_rep
49 typedef CV::simple_exception_policy<unsigned short, 1, 12, bad_month> greg_month_policies;
50 //! A constrained range that implements the gregorian_month rules
51 typedef CV::constrained_value<greg_month_policies> greg_month_rep;
54 //! Wrapper class to represent months in gregorian based calendar
55 class BOOST_DATE_TIME_DECL greg_month : public greg_month_rep {
57 typedef date_time::months_of_year month_enum;
58 typedef std::map<std::string, unsigned short> month_map_type;
59 typedef boost::shared_ptr<month_map_type> month_map_ptr_type;
60 //! Construct a month from the months_of_year enumeration
61 greg_month(month_enum theMonth) :
62 greg_month_rep(static_cast<greg_month_rep::value_type>(theMonth)) {}
63 //! Construct from a short value
64 greg_month(unsigned short theMonth) : greg_month_rep(theMonth) {}
65 //! Convert the value back to a short
66 operator unsigned short() const {return value_;}
67 //! Returns month as number from 1 to 12
68 unsigned short as_number() const {return value_;}
69 month_enum as_enum() const {return static_cast<month_enum>(value_);}
70 const char* as_short_string() const;
71 const char* as_long_string() const;
72 #ifndef BOOST_NO_STD_WSTRING
73 const wchar_t* as_short_wstring() const;
74 const wchar_t* as_long_wstring() const;
75 #endif // BOOST_NO_STD_WSTRING
76 //! Shared pointer to a map of Month strings (Names & Abbrev) & numbers
77 static month_map_ptr_type get_month_map_ptr();
79 /* parameterized as_*_string functions are intended to be called
80 * from a template function: "... as_short_string(charT c='\0');" */
81 const char* as_short_string(char) const
83 return as_short_string();
85 const char* as_long_string(char) const
87 return as_long_string();
89 #ifndef BOOST_NO_STD_WSTRING
90 const wchar_t* as_short_string(wchar_t) const
92 return as_short_wstring();
94 const wchar_t* as_long_string(wchar_t) const
96 return as_long_wstring();
98 #endif // BOOST_NO_STD_WSTRING
101 } } //namespace gregorian