[MERGE] libi2ncommon: (reinhard) added some (bit) operators to class WEEK.
authorThomas Jarosch <thomas.jarosch@intra2net.com>
Tue, 8 Jul 2008 11:33:08 +0000 (11:33 +0000)
committerThomas Jarosch <thomas.jarosch@intra2net.com>
Tue, 8 Jul 2008 11:33:08 +0000 (11:33 +0000)
src/timefunc.hxx

index 68fb538..3f5810a 100644 (file)
@@ -33,6 +33,11 @@ inline std::string output_hour_minute_from_seconds(int seconds)
 
 std::string get_month_name(unsigned char month);
 
+
+/**
+ * @brief represents some days of a week.
+ *
+ */
 class WEEK
 {
     private:
@@ -40,38 +45,108 @@ class WEEK
 
     public:
         enum WEEKDAY { SU=0, MO=1, TU=2, WE=3, TH=4, FR=5, SA=6 };
-        
+
         // throws out_of_range if illegal week
         WEEK(const std::string& daystring);
-        
-        WEEK(const std::bitset<7> &days)
-            : days(days)
+
+        WEEK(const std::bitset<7> &_days)
+            : days(_days)
             { }
-            
+
         WEEK()
             { }
-            
+
         void clear()
             { days.reset(); }
-            
+
         operator std::bitset<7>() const
             { return days; }
-            
+
         void set(WEEKDAY d, bool value=true)
             { days[d]=value; }
-        
+
         bool all_set() const
             { return (days.count()==7); }
         bool none_set() const
             { return days.none(); }
-        
+
         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)
+        {
+            return days == rhs.days;
+        }
+
+        bool operator!=(const WEEK& rhs)
+        {
+            return days != rhs.days;
+        }
+
+}; // eo class WEEK
+
+
+/**
+ * @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)
+{
+    WEEK result(lhs);
+    return result &= rhs;
+} // eo operator&(const WEEK&,const WEEK&)
+
+
+/**
+ * @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)
+{
+    WEEK result(lhs);
+    return result |= rhs;
+} // eo operator&(const WEEK&,const WEEK&)
+
+
+/**
+ * @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)
+{
+    WEEK result(lhs);
+    return result ^= rhs;
+} // eo operator&(const WEEK&,const WEEK&)
 
 
 /**