annotate DEPENDENCIES/generic/include/boost/date_time/gregorian/greg_month.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 #ifndef GREG_MONTH_HPP___
Chris@16 2 #define GREG_MONTH_HPP___
Chris@16 3
Chris@16 4 /* Copyright (c) 2002,2003 CrystalClear Software, Inc.
Chris@16 5 * Use, modification and distribution is subject to the
Chris@16 6 * Boost Software License, Version 1.0. (See accompanying
Chris@16 7 * file LICENSE_1_0.txt or http://www.boost.org/LICENSE_1_0.txt)
Chris@16 8 * Author: Jeff Garland, Bart Garst
Chris@101 9 * $Date$
Chris@16 10 */
Chris@16 11
Chris@16 12 #include "boost/date_time/constrained_value.hpp"
Chris@16 13 #include "boost/date_time/date_defs.hpp"
Chris@16 14 #include "boost/shared_ptr.hpp"
Chris@16 15 #include "boost/date_time/compiler_config.hpp"
Chris@16 16 #include <stdexcept>
Chris@16 17 #include <string>
Chris@16 18 #include <map>
Chris@16 19 #include <algorithm>
Chris@16 20 #include <cctype>
Chris@16 21
Chris@16 22 namespace boost {
Chris@16 23 namespace gregorian {
Chris@16 24
Chris@16 25 typedef date_time::months_of_year months_of_year;
Chris@16 26
Chris@16 27 //bring enum values into the namespace
Chris@16 28 using date_time::Jan;
Chris@16 29 using date_time::Feb;
Chris@16 30 using date_time::Mar;
Chris@16 31 using date_time::Apr;
Chris@16 32 using date_time::May;
Chris@16 33 using date_time::Jun;
Chris@16 34 using date_time::Jul;
Chris@16 35 using date_time::Aug;
Chris@16 36 using date_time::Sep;
Chris@16 37 using date_time::Oct;
Chris@16 38 using date_time::Nov;
Chris@16 39 using date_time::Dec;
Chris@16 40 using date_time::NotAMonth;
Chris@16 41 using date_time::NumMonths;
Chris@16 42
Chris@16 43 //! Exception thrown if a greg_month is constructed with a value out of range
Chris@16 44 struct bad_month : public std::out_of_range
Chris@16 45 {
Chris@16 46 bad_month() : std::out_of_range(std::string("Month number is out of range 1..12")) {}
Chris@16 47 };
Chris@16 48 //! Build a policy class for the greg_month_rep
Chris@16 49 typedef CV::simple_exception_policy<unsigned short, 1, 12, bad_month> greg_month_policies;
Chris@16 50 //! A constrained range that implements the gregorian_month rules
Chris@16 51 typedef CV::constrained_value<greg_month_policies> greg_month_rep;
Chris@16 52
Chris@16 53
Chris@16 54 //! Wrapper class to represent months in gregorian based calendar
Chris@16 55 class BOOST_DATE_TIME_DECL greg_month : public greg_month_rep {
Chris@16 56 public:
Chris@16 57 typedef date_time::months_of_year month_enum;
Chris@16 58 typedef std::map<std::string, unsigned short> month_map_type;
Chris@16 59 typedef boost::shared_ptr<month_map_type> month_map_ptr_type;
Chris@16 60 //! Construct a month from the months_of_year enumeration
Chris@16 61 greg_month(month_enum theMonth) :
Chris@16 62 greg_month_rep(static_cast<greg_month_rep::value_type>(theMonth)) {}
Chris@16 63 //! Construct from a short value
Chris@16 64 greg_month(unsigned short theMonth) : greg_month_rep(theMonth) {}
Chris@16 65 //! Convert the value back to a short
Chris@16 66 operator unsigned short() const {return value_;}
Chris@16 67 //! Returns month as number from 1 to 12
Chris@16 68 unsigned short as_number() const {return value_;}
Chris@16 69 month_enum as_enum() const {return static_cast<month_enum>(value_);}
Chris@16 70 const char* as_short_string() const;
Chris@16 71 const char* as_long_string() const;
Chris@16 72 #ifndef BOOST_NO_STD_WSTRING
Chris@16 73 const wchar_t* as_short_wstring() const;
Chris@16 74 const wchar_t* as_long_wstring() const;
Chris@16 75 #endif // BOOST_NO_STD_WSTRING
Chris@16 76 //! Shared pointer to a map of Month strings (Names & Abbrev) & numbers
Chris@16 77 static month_map_ptr_type get_month_map_ptr();
Chris@16 78
Chris@16 79 /* parameterized as_*_string functions are intended to be called
Chris@16 80 * from a template function: "... as_short_string(charT c='\0');" */
Chris@16 81 const char* as_short_string(char) const
Chris@16 82 {
Chris@16 83 return as_short_string();
Chris@16 84 }
Chris@16 85 const char* as_long_string(char) const
Chris@16 86 {
Chris@16 87 return as_long_string();
Chris@16 88 }
Chris@16 89 #ifndef BOOST_NO_STD_WSTRING
Chris@16 90 const wchar_t* as_short_string(wchar_t) const
Chris@16 91 {
Chris@16 92 return as_short_wstring();
Chris@16 93 }
Chris@16 94 const wchar_t* as_long_string(wchar_t) const
Chris@16 95 {
Chris@16 96 return as_long_wstring();
Chris@16 97 }
Chris@16 98 #endif // BOOST_NO_STD_WSTRING
Chris@16 99 };
Chris@16 100
Chris@16 101 } } //namespace gregorian
Chris@16 102
Chris@16 103
Chris@16 104
Chris@16 105 #endif