Commit ba5615af authored by thomas.forbriger's avatar thomas.forbriger Committed by thomas.forbriger
Browse files

added tests and comments

This is a legacy commit from before 2015-03-01.
It may be incomplete as well as inconsistent.
See COPYING.legacy and README.history for details.


SVN Path:     http://gpitrsvn.gpi.uni-karlsruhe.de/repos/TFSoftware/trunk
SVN Revision: 4582
SVN UUID:     67feda4a-a26e-11df-9d6e-31afc202ad0c
parent 901274ec
......@@ -121,15 +121,23 @@ template<class T=int>
RangeStepper(const Trange& range,
const Tvalue& stepsize=1):
Mrange(range), Mstepsize(stepsize), Mcurrent(Mrange.first()) { }
//! \brief return current value
operator Tvalue() const { return(this->current()); }
//! \brief return current value
Tvalue current() const { return(Mcurrent); }
/*! \brief true if stepper is still in range and can return a current
* value
*/
bool valid() const { return(Mcurrent<=Mrange.last()); }
//! \brief true if stepper will still be in range after next advance
bool more() const { return(Mcurrent<=(Mrange.last()-Mstepsize)); }
//! \brief advance to next value and return current value
Tvalue next()
{
if (this->valid()) { Mcurrent += Mstepsize; }
return(this->current());
}
//! \brief advance to next value and return current value
Tvalue operator++() { return(this->next()); }
private:
Trange Mrange;
......
......@@ -87,12 +87,18 @@ namespace tfxx {
Miterator(Mlist.begin()),
Mrangestepper(Trangestepper(*Miterator, Mstepsize))
{ }
//! \brief return current value in range list
Tvalue current() const { return(Mrangestepper.current()); }
//! \brief return current value in range list
operator Tvalue() const { return(this->current()); }
/*! \brief true if stepper is still in range and can return a current
* value
*/
bool valid() const
{
return(Mrangestepper.valid() && (Miterator!=Mlist.end()));
}
//! \brief true if stepper is still in range after next step forward
bool more() const
{
bool retval=this->valid();
......@@ -104,6 +110,7 @@ namespace tfxx {
}
return(retval);
}
//! \bief step forward and return current value
Tvalue next()
{
if (this->valid())
......@@ -119,6 +126,7 @@ namespace tfxx {
}
return(this->current());
}
//! \bief step forward and return current value
Tvalue operator++() { return(this->next()); }
private:
Tlist Mlist;
......
......@@ -116,13 +116,14 @@ int main(int iargc, char* argv[])
CODE( RL.append(R2) );
CODE( RL.append(R3) );
CODE( tfxx::RangeListStepper<int> RLS(RL, 2) );
CODE( while (RLS.more()) { cout << ++RLS << ", "; });
CODE( while (RLS.valid()) { cout << RLS << ", "; ++RLS; });
cout << endl;
CODE( cout << step << endl );
CODE( cout << list << endl );
CODE( tfxx::RangeListStepper<int> RLSs(tfxx::string::rangelist<int>(list), step) );
CODE( while (RLSs.valid()) { cout << RLSs << ", "; ++RLSs; });
cout << endl;
}
/* ----- END OF rangetest.cc ----- */
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment