greg_weekday.hpp 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. #ifndef GREG_WEEKDAY_HPP___
  2. #define GREG_WEEKDAY_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, Bart Garst
  8. * $Date$
  9. */
  10. #include <boost/date_time/constrained_value.hpp>
  11. #include <boost/date_time/date_defs.hpp>
  12. #include <boost/date_time/compiler_config.hpp>
  13. #include <stdexcept>
  14. #include <string>
  15. namespace boost {
  16. namespace gregorian {
  17. //bring enum values into the namespace
  18. using date_time::Sunday;
  19. using date_time::Monday;
  20. using date_time::Tuesday;
  21. using date_time::Wednesday;
  22. using date_time::Thursday;
  23. using date_time::Friday;
  24. using date_time::Saturday;
  25. //! Exception that flags that a weekday number is incorrect
  26. struct BOOST_SYMBOL_VISIBLE bad_weekday : public std::out_of_range
  27. {
  28. bad_weekday() : std::out_of_range(std::string("Weekday is out of range 0..6")) {}
  29. };
  30. typedef CV::simple_exception_policy<unsigned short, 0, 6, bad_weekday> greg_weekday_policies;
  31. typedef CV::constrained_value<greg_weekday_policies> greg_weekday_rep;
  32. //! Represent a day within a week (range 0==Sun to 6==Sat)
  33. class BOOST_DATE_TIME_DECL greg_weekday : public greg_weekday_rep {
  34. public:
  35. typedef boost::date_time::weekdays weekday_enum;
  36. greg_weekday(value_type day_of_week_num) :
  37. greg_weekday_rep(day_of_week_num)
  38. {}
  39. value_type as_number() const {return value_;}
  40. const char* as_short_string() const;
  41. const char* as_long_string() const;
  42. #ifndef BOOST_NO_STD_WSTRING
  43. const wchar_t* as_short_wstring() const;
  44. const wchar_t* as_long_wstring() const;
  45. #endif // BOOST_NO_STD_WSTRING
  46. weekday_enum as_enum() const {return static_cast<weekday_enum>(value_);}
  47. };
  48. } } //namespace gregorian
  49. #endif