]> granicus.if.org Git - icinga2/commitdiff
Implement TimePeriod::RemoveSegment().
authorGunnar Beutner <gunnar@beutner.name>
Thu, 14 Mar 2013 06:29:53 +0000 (07:29 +0100)
committerGunnar Beutner <gunnar@beutner.name>
Thu, 14 Mar 2013 06:29:53 +0000 (07:29 +0100)
lib/icinga/icinga.vcxproj.filters
lib/icinga/timeperiod.cpp

index 5909503497dd0f9ac0dec4bef525003cd9eb71e2..ca04835806eb40d2832838318888b9f33cf83b68 100644 (file)
@@ -70,6 +70,9 @@
     <ClCompile Include="icinga-type.cpp">
       <Filter>Quelldateien</Filter>
     </ClCompile>
+    <ClCompile Include="timeperiod.cpp">
+      <Filter>Quelldateien</Filter>
+    </ClCompile>
   </ItemGroup>
   <ItemGroup>
     <ClInclude Include="i2-icinga.h">
     <ClInclude Include="usergroup.h">
       <Filter>Headerdateien</Filter>
     </ClInclude>
+    <ClInclude Include="timeperiod.h">
+      <Filter>Headerdateien</Filter>
+    </ClInclude>
   </ItemGroup>
   <ItemGroup>
     <Filter Include="Headerdateien">
index 467869ad6ea8d07a3fa9f0e017ca9bb26c00d708..ca245c272ae1e81ec261bd4c04d66113cb90e51b 100644 (file)
@@ -119,12 +119,32 @@ void TimePeriod::RemoveSegment(double begin, double end)
        if (!segments)
                return;
 
+       Array::Ptr newSegments = boost::make_shared<Array>();
+
        /* Try to split or adjust an existing segment. */
        ObjectLock dlock(segments);
        BOOST_FOREACH(const Dictionary::Ptr& segment, segments) {
-               BOOST_THROW_EXCEPTION(runtime_error("Not implemented."));
+               /* Fully contained in the specified range? */
+               if (segment->Get("begin") >= begin && segment->Get("end") <= end)
+                       continue;
+
+               /* Not overlapping at all? */
+               if (segment->Get("end") < begin || segment->Get("begin") > end) {
+                       newSegments->Add(segment);
+
+                       continue;
+               }
+
+               /* Create a new segment and adjust its begin/end timestamps
+                * so as to not overlap with the specified range. */
+               Dictionary::Ptr newSegment = boost::make_shared<Dictionary>();
+               newSegment->Set("begin", (segment->Get("begin") < end) ? end : segment->Get("begin"));
+               newSegment->Set("end", (segment->Get("end") > begin) ? begin : segment->Get("end"));
+
+               newSegments->Add(newSegment);
        }
 
+       m_Segments = newSegments;
        Touch("segments");
 }