Lumiera  0.pre.03
»edit your freedom«
format-string.cpp File Reference

Go to the source code of this file.

Description

Implementation for printf-style formatting, based on boost::format.

This file holds the generic implementation of our format frontend, which actually just invokes boost::format. The corresponding header format-string.hpp provides some template functions and classes, either invoking a custom string conversion, or passing primitive values down unaltered.

Here, we define explicit specialisations for the frontend to invoke, which in turn just pass on the given argument value to the embedded boost::format object, which in turn dumps the formatted result into an embedded string stream.

To avoid exposing boost::format in the frontend header, we use an opaque buffer of appropriate size to piggyback the formatter object.

Warning
unfortunately this requires a hard coded buffer size constant in the front-end, which we define there manually, based on the current implementation layout found in the boost libraries. If Boost eventually changes the implementation, the assertion in our constructor will trigger.
See also
FormatString_test

Definition in file format-string.cpp.

#include "lib/error.hpp"
#include "lib/format-util.hpp"
#include "lib/format-string.hpp"
#include <boost/static_assert.hpp>
#include <boost/format.hpp>
#include <iostream>
#include <cstddef>
#include <new>

Functions

boost::format & accessImpl (std::byte *buffer)
 
void destroyImpl (std::byte *buffer)
 
 LUMIERA_ERROR_DEFINE (FORMAT_SYNTAX, "Syntax error in format string for boost::format")
 
std::ostream & operator<< (std::ostream &os, _Fmt const &fmt)
 send the formatted buffer directly to the output stream. More...
 
void pushFailsafeReplacement (std::byte *formatter, const char *errorMsg=NULL)
 in case the formatting of a (primitive) value fails, we try to supply an error indicator instead
 
void suppressInsufficientArgumentErrors (std::byte *formatter)
 

Namespaces

Function Documentation

◆ operator<<()

std::ostream& util::operator<< ( std::ostream &  os,
_Fmt const &  fmt 
)

send the formatted buffer directly to the output stream.

Note
this is more efficient than creating a string and outputting that, because boost::format internally uses a string-stream to generate the formatted representation, relying on the C++ output framework

Definition at line 248 of file format-string.cpp.