[MERGE] libi2ncommon: (reinhard) added changed flag and a weak mark to Interval.
authorThomas Jarosch <thomas.jarosch@intra2net.com>
Tue, 8 Jul 2008 11:39:11 +0000 (11:39 +0000)
committerThomas Jarosch <thomas.jarosch@intra2net.com>
Tue, 8 Jul 2008 11:39:11 +0000 (11:39 +0000)
src/timefunc.cpp
src/timefunc.hxx
test/test_timefunc.cpp

index 139862b..c055aa4 100644 (file)
@@ -500,6 +500,7 @@ void Intervals::add(const Interval& new_frame)
             {
                 // the new interval starts earlier; we need to adjust our current frame:
                 current_frame.m_lower_bound = new_frame.m_lower_bound;
+                current_frame.m_changed = true;
             }
             // NOTE no "else" part needed since in that case our current frame already
             // contains the new one!
@@ -516,10 +517,12 @@ void Intervals::add(const Interval& new_frame)
         {
             // yes, we need to move the start:
             current_frame.m_lower_bound = new_frame.m_lower_bound;
+            current_frame.m_changed= true;
         }
 
         // now let's extend the end:
         current_frame.m_upper_bound = new_frame.m_upper_bound;
+        current_frame.m_changed = true;
 
         // well... let's walk through the following frames; looking for more joins...:
         IntervalList::iterator it2 = it;
@@ -586,7 +589,11 @@ void Intervals::sub(const Interval& del_frame)
                 m_intervals.insert(it, Interval( current_frame.m_lower_bound, del_frame.m_lower_bound ) );
             }
             // adjust start of current frame:
-            current_frame.m_lower_bound= del_frame.m_upper_bound;
+            if (current_frame.m_lower_bound < del_frame.m_upper_bound)
+            {
+                current_frame.m_lower_bound= del_frame.m_upper_bound;
+                current_frame.m_changed= true;
+            }
             // and we are done!
             return;
         }
@@ -596,6 +603,7 @@ void Intervals::sub(const Interval& del_frame)
             // a part of the current interval needs to be preserved..
             // move the end.
             current_frame.m_upper_bound= del_frame.m_lower_bound;
+            current_frame.m_changed= true;
             // and continue with the next interval:
             ++it;
             continue;
index 3f5810a..dd8aec1 100644 (file)
@@ -158,12 +158,16 @@ class Interval
         Interval()
         : m_lower_bound(0)
         , m_upper_bound(0)
+        , m_weak_mark(0)
+        , m_changed(false)
         {
         } //
 
-        Interval( unsigned int start, unsigned int end )
+        Interval( unsigned int start, unsigned int end, int weak_mark= 0 )
         : m_lower_bound(start)
         , m_upper_bound(end)
+        , m_weak_mark(weak_mark)
+        , m_changed(false)
         {
         } //
 
@@ -184,6 +188,10 @@ class Interval
         unsigned int lower_bound() const { return m_lower_bound; }
         unsigned int upper_bound() const { return m_upper_bound; }
 
+        int weak_mark() const { return m_weak_mark; }
+
+        bool changed() const { return m_changed; }
+
 
         bool operator== (const Interval& other) const
         {
@@ -213,6 +221,9 @@ class Interval
         unsigned int m_lower_bound;
         unsigned int m_upper_bound;
 
+        int m_weak_mark;
+        bool m_changed;
+
 }; // eo Interval
 
 
index 36ce508..30c0997 100644 (file)
@@ -129,6 +129,7 @@ public:
 
        CPPUNIT_ASSERT_EQUAL( 10u, intervals.front().lower_bound() );
        CPPUNIT_ASSERT_EQUAL( 100u, intervals.front().upper_bound() );
+       CPPUNIT_ASSERT_EQUAL( false, intervals.front().changed() );
    } // eo AddIntervalsInclude()
 
 
@@ -145,6 +146,7 @@ public:
 
        CPPUNIT_ASSERT_EQUAL( 5u, intervals.front().lower_bound() );
        CPPUNIT_ASSERT_EQUAL( 120u, intervals.front().upper_bound() );
+       CPPUNIT_ASSERT_EQUAL( true, intervals.front().changed() );
    } // eo AddIntervalsEmbrace()
 
 
@@ -161,6 +163,7 @@ public:
 
        CPPUNIT_ASSERT_EQUAL( 10u, intervals.front().lower_bound() );
        CPPUNIT_ASSERT_EQUAL( 120u, intervals.front().upper_bound() );
+       CPPUNIT_ASSERT_EQUAL( true, intervals.front().changed() );
    } // eo AddIntervalsJoin1()
 
 
@@ -177,6 +180,7 @@ public:
 
        CPPUNIT_ASSERT_EQUAL( 10u, intervals.front().lower_bound() );
        CPPUNIT_ASSERT_EQUAL( 120u, intervals.front().upper_bound() );
+       CPPUNIT_ASSERT_EQUAL( true, intervals.front().changed() );
    } // eo AddIntervalsJoin1b()
 
 
@@ -204,6 +208,7 @@ public:
 
        CPPUNIT_ASSERT_EQUAL( 10u, intervals.front().lower_bound() );
        CPPUNIT_ASSERT_EQUAL( 250u, intervals.front().upper_bound() );
+       CPPUNIT_ASSERT_EQUAL( true, intervals.front().changed() );
    } // eo AddIntervalsJoin2()
 
 
@@ -220,6 +225,7 @@ public:
 
        CPPUNIT_ASSERT_EQUAL( 10u, intervals.front().lower_bound() );
        CPPUNIT_ASSERT_EQUAL( 100u, intervals.front().upper_bound() );
+       CPPUNIT_ASSERT_EQUAL( false, intervals.front().changed() );
    } // eo SubIntervalsDisjoint()
 
 
@@ -252,6 +258,8 @@ public:
 
        CPPUNIT_ASSERT_EQUAL( 40u, intervals.back().lower_bound() );
        CPPUNIT_ASSERT_EQUAL( 100u, intervals.back().upper_bound() );
+       CPPUNIT_ASSERT_EQUAL( false, intervals.front().changed() );
+       CPPUNIT_ASSERT_EQUAL( true, intervals.back().changed() );
    } // eo SubIntervalsSplit1()
 
 
@@ -267,6 +275,7 @@ public:
 
        CPPUNIT_ASSERT_EQUAL( 20u, intervals.front().lower_bound() );
        CPPUNIT_ASSERT_EQUAL( 100u, intervals.front().upper_bound() );
+       CPPUNIT_ASSERT_EQUAL( true, intervals.front().changed() );
    } // eo SubIntervalsCutFront()
 
 
@@ -282,6 +291,7 @@ public:
 
        CPPUNIT_ASSERT_EQUAL( 10u, intervals.front().lower_bound() );
        CPPUNIT_ASSERT_EQUAL( 87u, intervals.front().upper_bound() );
+       CPPUNIT_ASSERT_EQUAL( true, intervals.front().changed() );
    } // eo SubIntervalsCutBack()
 
 
@@ -302,6 +312,7 @@ public:
 
        CPPUNIT_ASSERT_EQUAL( 220u, intervals.front().lower_bound() );
        CPPUNIT_ASSERT_EQUAL( 300u, intervals.front().upper_bound() );
+       CPPUNIT_ASSERT_EQUAL( true, intervals.front().changed() );
    } // eo SubIntervalsCutMore()