45 #include <boost/static_assert.hpp> 46 #include <boost/format.hpp> 63 accessImpl (std::byte* buffer)
65 return * std::launder (reinterpret_cast<boost::format*> (buffer));
70 destroyImpl (std::byte* buffer)
72 accessImpl(buffer).~format();
81 string placeholder(
"<Error");
84 placeholder += errorMsg;
88 accessImpl(formatter) % placeholder;
94 suppressInsufficientArgumentErrors (std::byte* formatter)
96 using namespace boost::io;
97 accessImpl(formatter).exceptions (all_error_bits ^ too_few_args_bit);
116 static_assert (
sizeof(boost::format) <= FORMATTER_SIZE,
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");
122 new(formatter_) boost::format(formatString);
123 suppressInsufficientArgumentErrors (formatter_);
125 catch (boost::io::bad_format_string& syntaxError)
128 ,
_Fmt(
"Format string '%s' is broken") % formatString
129 , LUMIERA_ERROR_FORMAT_SYNTAX);
135 destroyImpl (formatter_);
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" 176 WARN (progress,
"Format: Unexpected problems accepting format parameter '%s'",
cStr(
toString(val)));
185 template void _Fmt::format (
const char, Implementation&);
186 template void _Fmt::format (
const uchar, 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&);
200 template void _Fmt::format (
const ulong, 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>";
239 operator<< (std::ostream& os,
_Fmt const& fmt)
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>";
static void format(const VAL, Implementation &)
call into the opaque implementation
Implementation formatter_
_Fmt(string formatString)
Build a formatter object based on the given format string.
CStr cStr(std::string const &rendered)
convenience shortcut: forced conversion to c-String via string.
#define ERROR_LOG_AND_IGNORE(_FLAG_, _OP_DESCR_)
convenience shortcut for a sequence of catch blocks just logging and consuming an error...
A front-end for using printf-style formatting.
Derived specific exceptions within Lumiera's exception hierarchy.
Lumiera error handling (C++ interface).
#define LUMIERA_ERROR_DEFINE(err, msg)
Definition and initialisation of an error constant.