Files CCore/inc/PrintStem.h CCore/src/PrintStem.cpp
This part provides few utility classes to help printing a set of objects. These classes prints "stems" before an actual object. The stem depends of the object position in the set.
Each stem class object can be printed. Each print operation changes the internal state of the object. The actual print result depends on this state. You may reset the state by the method reset().
class PrintFirst : NoCopy
{
mutable bool flag = true ;
StrLen first;
StrLen other;
public:
PrintFirst(StrLen first_,StrLen other_) : first(first_),other(other_) {}
void reset() { flag=true; }
StrLen end(StrLen non_empty,StrLen empty) const { return flag?empty:non_empty; }
// print object
template <class P>
void print(P &out) const;
};
This class prints the first string the first time and the other string otherwise. In other words, the printout is: first other other ...
The method end() selects from two string: non_empty and empty. The empty is selected iff the object has not been printed yet.
class PrintPeriod : NoCopy
{
mutable bool flag = true ;
mutable unsigned count = 0 ;
unsigned period; // > 0
StrLen first;
StrLen next;
StrLen line;
public:
PrintPeriod(unsigned period_,StrLen first_,StrLen next_,StrLen line_) : period(period_),first(first_),next(next_),line(line_) {}
void reset() { flag=true; }
StrLen end(StrLen non_empty,StrLen empty) const { return flag?empty:non_empty; }
// print object
template <class P>
void print(P &out) const;
};
This class has four parameters: period, first, next and line. The printout is: first next ... next ( line next ... next ) ... The length of the line is period. I.e. from first to line and from line to next line there are exact period-1 nexts.
The method end() selects from two string: non_empty and empty. The empty is selected iff the object has not been printed yet.