Skip to content

Commit

Permalink
calendar event iterator bug
Browse files Browse the repository at this point in the history
  • Loading branch information
jdetaeye committed Nov 16, 2018
1 parent 439e690 commit a172646
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 11 deletions.
8 changes: 7 additions & 1 deletion include/frepple/model.h
Original file line number Diff line number Diff line change
Expand Up @@ -484,13 +484,14 @@ class Calendar : public HasName<Calendar>, public HasSource
Calendar* theCalendar = nullptr;
Date curDate;
double curValue = 0.0;
double prevValue = 0.0;
public:
const Date& getDate() const
{
return curDate;
}

double getValue()
double getValue() const
{
return curValue;
}
Expand All @@ -500,6 +501,11 @@ class Calendar : public HasName<Calendar>, public HasSource
return theCalendar;
}

double getPrevValue() const
{
return prevValue;
}

EventIterator(
Calendar* c = nullptr,Date d = Date::infinitePast, bool forward = true
);
Expand Down
5 changes: 4 additions & 1 deletion src/model/calendar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -532,7 +532,7 @@ Calendar::EventIterator::EventIterator
if (cacheiter == theCalendar->eventlist.end())
curValue = theCalendar->getDefault();
else
curValue = cacheiter->second;
curValue = cacheiter->second;
}
else
{
Expand All @@ -544,6 +544,7 @@ Calendar::EventIterator::EventIterator
else
curValue = cacheiter->second;
}
prevValue = curValue;
}


Expand All @@ -564,6 +565,7 @@ Calendar::EventIterator& Calendar::EventIterator::operator++()
}
}
}
prevValue = curValue;
if (cacheiter == theCalendar->eventlist.end())
{
curDate = Date::infiniteFuture;
Expand All @@ -580,6 +582,7 @@ Calendar::EventIterator& Calendar::EventIterator::operator++()

Calendar::EventIterator& Calendar::EventIterator::operator--()
{
prevValue = curValue;
if (cacheiter == theCalendar->eventlist.end())
{
curValue = theCalendar->getDefault();
Expand Down
25 changes: 16 additions & 9 deletions src/model/operation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -256,27 +256,35 @@ DateRange Operation::calculateOperationTime(
bool status = false;
Duration curduration = duration;
while (true)
{
// Check whether all calendars are available
bool available = true;
{
// Find the closest event date
Date selected = forward ? Date::infiniteFuture : Date::infinitePast;
for (auto t = cals.begin(); t != cals.end(); ++t)
{
if (
(forward && t->getDate() < selected)
|| (!forward && t->getDate() > selected)
)
{
selected = t->getDate();
if (forward && available && t->getValue() == 0)
}

// Check whether all calendars are available at the next event date
bool available = true;
if (forward)
{
for (auto t = cals.begin(); t != cals.end() && available; ++t)
{
if (t->getDate() == selected && t->getValue() == 0)
available = false;
else if (t->getDate() != selected && t->getPrevValue() == 0)
available = false;
}
}
if (!forward)
else
{
for (auto t = cals.begin(); t != cals.end(); ++t)
for (auto t = cals.begin(); t != cals.end() && available; ++t)
{
if (available && t->getCalendar()->getValue(selected, forward) == 0)
if (t->getCalendar()->getValue(selected, forward) == 0)
available = false;
}
}
Expand Down Expand Up @@ -390,7 +398,6 @@ DateRange Operation::calculateOperationTime(
--(*t);
}
}

return result;
}

Expand Down

0 comments on commit a172646

Please sign in to comment.