Lumiera
0.pre.03
»edit your freedom«
|
#include "lib/format-string.hpp"
A front-end for using printf-style formatting.
Values to be formatted can be supplied through the operator%. Custom defined string conversions on objects will be used, any errors while invoking the format operation will be suppressed. The implementation is based on boost::format, but kept opaque to keep code size and compilation times down.
Definition at line 157 of file format-string.hpp.
Public Member Functions | |
_Fmt (string formatString) | |
Build a formatter object based on the given format string. More... | |
operator string () const | |
get the formatted result More... | |
template<typename VAL > | |
_Fmt & | operator% (VAL const &) |
The percent operator ('' ) is used do feed parameter values to be included into the formatted result, at the positions marked by printf-style placeholders within the format string. More... | |
Classes | |
struct | Converter |
helper to prepare parameters for inclusion More... | |
struct | Converter< bool > |
struct | Converter< const char * > |
struct | Converter< lib::Literal > |
struct | Converter< lib::Symbol > |
struct | Converter< SP, lib::meta::enable_if< _shall_show_smartWrapper< SP > > > |
struct | Converter< VAL * > |
struct | Converter< VAL, lib::meta::enable_if< _shall_convert_toString< VAL > > > |
some custom types explicitly provide a string representation More... | |
struct | Converter< VAL, lib::meta::enable_if< _shall_format_directly< VAL > > > |
some basic types are directly forwarded down to the implementation; More... | |
struct | Converter< void * > |
Friends | |
template<typename X > | |
bool | operator!= (_Fmt const &fmt, X const &x) |
template<typename X > | |
bool | operator!= (X const &x, _Fmt const &fmt) |
std::ostream & | operator<< (std::ostream &os, _Fmt const &) |
send the formatted buffer directly to the output stream. More... | |
bool | operator== (_Fmt const &, _Fmt const &) |
bool | operator== (_Fmt const &, string const &) |
bool | operator== (_Fmt const &, const char *const) |
bool | operator== (string const &, _Fmt const &) |
bool | operator== (const char *const, _Fmt const &) |
Private Types | |
enum | { FORMATTER_SIZE = lib::meta::SizeTrait::BOOST_FORMAT } |
size of an opaque implementation Buffer | |
typedef std::byte | Implementation[FORMATTER_SIZE] |
Static Private Member Functions | |
template<typename VAL > | |
static void | format (const VAL, Implementation &) |
call into the opaque implementation More... | |
Private Attributes | |
Implementation | formatter_ |
Additional Inherited Members | |
Private Member Functions inherited from NonCopyable | |
NonCopyable (NonCopyable const &)=delete | |
NonCopyable & | operator= (NonCopyable const &)=delete |
_Fmt | ( | string | formatString | ) |
Build a formatter object based on the given format string.
The actual implementation is delegated to an boost::format object, which is placement-constructed into an opaque buffer embedded into this object. Defining the necessary size for this buffer relies on implementation details of boost::format (and might break)
Definition at line 123 of file format-string.cpp.
|
staticprivate |
call into the opaque implementation
access point for the frontend, allowing to push a single parameter value down into the implementation for the actual formatting. Only selected primitive types are handled directly this way, while all custom conversions, the handling of pointers and the fallback (showing a type string) is done in the frontend.
Definition at line 163 of file format-string.cpp.
operator string | ( | ) | const |
get the formatted result
Definition at line 222 of file format-string.cpp.
|
inline |
The percent operator (''
) is used do feed parameter values to be included into the formatted result, at the positions marked by printf-style placeholders within the format string.
void*
. Any other type gets just translated into a type-ID (using the mangled RTTI info). In case of errors during the conversion, a string representation of the error is returned val | arbitrary value or pointer to be included into the result |
Definition at line 230 of file format-string.hpp.
|
mutableprivate |
buffer to hold a boost::format
Definition at line 167 of file format-string.hpp.
|
friend |
send the formatted buffer directly to the output stream.
Definition at line 248 of file format-string.cpp.