98 #ifndef UTIL_FORMAT_STRING_H 99 #define UTIL_FORMAT_STRING_H 116 template<
typename C,
class _TRAITS>
119 using ostream = basic_ostream<char, char_traits<char>>;
133 typedef unsigned char uchar;
152 enum{ FORMATTER_SIZE = lib::meta::SizeTrait::BOOST_FORMAT };
154 typedef std::byte Implementation[FORMATTER_SIZE];
158 alignas(size_t)
mutable Implementation formatter_;
162 template<
typename VAL>
163 static void format (
const VAL, Implementation&);
166 template<
typename VAL,
class SEL =
void>
173 _Fmt (
string formatString);
175 operator string()
const;
177 template<
typename VAL>
179 operator% (VAL
const&);
185 friend bool operator== (
_Fmt const&,
_Fmt const&);
186 friend bool operator== (
_Fmt const&,
string const&);
187 friend bool operator== (
_Fmt const&,
const char *
const);
188 friend bool operator== (
string const& ,
_Fmt const&);
189 friend bool operator== (
const char *
const,
_Fmt const&);
192 friend bool operator != (
_Fmt const& fmt, X
const& x) {
return not (fmt == x); }
194 friend bool operator != (X
const& x,
_Fmt const& fmt) {
return not (x == fmt); }
219 template<
typename VAL>
221 _Fmt::operator% (VAL
const& val)
267 : __and_<__not_<_shall_format_directly<X>>
268 , std::bool_constant<lib::meta::can_convertToString<X>::value>
273 template<
typename SP>
281 template <
typename T,
typename D>
288 template<
typename SP>
290 : __and_<__not_<_shall_convert_toString<SP>>
291 ,_is_smart_wrapper<std::remove_reference_t<std::remove_cv_t<SP>>>
303 TRACE_IF (errID, progress,
"Lumiera errorstate '%s' cleared.", errID);
307 _log_and_stringify (std::exception
const& ex)
310 WARN (progress,
"Error while invoking custom string conversion: %s", ex.what());
312 return string(
"<string conversion failed: ")+ex.what()+
">";
315 return "(formatting failure)";
319 _log_unknown_exception()
323 ERROR (progress,
"Unknown error while invoking custom string conversion. Lumiera error flag = %s", errID);
325 ERROR (progress,
"Unknown error while invoking custom string conversion. No Lumiera error flag set.");
326 return "<Unknown error in string conversion>";
337 template<
typename VAL,
class SEL>
341 dump (VAL
const&, Implementation& impl)
343 format (
"«"+typeStr<VAL>()+
"»", impl);
347 template<
typename VAL>
351 dump (
const VAL *pVal, Implementation& impl)
356 format (BOTTOM_INDICATOR, impl);
364 dump (
const void* address, Implementation& impl)
366 format (address, impl);
374 dump (
const char* cString, Implementation& impl)
376 format (cString? cString : BOTTOM_INDICATOR, impl);
384 dump (
bool yes, Implementation& impl)
386 format (yes?
"true":
"false", impl);
394 dump (
lib::Literal const& literal, Implementation& impl)
396 format (literal.empty()?
"" : literal.c(), impl);
404 dump (
lib::Symbol const& symbol, Implementation& impl)
406 format (symbol.c(), impl);
411 template<
typename VAL>
415 dump (VAL
const& val, Implementation& impl)
417 format (
string(val), impl);
419 catch(std::exception
const& ex)
421 format (_log_and_stringify(ex), impl);
425 format (_log_unknown_exception(), impl);
429 template<
typename SP>
433 dump (SP
const& smP, Implementation& impl)
437 catch(std::exception
const& ex)
439 format (_log_and_stringify(ex), impl);
443 format (_log_unknown_exception(), impl);
449 template<
typename VAL>
453 dump (
const VAL val, Implementation& impl)
464 operator== (
_Fmt const& left,
_Fmt const& right)
466 return string(left) == string(right);
470 operator== (
_Fmt const& fmt,
string const& str)
472 return string(fmt) == str;
476 operator== (
_Fmt const& fmt,
const char *
const cString)
478 return string(fmt) == string(cString);
482 operator== (
string const& str,
_Fmt const& fmt)
488 operator== (
const char *
const cString,
_Fmt const& fmt)
490 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.