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.cpp in vendors/XIOS/current/extern/boost/src/date_time – NEMO

source: vendors/XIOS/current/extern/boost/src/date_time/greg_month.cpp @ 3428

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

importing initial XIOS vendor drop

File size: 5.8 KB
Line 
1/* Copyright (c) 2002-2005 CrystalClear Software, Inc.
2 * Use, modification and distribution is subject to the
3 * Boost Software License, Version 1.0. (See accompanying
4 * file LICENSE_1_0.txt or http://www.boost.org/LICENSE_1_0.txt)
5 * Author: Jeff Garland, Bart Garst
6 * $Date: 2008-11-23 06:13:35 -0500 (Sun, 23 Nov 2008) $
7 */
8
9
10
11#ifndef BOOST_DATE_TIME_SOURCE
12#define BOOST_DATE_TIME_SOURCE
13#endif
14#include <boost/date_time/gregorian/greg_month.hpp>
15#include <boost/date_time/gregorian/greg_facet.hpp>
16#include <boost/date_time/date_format_simple.hpp>
17#include <boost/date_time/compiler_config.hpp>
18#if defined(BOOST_DATE_TIME_INCLUDE_LIMITED_HEADERS)
19#include <boost/date_time/gregorian/formatters_limited.hpp>
20#else
21#include <boost/date_time/gregorian/formatters.hpp>
22#endif
23#include <boost/date_time/date_parsing.hpp>
24#include <boost/date_time/gregorian/parsers.hpp>
25
26#include "greg_names.hpp"
27namespace boost {
28namespace gregorian {
29
30  /*! Returns a shared pointer to a map of Month strings & numbers.
31   * Strings are both full names and abbreviations.
32   * Ex. ("jan",1), ("february",2), etc...
33   * Note: All characters are lowercase - for case insensitivity
34   */
35  greg_month::month_map_ptr_type greg_month::get_month_map_ptr()
36  {
37    static month_map_ptr_type month_map_ptr(new greg_month::month_map_type());
38
39    if(month_map_ptr->empty()) {
40      std::string s("");
41      for(unsigned short i = 1; i <= 12; ++i) {
42        greg_month m(static_cast<month_enum>(i));
43        s = m.as_long_string();
44        s = date_time::convert_to_lower(s);
45        month_map_ptr->insert(std::make_pair(s, i));
46        s = m.as_short_string();
47        s = date_time::convert_to_lower(s);
48        month_map_ptr->insert(std::make_pair(s, i));
49      }
50    }
51    return month_map_ptr;
52  }
53
54
55  //! Returns 3 char english string for the month ex: Jan, Feb, Mar, Apr
56  const char*
57  greg_month::as_short_string() const 
58  {
59    return short_month_names[value_-1];
60  }
61 
62  //! Returns full name of month as string in english ex: January, February
63  const char*
64  greg_month::as_long_string()  const 
65  {
66    return long_month_names[value_-1];
67  }
68 
69  //! Return special_value from string argument
70  /*! Return special_value from string argument. If argument is
71   * not one of the special value names (defined in names.hpp),
72   * return 'not_special' */
73  special_values special_value_from_string(const std::string& s) {
74    short i = date_time::find_match(special_value_names,
75                                    special_value_names,
76                                    date_time::NumSpecialValues,
77                                    s);
78    if(i >= date_time::NumSpecialValues) { // match not found
79      return not_special;
80    }
81    else {
82      return static_cast<special_values>(i);
83    }
84  }
85
86
87#ifndef BOOST_NO_STD_WSTRING
88  //! Returns 3 wchar_t english string for the month ex: Jan, Feb, Mar, Apr
89  const wchar_t*
90  greg_month::as_short_wstring() const 
91  {
92    return w_short_month_names[value_-1];
93  }
94 
95  //! Returns full name of month as wchar_t string in english ex: January, February
96  const wchar_t*
97  greg_month::as_long_wstring()  const 
98  {
99    return w_long_month_names[value_-1];
100  }
101#endif // BOOST_NO_STD_WSTRING
102 
103#ifndef BOOST_DATE_TIME_NO_LOCALE
104  /*! creates an all_date_names_put object with the correct set of names.
105   * This function is only called in the event of an exception where
106   * the imbued locale containing the needed facet is for some reason
107   * unreachable.
108   */
109  BOOST_DATE_TIME_DECL
110  boost::date_time::all_date_names_put<greg_facet_config, char>* 
111  create_facet_def(char type)
112  {
113    typedef 
114      boost::date_time::all_date_names_put<greg_facet_config, char> facet_def;
115   
116    return new facet_def(short_month_names,
117                         long_month_names,
118                         special_value_names,
119                         short_weekday_names,
120                         long_weekday_names);
121  }
122 
123  //! generates a locale with the set of gregorian name-strings of type char*
124  BOOST_DATE_TIME_DECL std::locale generate_locale(std::locale& loc, char type){
125    typedef boost::date_time::all_date_names_put<greg_facet_config, char> facet_def;
126    return std::locale(loc, new facet_def(short_month_names,
127                                          long_month_names,
128                                          special_value_names,
129                                          short_weekday_names,
130                                          long_weekday_names)
131        );
132  }
133 
134#ifndef BOOST_NO_STD_WSTRING
135  /*! creates an all_date_names_put object with the correct set of names.
136   * This function is only called in the event of an exception where
137   * the imbued locale containing the needed facet is for some reason
138   * unreachable.
139   */
140  BOOST_DATE_TIME_DECL
141  boost::date_time::all_date_names_put<greg_facet_config, wchar_t>* 
142  create_facet_def(wchar_t type)
143  {
144    typedef 
145      boost::date_time::all_date_names_put<greg_facet_config,wchar_t> facet_def;
146   
147    return new facet_def(w_short_month_names,
148                         w_long_month_names,
149                         w_special_value_names,
150                         w_short_weekday_names,
151                         w_long_weekday_names);
152  }
153
154  //! generates a locale with the set of gregorian name-strings of type wchar_t*
155  BOOST_DATE_TIME_DECL std::locale generate_locale(std::locale& loc, wchar_t type){
156    typedef boost::date_time::all_date_names_put<greg_facet_config, wchar_t> facet_def;
157    return std::locale(loc, new facet_def(w_short_month_names,
158                                          w_long_month_names,
159                                          w_special_value_names,
160                                          w_short_weekday_names,
161                                          w_long_weekday_names)
162        );
163  }
164#endif // BOOST_NO_STD_WSTRING
165#endif // BOOST_DATE_TIME_NO_LOCALE
166
167} } //namespace gregorian
168
169
170
171
172
173
Note: See TracBrowser for help on using the repository browser.