/* The software in this package is distributed under the GNU General Public License version 2 (with a special exception described below). A copy of GNU General Public License (GPL) is included in this distribution, in the file COPYING.GPL. As a special exception, if other files instantiate templates or use macros or inline functions from this file, or you compile this file and link it with other works to produce a work based on this file, this file does not by itself cause the resulting work to be covered by the GNU General Public License. However the source code for this file must still be made available in accordance with section (3) of the GNU General Public License. This exception does not invalidate any other reasons why a work based on this file might be covered by the GNU General Public License. */ /** @file * @brief time related functions. Week module * * @copyright Copyright © 2001-2009 by Intra2net AG */ #ifndef __WEEK_HPP #define __WEEK_HPP #include #include namespace I2n { namespace Time { /** * @brief represents some days of a week. * */ class Week { private: /// Bitset storing the active days. Zero is Sunday. std::bitset<7> Days; /// Flag to indicate if this Week is valid bool IsValid; public: enum WeekDay { Su=0, Mo=1, Tu=2, We=3, Th=4, Fr=5, Sa=6, _WeekDay_END=7 }; Week(); Week(const std::string& daystring); Week(const std::bitset<7> &_days); bool is_valid() const; void clear(); operator std::bitset<7>() const { return Days; } bool set(const std::string& daystring); bool set(const WeekDay day, bool value=true); bool get(WeekDay day) const; bool is_set(WeekDay day) const; bool all_set() const; bool none_set() const; unsigned int days_till_set(WeekDay day) const; unsigned int days_since_set(WeekDay day) const; std::string get_daystring() const; std::string get_displaystring() const; std::string get_netfilterstring() const; static std::string get_day_display(WeekDay day); static std::string get_english_display(WeekDay day); // some operators for convenience: Week& operator&=(const Week& rhs) { Days &= rhs.Days; return *this; } Week& operator|=(const Week& rhs) { Days |= rhs.Days; return *this; } Week& operator^=(const Week& rhs) { Days ^= rhs.Days; return *this; } bool operator==(const Week& rhs) const { return Days == rhs.Days; } bool operator!=(const Week& rhs) const { return Days != rhs.Days; } }; /** * @brief delivers a week containing the days which are in both weeks. * @param lhs first week. * @param rhs second week. * @return week which has only those days which are in both weeks. */ inline Week operator&(const Week& lhs, const Week& rhs) { I2n::Time::Week result(lhs); return result &= rhs; } /** * @brief delivers a week containing the days which are at least in one of both weeks. * @param lhs first week. * @param rhs second week. * @return week which has only those days which are at least in one of both weeks. */ inline Week operator|(const Week& lhs, const Week& rhs) { I2n::Time::Week result(lhs); return result |= rhs; } /** * @brief delivers a week containing the days which are in only one of both weeks. * @param lhs first week. * @param rhs second week. * @return week which has only those days which are in only one of both weeks. */ inline Week operator^(const Week& lhs, const Week& rhs) { I2n::Time::Week result(lhs); return result ^= rhs; } } } #endif