107 #ifndef UTIL_FORMAT_STRING_H 108 #define UTIL_FORMAT_STRING_H 124 template<
typename C,
class _TRAITS>
127 using ostream = basic_ostream<char, char_traits<char>>;
141 typedef unsigned char uchar;
160 enum{ FORMATTER_SIZE = lib::meta::SizeTrait::BOOST_FORMAT };
162 typedef char Implementation[FORMATTER_SIZE];
170 template<
typename VAL>
171 static void format (
const VAL, Implementation&);
174 template<
typename VAL,
class SEL =
void>
181 _Fmt (
string formatString);
183 operator string()
const;
185 template<
typename VAL>
187 operator% (VAL
const&);
193 friend bool operator== (
_Fmt const&,
_Fmt const&);
194 friend bool operator== (
_Fmt const&,
string const&);
195 friend bool operator== (
_Fmt const&,
const char *
const);
196 friend bool operator== (
string const& ,
_Fmt const&);
197 friend bool operator== (
const char *
const,
_Fmt const&);
200 friend bool operator != (
_Fmt const& fmt, X
const& x) {
return not (fmt == x); }
202 friend bool operator != (X
const& x,
_Fmt const& fmt) {
return not (x == fmt); }
227 template<
typename VAL>
229 _Fmt::operator% (VAL
const& val)
275 : __and_<__not_<_shall_format_directly<X>>
276 , std::bool_constant<lib::meta::can_convertToString<X>::value>
281 template<
typename SP>
289 template <
typename T,
typename D>
296 template<
typename SP>
298 : __and_<__not_<_shall_convert_toString<SP>>
299 ,_is_smart_wrapper<std::remove_reference_t<std::remove_cv_t<SP>>>
311 TRACE_IF (errID, progress,
"Lumiera errorstate '%s' cleared.", errID);
315 _log_and_stringify (std::exception
const& ex)
318 WARN (progress,
"Error while invoking custom string conversion: %s", ex.what());
320 return string(
"<string conversion failed: ")+ex.what()+
">";
323 return "(formatting failure)";
327 _log_unknown_exception()
331 ERROR (progress,
"Unknown error while invoking custom string conversion. Lumiera error flag = %s", errID);
333 ERROR (progress,
"Unknown error while invoking custom string conversion. No Lumiera error flag set.");
334 return "<Unknown error in string conversion>";
345 template<
typename VAL,
class SEL>
349 dump (VAL
const&, Implementation& impl)
351 format (
"«"+typeStr<VAL>()+
"»", impl);
355 template<
typename VAL>
359 dump (
const VAL *pVal, Implementation& impl)
364 format (BOTTOM_INDICATOR, impl);
372 dump (
const void* address, Implementation& impl)
374 format (address, impl);
382 dump (
const char* cString, Implementation& impl)
384 format (cString? cString : BOTTOM_INDICATOR, impl);
392 dump (
bool yes, Implementation& impl)
394 format (yes?
"true":
"false", impl);
402 dump (
lib::Literal const& literal, Implementation& impl)
404 format (literal.empty()?
"" : literal.c(), impl);
412 dump (
lib::Symbol const& symbol, Implementation& impl)
414 format (symbol.c(), impl);
419 template<
typename VAL>
423 dump (VAL
const& val, Implementation& impl)
425 format (
string(val), impl);
427 catch(std::exception
const& ex)
429 format (_log_and_stringify(ex), impl);
433 format (_log_unknown_exception(), impl);
437 template<
typename SP>
441 dump (SP
const& smP, Implementation& impl)
445 catch(std::exception
const& ex)
447 format (_log_and_stringify(ex), impl);
451 format (_log_unknown_exception(), impl);
457 template<
typename VAL>
461 dump (
const VAL val, Implementation& impl)
472 operator== (
_Fmt const& left,
_Fmt const& right)
474 return string(left) == string(right);
478 operator== (
_Fmt const& fmt,
string const& str)
480 return string(fmt) == str;
484 operator== (
_Fmt const& fmt,
const char *
const cString)
486 return string(fmt) == string(cString);
490 operator== (
string const& str,
_Fmt const& fmt)
496 operator== (
const char *
const cString,
_Fmt const& fmt)
498 return fmt == cString;
Implementation formatter_
ostream & operator<<(ostream &os, const Option &ops)
for outputting the help messages.
Any copy and copy construction prohibited.
inline string literal This is a marker type to indicate that
#define LUMIERA_ERROR_DECLARE(err)
Forward declare an error constant.
A front-end for using printf-style formatting.
helper to prepare parameters for inclusion
Implementation namespace for support and library code.
Token or Atom with distinct identity.
Mix-Ins to allow or prohibit various degrees of copying and cloning.
Metaprogramming definitions to deal with dependency on implementation size and layout.
lumiera_err lumiera_error(void)
Get and clear current error state.
Lumiera error handling (C++ interface).
string typeSymbol()
Short readable type identifier, not necessarily unique or complete.