Chris@16
|
1 #ifndef GREG_YEAR_HPP___
|
Chris@16
|
2 #define GREG_YEAR_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
|
Chris@101
|
9 * $Date$
|
Chris@16
|
10 */
|
Chris@16
|
11
|
Chris@16
|
12 #include "boost/date_time/constrained_value.hpp"
|
Chris@16
|
13 #include <stdexcept>
|
Chris@16
|
14 #include <string>
|
Chris@16
|
15
|
Chris@16
|
16 namespace boost {
|
Chris@16
|
17 namespace gregorian {
|
Chris@16
|
18
|
Chris@16
|
19 //! Exception type for gregorian year
|
Chris@16
|
20 struct bad_year : public std::out_of_range
|
Chris@16
|
21 {
|
Chris@16
|
22 bad_year() :
|
Chris@16
|
23 std::out_of_range(std::string("Year is out of valid range: 1400..10000"))
|
Chris@16
|
24 {}
|
Chris@16
|
25 };
|
Chris@16
|
26 //! Policy class that declares error handling gregorian year type
|
Chris@16
|
27 typedef CV::simple_exception_policy<unsigned short, 1400, 10000, bad_year> greg_year_policies;
|
Chris@16
|
28
|
Chris@16
|
29 //! Generated representation for gregorian year
|
Chris@16
|
30 typedef CV::constrained_value<greg_year_policies> greg_year_rep;
|
Chris@16
|
31
|
Chris@16
|
32 //! Represent a day of the month (range 1900 - 10000)
|
Chris@16
|
33 /*! This small class allows for simple conversion an integer value into
|
Chris@16
|
34 a year for the gregorian calendar. This currently only allows a
|
Chris@16
|
35 range of 1900 to 10000. Both ends of the range are a bit arbitrary
|
Chris@16
|
36 at the moment, but they are the limits of current testing of the
|
Chris@16
|
37 library. As such they may be increased in the future.
|
Chris@16
|
38 */
|
Chris@16
|
39 class greg_year : public greg_year_rep {
|
Chris@16
|
40 public:
|
Chris@16
|
41 greg_year(unsigned short year) : greg_year_rep(year) {}
|
Chris@16
|
42 operator unsigned short() const {return value_;}
|
Chris@16
|
43 private:
|
Chris@16
|
44
|
Chris@16
|
45 };
|
Chris@16
|
46
|
Chris@16
|
47
|
Chris@16
|
48
|
Chris@16
|
49 } } //namespace gregorian
|
Chris@16
|
50
|
Chris@16
|
51
|
Chris@16
|
52
|
Chris@16
|
53 #endif
|