New URL for NEMO forge!   http://forge.nemo-ocean.eu

Since March 2022 along with NEMO 4.2 release, the code development moved to a self-hosted GitLab.
This present forge is now archived and remained online for history.
greg_month.hpp in vendors/XIOS/current/extern/boost/include/boost/date_time/gregorian – NEMO

source: vendors/XIOS/current/extern/boost/include/boost/date_time/gregorian/greg_month.hpp @ 3408

Last change on this file since 3408 was 3408, checked in by rblod, 12 years ago

importing initial XIOS vendor drop

  • Property svn:keywords set to Id
File size: 3.4 KB
Line 
1#ifndef GREG_MONTH_HPP___
2#define GREG_MONTH_HPP___
3
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
9 * $Date: 2008-02-27 15:00:24 -0500 (Wed, 27 Feb 2008) $
10 */
11
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"
16#include <stdexcept>
17#include <string>
18#include <map>
19#include <algorithm>
20#include <cctype>
21
22namespace boost {
23namespace gregorian {
24
25  typedef date_time::months_of_year months_of_year;
26
27  //bring enum values into the namespace
28  using date_time::Jan;
29  using date_time::Feb;
30  using date_time::Mar;
31  using date_time::Apr;
32  using date_time::May;
33  using date_time::Jun;
34  using date_time::Jul;
35  using date_time::Aug;
36  using date_time::Sep;
37  using date_time::Oct;
38  using date_time::Nov;
39  using date_time::Dec;
40  using date_time::NotAMonth;
41  using date_time::NumMonths;
42 
43  //! Exception thrown if a greg_month is constructed with a value out of range
44  struct bad_month : public std::out_of_range
45  {
46    bad_month() : std::out_of_range(std::string("Month number is out of range 1..12")) {}
47  };
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;
52
53 
54  //! Wrapper class to represent months in gregorian based calendar
55  class BOOST_DATE_TIME_DECL greg_month : public greg_month_rep {
56  public:
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();
78
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
82    {
83      return as_short_string();
84    }
85    const char* as_long_string(char) const
86    {
87      return as_long_string();
88    }
89#ifndef BOOST_NO_STD_WSTRING
90    const wchar_t* as_short_string(wchar_t) const
91    {
92      return as_short_wstring();
93    }
94    const wchar_t* as_long_string(wchar_t) const
95    {
96      return as_long_wstring();
97    }
98#endif // BOOST_NO_STD_WSTRING
99  };
100
101} } //namespace gregorian
102
103
104
105#endif
Note: See TracBrowser for help on using the repository browser.