54 #include <boost/static_assert.hpp> 55 #include <boost/format.hpp> 72 accessImpl (std::byte* buffer)
74 return * std::launder (reinterpret_cast<boost::format*> (buffer));
79 destroyImpl (std::byte* buffer)
81 accessImpl(buffer).~format();
90 string placeholder(
"<Error");
93 placeholder += errorMsg;
97 accessImpl(formatter) % placeholder;
103 suppressInsufficientArgumentErrors (std::byte* formatter)
105 using namespace boost::io;
106 accessImpl(formatter).exceptions (all_error_bits ^ too_few_args_bit);
125 static_assert (
sizeof(boost::format) <= FORMATTER_SIZE,
126 "opaque working buffer insufficient " 127 "to hold a boost::format instance. " 128 "Maybe boost implementation change. " 129 "Please verify lib/meta/size-trait.hpp");
131 new(formatter_) boost::format(formatString);
132 suppressInsufficientArgumentErrors (formatter_);
134 catch (boost::io::bad_format_string& syntaxError)
137 ,
_Fmt(
"Format string '%s' is broken") % formatString
138 , LUMIERA_ERROR_FORMAT_SYNTAX);
144 destroyImpl (formatter_);
161 template<
typename VAL>
165 accessImpl(formatter) % val;
168 catch (boost::io::too_many_args& argErr)
170 WARN (progress,
"Format: excess argument '%s' of type «%s» ignored." 172 ,
cStr(typeStr(val)));
174 catch (std::exception& failure)
177 WARN (progress,
"Format: Parameter '%s' causes problems: %s" 185 WARN (progress,
"Format: Unexpected problems accepting format parameter '%s'",
cStr(
toString(val)));
194 template void _Fmt::format (
const char, Implementation&);
195 template void _Fmt::format (
const uchar, Implementation&);
196 template void _Fmt::format (
const int16_t, Implementation&);
197 template void _Fmt::format (
const uint16_t,Implementation&);
198 template void _Fmt::format (
const int32_t, Implementation&);
199 template void _Fmt::format (
const uint32_t,Implementation&);
200 template void _Fmt::format (
const int64_t, Implementation&);
201 template void _Fmt::format (
const uint64_t,Implementation&);
202 template void _Fmt::format (
const float, Implementation&);
203 template void _Fmt::format (
const double, Implementation&);
204 template void _Fmt::format (
const string, Implementation&);
205 template void _Fmt::format (
const void *, Implementation&);
206 template void _Fmt::format (
const char *, Implementation&);
208 template void _Fmt::format (
const long, Implementation&);
209 template void _Fmt::format (
const ulong, Implementation&);
222 _Fmt::operator string() const
224 return accessImpl(formatter_).str();
227 catch (std::exception& failure)
230 WARN (progress,
"Format: Failure to receive formatted result: %s", failure.what());
231 return "<formatting failure>";
236 WARN (progress,
"Format: Unexpected problems while formatting output.");
237 return "<unexpected problems>";
248 operator<< (std::ostream& os,
_Fmt const& fmt)
253 catch(std::exception& failure)
256 WARN (progress,
"Format: Failure when outputting formatted result: %s", failure.what());
257 return os <<
"<formatting failure>";
262 WARN (progress,
"Format: Unexpected problems while producing formatted output.");
263 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.