The type of an expression that can be printed using operator <<. More...
#include <fmtio.h>
Public Member Functions | |
cs (char const *cs) | |
Begin a conversion sequence that contains one or more % operators to define the variables of interest. For example: | |
operator std::string const & () const | |
template<class T , int N> | |
cs const & | operator% (T const (&rhs)[N]) const |
Used to print any type. Triggered by the following syntax is used: | |
cs const & | operator% (char const *rhs) const |
Used to print any type. Triggered by the following syntax is used: | |
template<class T > | |
cs const & | operator% (T const &rhs) const |
Used to print any type. Triggered by the following syntax is used: | |
size_t | size () const |
~cs () | |
Private Member Functions | |
void | advanceFormat () const |
Consume text from the control string until the next '' character and append the text to the output buffer. | |
cs (cs const &) | |
bool | isIntegralFormat () const |
Return true if the current expectedFormat_ is an integral format. | |
template<class T > | |
void | operator<< (T &) const |
template<class T > | |
void | output (T const &t, printableType::UserDefined) const |
Used to print user defined types. | |
template<class T > | |
void | output (T const &t, printableType::DoubleFloat) const |
Used to print doubles. | |
template<class T > | |
void | output (T const &t, printableType::Float) const |
Used to print floats. | |
template<class T > | |
void | output (T const &t, printableType::StlString) const |
Used to print std::string. | |
template<class T > | |
void | output (T const &t, printableType::String) const |
Used to print char const *, and unsigned char const *. | |
template<class T > | |
void | output (T const &t, printableType::Char) const |
Used to print character data. | |
template<class T > | |
void | output (T const &t, printableType::Unsigned) const |
Used to output unsigned integral data types like unsigned int, unsigned short, unsigned char, etc. | |
template<class T > | |
void | output (T const &t, printableType::Integral) const |
Used to output signed integral data types like int, short, long, unsigned, long long, etc. | |
void | outputFloat (double d) const |
Generalized floating point print routine. | |
void | outputIntegral (long long t) const |
General purpose integer output routine. | |
void | reset () const |
Reset the field formatting fields to their default state. | |
Private Attributes | |
std::string | buffer_ |
char const * | cs_ |
char | expectedFormat_ |
int | fieldWidth_ |
int | fillChar_ |
int | left_ |
int | precision_ |
The type of an expression that can be printed using operator <<.
This class behaves similarly to boost::format() but runs about 3 times faster.
Expressions of this type are constructed like this:
fmtio::cs("%d-%d") % 13 % 14
When printed using cout, you will see text of the form:
13-14
You can also you expressions of this type to populate string variables:
string fred = fmtio::cs("%-04x") % 8;
In this case, fred is initialized with 0008.
Variables of this type are only minimally useful -- the general idea is that you use the constructor, cs(char const *), as passed in an cout expression to construct formatted output in a manner that is easier to use than if you had used the iomanip header file contents to do the same job.
For example:
cout << fmtio::cs("Stuff: %-08.4f") % 9.3 << endl;
In this case, the sub-expression, cs(...) % 9.3, is converted into a string which is then printed as: Stuff: 0009.300.
Most builtin types can all be sent to ostreams or converted into strings by this class.
User defined struct and classes can only be processed if there is an operator<<(std::ostream,...) defined for them.
Pointers and arrays are automatically treated as integers. You can use x to print them as hex.
Enumerations are not at this time usable. Convert them to integers. For example:
#include <iostream> #include <fmtio/fmtio.h> enum stuff { enum1 }; int main() { std::cout << fmtio::cs("%d") % enum1 << std::endl; // WILL NOT COMPILE! std::cout << fmtio::cs("%d") % int(enum1) << std::endl; // works ok }
The control strings are simplified form of printf -- basically all you get is this:
sprintf is used to generate most of the strings, but floats and and user defined types are printed using operator<< into a stringstream.
The conversion characters are as follows:
Multiple % operators can be used with a given cs() but multiple % conversions must be specified when this occurs and they must correcly the match the basic data type as detected by the classifer() methods. Here's an example of one that works:
cout << fmtio::cs("%s %d %x") %"stringdata" %integerVariable %integerVariable << endl;
And here is an invalid example:
cout << fmtio::cs("%s %d %x") %1.0 %integerVariable %integerVariable << endl;
In this invalid example, s is specified but a floating point data type is actually supplied for the first parameter.
All the parameters must be matched and they must all be correct.
Definition at line 212 of file fmtio.h.
cs | ( | char const * | cs | ) |
void advanceFormat | ( | ) | const [private] |
bool isIntegralFormat | ( | ) | const [private] |
cs const& operator% | ( | T const (&) | rhs[N] | ) | const |
Used to print any type. Triggered by the following syntax is used:
This member assumes that the cs will have been constructed with the appropriate % conversion character in the correct position for this "%someObject" to match it.
cs const& operator% | ( | char const * | rhs | ) | const |
cs const& operator% | ( | T const & | rhs | ) | const |
Used to print any type. Triggered by the following syntax is used:
This member assumes that the cs will have been constructed with the appropriate % conversion character in the correct position for this "%someObject" to match it.
Definition at line 730 of file fmtio.h.
void operator<< | ( | T & | ) | const [private] |
void output | ( | T const & | t, | |
printableType::UserDefined | ||||
) | const [private] |
void output | ( | T const & | t, | |
printableType::DoubleFloat | ||||
) | const [private] |
void output | ( | T const & | t, | |
printableType::Float | ||||
) | const [private] |
void output | ( | T const & | t, | |
printableType::StlString | ||||
) | const [private] |
void output | ( | T const & | t, | |
printableType::String | ||||
) | const [private] |
void output | ( | T const & | t, | |
printableType::Char | ||||
) | const [private] |
void output | ( | T const & | t, | |
printableType::Unsigned | ||||
) | const [private] |
void output | ( | T const & | t, | |
printableType::Integral | ||||
) | const [private] |
void outputFloat | ( | double | d | ) | const [private] |
void outputIntegral | ( | long long | t | ) | const [private] |
void reset | ( | ) | const [private] |
char expectedFormat_ [mutable, private] |
int fieldWidth_ [mutable, private] |
int precision_ [mutable, private] |