9 #ifndef Tempus_TimeEventRangeIndex_impl_hpp
10 #define Tempus_TimeEventRangeIndex_impl_hpp
15 template<
class Scalar>
17 : start_(0), stop_(0), stride_(1)
19 this->
setName(
"TimeEventRangeIndex");
24 template<
class Scalar>
26 std::string name,
int start,
int stop,
int stride)
29 this->setIndexRange(start, stop, stride);
33 template<
class Scalar>
44 template<
class Scalar>
56 template<
class Scalar>
62 }
else if (stride_ > (stop_ - start_)) {
63 stride_ = stop_ - start_;
69 template<
class Scalar>
72 if (stride_ == 0 || start_ == stop_)
75 numEvents_ = int((stop_ - start_) / stride_) + 1;
79 template<
class Scalar>
82 return (indexToNextEvent(index) == 0);
86 template<
class Scalar>
89 return indexOfNextEvent(index) - index;
93 template<
class Scalar>
97 if (index <= start_)
return start_;
99 const int indexOfLast = start_ + (numEvents_-1) * stride_;
101 if (indexOfLast <= index)
return indexOfLast;
104 if ((index - start_) % stride_ == 0)
return index;
106 const int numStrides = (index - start_) / stride_ + 1;
107 const Scalar indexOfNext = start_ + numStrides * stride_;
112 template<
class Scalar>
115 if (index1 > index2) {
121 const Scalar indexOfLast = start_ + (numEvents_-1) * stride_;
122 if (index2 < start_ || indexOfLast < index1)
return false;
124 Scalar indexEvent1 = indexOfNextEvent(index1);
125 Scalar indexEvent2 = indexOfNextEvent(index2);
127 if (indexEvent1 != indexEvent2)
return true;
130 if (index1 <= indexEvent1 && indexEvent1 <= index2)
return true;
136 template<
class Scalar>
141 *out <<
"TimeEventRange:" <<
"\n"
142 <<
"name = " << this->getName() <<
"\n"
143 <<
"start_ = " << start_ <<
"\n"
144 <<
"stop_ = " << stop_ <<
"\n"
145 <<
"stride_ = " << stride_ <<
"\n"
146 <<
"numEvents_ = " << numEvents_ << std::endl;
152 #endif // Tempus_TimeEventRangeIndex_impl_hpp
virtual void setIndexStart(int start)
virtual void setName(std::string name)
virtual int indexToNextEvent(int index) const
How many indices until the next event. Negative indicating the last event is in the past...
static RCP< FancyOStream > getDefaultOStream()
virtual void setIndexStride(int stride)
virtual void setNumEvents()
virtual void setIndexStop(int stop)
TimeEventRangeIndex()
Default constructor.
virtual void describe() const
Describe member data.
virtual bool eventInRangeIndex(int index1, int index2) const
Test if an event occurs within the index range.
virtual int indexOfNextEvent(int index) const
Index of the next event. Negative indicating the last event is in the past.
virtual bool isIndex(int index) const
Test if index is a time event.