greg_day.hpp 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. #ifndef GREG_DAY_HPP___
  2. #define GREG_DAY_HPP___
  3. /* Copyright (c) 2002,2003 CrystalClear Software, Inc.
  4. * Use, modification and distribution is subject to the
  5. * Boost Software License, Version 1.0. (See accompanying
  6. * file LICENSE_1_0.txt or http://www.boost.org/LICENSE_1_0.txt)
  7. * Author: Jeff Garland
  8. * $Date$
  9. */
  10. #include <boost/date_time/constrained_value.hpp>
  11. #include <boost/date_time/compiler_config.hpp>
  12. #include <stdexcept>
  13. #include <string>
  14. namespace boost {
  15. namespace gregorian {
  16. //! Exception type for gregorian day of month (1..31)
  17. struct BOOST_SYMBOL_VISIBLE bad_day_of_month : public std::out_of_range
  18. {
  19. bad_day_of_month() :
  20. std::out_of_range(std::string("Day of month value is out of range 1..31"))
  21. {}
  22. //! Allow other classes to throw with unique string for bad day like Feb 29
  23. bad_day_of_month(const std::string& s) :
  24. std::out_of_range(s)
  25. {}
  26. };
  27. //! Policy class that declares error handling and day of month ranges
  28. typedef CV::simple_exception_policy<unsigned short, 1, 31, bad_day_of_month> greg_day_policies;
  29. //! Generated represetation for gregorian day of month
  30. typedef CV::constrained_value<greg_day_policies> greg_day_rep;
  31. //! Represent a day of the month (range 1 - 31)
  32. /*! This small class allows for simple conversion an integer value into
  33. a day of the month for a standard gregorian calendar. The type
  34. is automatically range checked so values outside of the range 1-31
  35. will cause a bad_day_of_month exception
  36. */
  37. class BOOST_SYMBOL_VISIBLE greg_day : public greg_day_rep {
  38. public:
  39. greg_day(value_type day_of_month) : greg_day_rep(day_of_month) {}
  40. value_type as_number() const {return value_;}
  41. operator value_type() const {return value_;}
  42. private:
  43. };
  44. } } //namespace gregorian
  45. #endif