]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/icl/example/toytime.hpp
add subtree-ish sources for 12.0.3
[ceph.git] / ceph / src / boost / libs / icl / example / toytime.hpp
1 /*-----------------------------------------------------------------------------+
2 Copyright (c) 2007-2009: Joachim Faulhaber
3 +------------------------------------------------------------------------------+
4 Copyright (c) 1999-2006: Cortex Software GmbH, Kantstrasse 57, Berlin
5 +------------------------------------------------------------------------------+
6 Distributed under the Boost Software License, Version 1.0.
7 (See accompanying file LICENCE.txt or copy at
8 http://www.boost.org/LICENSE_1_0.txt)
9 +-----------------------------------------------------------------------------*/
10 #include <boost/config.hpp>
11 #ifdef BOOST_MSVC
12 #pragma warning(push)
13 #pragma warning(disable:4996) // This function or variable may be unsafe. Consider using fopen_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details.
14 #endif
15
16 namespace boost{namespace icl
17 {
18
19 /** Time is a toy-class to demonstrate a class that conforms the requirements of
20 a template parameter for class template icl::interval.
21
22 In real world applications you may want to use the integer representation of a
23 time variable. That way intervals and their containers are working most efficiently.
24 */
25
26 enum {sunday=0, monday, tuesday, wednesday, thursday, friday, saturday};
27 static const char* daynames[] = {"sun", "mon", "tue", "wed", "thu", "fri", "sat"};
28
29 class Time
30 {
31 public:
32 Time(): m_time(0) {}
33 Time(int hours, int minutes): m_time(60*hours+minutes) {}
34 Time(int day, int hours, int minutes): m_time((24*60)*day+60*hours+minutes) {}
35 int getDay()const { return m_time/(24*60); }
36 int getHours()const { return (m_time%(24*60))/60; }
37 int getMinutes()const { return (m_time%(24*60))%60; }
38 int asInt()const { return m_time; }
39 std::string getDayString()const { return daynames[getDay()]; }
40
41 std::string as_string()const
42 {
43 const int MAX_TIMESTING_LEN = 256;
44 char repr[MAX_TIMESTING_LEN];
45 sprintf(repr, "%3s:%02d:%02d", getDayString().c_str(), getHours(), getMinutes());
46 return std::string(repr);
47 }
48
49 Time& operator ++ () { m_time++; return *this; }
50 Time& operator -- () { m_time--; return *this; }
51
52 private:
53 int m_time;
54 };
55
56
57 bool operator < (const Time& x1, const Time& x2) { return x1.asInt() < x2.asInt(); }
58 bool operator == (const Time& x1, const Time& x2) { return x1.asInt() == x2.asInt(); }
59 bool operator <= (const Time& x1, const Time& x2) { return x1.asInt() <= x2.asInt(); }
60
61
62 template<class CharType, class CharTraits>
63 std::basic_ostream<CharType, CharTraits> &operator<<
64 (std::basic_ostream<CharType, CharTraits> &stream, Time const& value)
65 {
66 return stream << value.as_string();
67 }
68
69 }} // namespace icl boost
70
71 #ifdef BOOST_MSVC
72 #pragma warning(pop)
73 #endif
74