diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-27 18:24:20 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-27 18:24:20 +0000 |
commit | 483eb2f56657e8e7f419ab1a4fab8dce9ade8609 (patch) | |
tree | e5d88d25d870d5dedacb6bbdbe2a966086a0a5cf /src/boost/libs/icl/example/toytime.hpp | |
parent | Initial commit. (diff) | |
download | ceph-upstream.tar.xz ceph-upstream.zip |
Adding upstream version 14.2.21.upstream/14.2.21upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'src/boost/libs/icl/example/toytime.hpp')
-rw-r--r-- | src/boost/libs/icl/example/toytime.hpp | 74 |
1 files changed, 74 insertions, 0 deletions
diff --git a/src/boost/libs/icl/example/toytime.hpp b/src/boost/libs/icl/example/toytime.hpp new file mode 100644 index 00000000..30062878 --- /dev/null +++ b/src/boost/libs/icl/example/toytime.hpp @@ -0,0 +1,74 @@ +/*-----------------------------------------------------------------------------+ +Copyright (c) 2007-2009: Joachim Faulhaber ++------------------------------------------------------------------------------+ +Copyright (c) 1999-2006: Cortex Software GmbH, Kantstrasse 57, Berlin ++------------------------------------------------------------------------------+ + Distributed under the Boost Software License, Version 1.0. + (See accompanying file LICENCE.txt or copy at + http://www.boost.org/LICENSE_1_0.txt) ++-----------------------------------------------------------------------------*/ +#include <boost/config.hpp> +#ifdef BOOST_MSVC +#pragma warning(push) +#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. +#endif + +namespace boost{namespace icl +{ + +/** Time is a toy-class to demonstrate a class that conforms the requirements of + a template parameter for class template icl::interval. + + In real world applications you may want to use the integer representation of a + time variable. That way intervals and their containers are working most efficiently. +*/ + +enum {sunday=0, monday, tuesday, wednesday, thursday, friday, saturday}; +static const char* daynames[] = {"sun", "mon", "tue", "wed", "thu", "fri", "sat"}; + +class Time +{ +public: + Time(): m_time(0) {} + Time(int hours, int minutes): m_time(60*hours+minutes) {} + Time(int day, int hours, int minutes): m_time((24*60)*day+60*hours+minutes) {} + int getDay()const { return m_time/(24*60); } + int getHours()const { return (m_time%(24*60))/60; } + int getMinutes()const { return (m_time%(24*60))%60; } + int asInt()const { return m_time; } + std::string getDayString()const { return daynames[getDay()]; } + + std::string as_string()const + { + const int MAX_TIMESTING_LEN = 256; + char repr[MAX_TIMESTING_LEN]; + sprintf(repr, "%3s:%02d:%02d", getDayString().c_str(), getHours(), getMinutes()); + return std::string(repr); + } + + Time& operator ++ () { m_time++; return *this; } + Time& operator -- () { m_time--; return *this; } + +private: + int m_time; +}; + + +bool operator < (const Time& x1, const Time& x2) { return x1.asInt() < x2.asInt(); } +bool operator == (const Time& x1, const Time& x2) { return x1.asInt() == x2.asInt(); } +bool operator <= (const Time& x1, const Time& x2) { return x1.asInt() <= x2.asInt(); } + + +template<class CharType, class CharTraits> +std::basic_ostream<CharType, CharTraits> &operator<< + (std::basic_ostream<CharType, CharTraits> &stream, Time const& value) +{ + return stream << value.as_string(); +} + +}} // namespace icl boost + +#ifdef BOOST_MSVC +#pragma warning(pop) +#endif + |