From d99671ba0efe986e46bf738a1db6991ba9d05295 Mon Sep 17 00:00:00 2001 From: Gunnar Beutner Date: Thu, 14 Mar 2013 07:29:53 +0100 Subject: [PATCH] Implement TimePeriod::RemoveSegment(). --- lib/icinga/icinga.vcxproj.filters | 6 ++++++ lib/icinga/timeperiod.cpp | 22 +++++++++++++++++++++- 2 files changed, 27 insertions(+), 1 deletion(-) diff --git a/lib/icinga/icinga.vcxproj.filters b/lib/icinga/icinga.vcxproj.filters index 590950349..ca0483580 100644 --- a/lib/icinga/icinga.vcxproj.filters +++ b/lib/icinga/icinga.vcxproj.filters @@ -70,6 +70,9 @@ Quelldateien + + Quelldateien + @@ -126,6 +129,9 @@ Headerdateien + + Headerdateien + diff --git a/lib/icinga/timeperiod.cpp b/lib/icinga/timeperiod.cpp index 467869ad6..ca245c272 100644 --- a/lib/icinga/timeperiod.cpp +++ b/lib/icinga/timeperiod.cpp @@ -119,12 +119,32 @@ void TimePeriod::RemoveSegment(double begin, double end) if (!segments) return; + Array::Ptr newSegments = boost::make_shared(); + /* 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(); + 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"); }