45#include <boost/static_assert.hpp>
46#include <boost/format.hpp>
65 return * std::launder (
reinterpret_cast<boost::format*
> (buffer));
81 string placeholder(
"<Error");
84 placeholder += errorMsg;
94 suppressInsufficientArgumentErrors (
std::
byte* formatter)
96 using namespace boost::io;
97 accessImpl(formatter).exceptions (all_error_bits ^ too_few_args_bit);
117 "opaque working buffer insufficient "
118 "to hold a boost::format instance. "
119 "Maybe boost implementation change. "
120 "Please verify lib/meta/size-trait.hpp");
123 suppressInsufficientArgumentErrors (
formatter_);
125 catch (boost::io::bad_format_string& syntaxError)
128 ,
_Fmt(
"Format string '%s' is broken") % formatString
129 , LUMIERA_ERROR_FORMAT_SYNTAX);
152 template<
typename VAL>
156 accessImpl(formatter) % val;
159 catch (boost::io::too_many_args& argErr)
161 WARN (progress,
"Format: excess argument '%s' of type «%s» ignored."
163 ,
cStr(typeStr(val)));
165 catch (std::exception& failure)
168 WARN (progress,
"Format: Parameter '%s' causes problems: %s"
169 ,
cStr(toString(val))
171 pushFailsafeReplacement (formatter, failure.what());
176 WARN (progress,
"Format: Unexpected problems accepting format parameter '%s'",
cStr(
toString(val)));
185 template void _Fmt::format (
const char, Implementation&);
187 template void _Fmt::format (
const int16_t, Implementation&);
188 template void _Fmt::format (
const uint16_t,Implementation&);
189 template void _Fmt::format (
const int32_t, Implementation&);
190 template void _Fmt::format (
const uint32_t,Implementation&);
191 template void _Fmt::format (
const int64_t, Implementation&);
192 template void _Fmt::format (
const uint64_t,Implementation&);
193 template void _Fmt::format (
const float, Implementation&);
194 template void _Fmt::format (
const double, Implementation&);
195 template void _Fmt::format (
const string, Implementation&);
196 template void _Fmt::format (
const void *, Implementation&);
197 template void _Fmt::format (
const char *, Implementation&);
199 template void _Fmt::format (
const long, Implementation&);
213 _Fmt::operator string() const
215 return accessImpl(formatter_).str();
218 catch (std::exception& failure)
221 WARN (progress,
"Format: Failure to receive formatted result: %s", failure.what());
222 return "<formatting failure>";
227 WARN (progress,
"Format: Unexpected problems while formatting output.");
228 return "<unexpected problems>";
244 catch(std::exception& failure)
247 WARN (progress,
"Format: Failure when outputting formatted result: %s", failure.what());
248 return os <<
"<formatting failure>";
253 WARN (progress,
"Format: Unexpected problems while producing formatted output.");
254 return os <<
"<unexpected problems>";
A front-end for using printf-style formatting.
Implementation formatter_
static void format(const VAL, Implementation &)
call into the opaque implementation
_Fmt(string formatString)
Build a formatter object based on the given format string.
#define LUMIERA_ERROR_DEFINE(err, msg)
Definition and initialisation of an error constant.
Lumiera error handling (C++ interface).
#define ERROR_LOG_AND_IGNORE(_FLAG_, _OP_DESCR_)
convenience shortcut for a sequence of catch blocks just logging and consuming an error.
LumieraError< LERR_(FATAL), Logic > Fatal
std::ostream & operator<<(std::ostream &os, _Fmt const &fmt)
send the formatted buffer directly to the output stream.
std::string toString(TY const &val) noexcept
get some string representation of any object, reliably.
CStr cStr(std::string const &rendered)
convenience shortcut: forced conversion to c-String via string.