Files CCore/inc/PrintBits.h CCore/src/PrintBits.cpp
PrintBits() is a Creator function, it is used to bind together a printing device and some unsigned integral value to build the Helper Type PrintBitsType object.
template <class UInt,class P>
PrintBitsType<P,UInt> PrintBits(P &out,UInt value) { return PrintBitsType<P,UInt>(out,value); }
PrintBitsType prints bits of the given value in a textual form.
template <class P,class UInt>
class PrintBitsType
{
P &out;
UInt value;
bool empty;
public:
PrintBitsType(P &out,UInt value);
PrintBitsType<P,UInt> & operator () (UInt flag,StrLen name);
void complete();
};
Here is the usage pattern (from GenFile.h):
PrintBits<uint32>(out,oflags) (Open_Read ,"Read") (Open_Write ,"Write") (Open_Pos ,"Pos") (Open_Create ,"Create") (Open_Erase ,"Erase") (Open_New ,"New") (Open_AutoDelete,"AutoDelete") (Open_PosEnd ,"PosEnd") .complete(); // // Prints like Read|Write|Pos //
And more:
class FileOpenFlagsTextDesc { FileOpenFlags oflags; public: explicit FileOpenFlagsTextDesc(FileOpenFlags oflags_) : oflags(oflags_) {} template <class P> void print(P &out) const { PrintBits<uint32>(out,oflags) (Open_Read ,"Read") (Open_Write ,"Write") (Open_Pos ,"Pos") (Open_Create ,"Create") (Open_Erase ,"Erase") (Open_New ,"New") (Open_AutoDelete,"AutoDelete") (Open_PosEnd ,"PosEnd") .complete(); } }; inline FileOpenFlagsTextDesc GetTextDesc(FileOpenFlags oflags) { return FileOpenFlagsTextDesc(oflags); }