107 #ifndef UTIL_FORMAT_STRING_H 108 #define UTIL_FORMAT_STRING_H 125 template<
typename C,
class _TRAITS>
128 using ostream = basic_ostream<char, char_traits<char>>;
142 typedef unsigned char uchar;
161 enum{ FORMATTER_SIZE = lib::meta::SizeTrait::BOOST_FORMAT };
163 typedef std::byte Implementation[FORMATTER_SIZE];
167 alignas(size_t)
mutable Implementation formatter_;
171 template<
typename VAL>
172 static void format (
const VAL, Implementation&);
175 template<
typename VAL,
class SEL =
void>
182 _Fmt (
string formatString);
184 operator string()
const;
186 template<
typename VAL>
188 operator% (VAL
const&);
194 friend bool operator== (
_Fmt const&,
_Fmt const&);
195 friend bool operator== (
_Fmt const&,
string const&);
196 friend bool operator== (
_Fmt const&,
const char *
const);
197 friend bool operator== (
string const& ,
_Fmt const&);
198 friend bool operator== (
const char *
const,
_Fmt const&);
201 friend bool operator != (
_Fmt const& fmt, X
const& x) {
return not (fmt == x); }
203 friend bool operator != (X
const& x,
_Fmt const& fmt) {
return not (x == fmt); }
228 template<
typename VAL>
230 _Fmt::operator% (VAL
const& val)
276 : __and_<__not_<_shall_format_directly<X>>
277 , std::bool_constant<lib::meta::can_convertToString<X>::value>
282 template<
typename SP>
290 template <
typename T,
typename D>
297 template<
typename SP>
299 : __and_<__not_<_shall_convert_toString<SP>>
300 ,_is_smart_wrapper<std::remove_reference_t<std::remove_cv_t<SP>>>
312 TRACE_IF (errID, progress,
"Lumiera errorstate '%s' cleared.", errID);
316 _log_and_stringify (std::exception
const& ex)
319 WARN (progress,
"Error while invoking custom string conversion: %s", ex.what());
321 return string(
"<string conversion failed: ")+ex.what()+
">";
324 return "(formatting failure)";
328 _log_unknown_exception()
332 ERROR (progress,
"Unknown error while invoking custom string conversion. Lumiera error flag = %s", errID);
334 ERROR (progress,
"Unknown error while invoking custom string conversion. No Lumiera error flag set.");
335 return "<Unknown error in string conversion>";
346 template<
typename VAL,
class SEL>
350 dump (VAL
const&, Implementation& impl)
352 format (
"«"+typeStr<VAL>()+
"»", impl);
356 template<
typename VAL>
360 dump (
const VAL *pVal, Implementation& impl)
365 format (BOTTOM_INDICATOR, impl);
373 dump (
const void* address, Implementation& impl)
375 format (address, impl);
383 dump (
const char* cString, Implementation& impl)
385 format (cString? cString : BOTTOM_INDICATOR, impl);
393 dump (
bool yes, Implementation& impl)
395 format (yes?
"true":
"false", impl);
403 dump (
lib::Literal const& literal, Implementation& impl)
405 format (literal.empty()?
"" : literal.c(), impl);
413 dump (
lib::Symbol const& symbol, Implementation& impl)
415 format (symbol.c(), impl);
420 template<
typename VAL>
424 dump (VAL
const& val, Implementation& impl)
426 format (
string(val), impl);
428 catch(std::exception
const& ex)
430 format (_log_and_stringify(ex), impl);
434 format (_log_unknown_exception(), impl);
438 template<
typename SP>
442 dump (SP
const& smP, Implementation& impl)
446 catch(std::exception
const& ex)
448 format (_log_and_stringify(ex), impl);
452 format (_log_unknown_exception(), impl);
458 template<
typename VAL>
462 dump (
const VAL val, Implementation& impl)
473 operator== (
_Fmt const& left,
_Fmt const& right)
475 return string(left) == string(right);
479 operator== (
_Fmt const& fmt,
string const& str)
481 return string(fmt) == str;
485 operator== (
_Fmt const& fmt,
const char *
const cString)
487 return string(fmt) == string(cString);
491 operator== (
string const& str,
_Fmt const& fmt)
497 operator== (
const char *
const cString,
_Fmt const& fmt)
499 return fmt == cString;
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.
Marker types to indicate a literal string and a Symbol.
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.