Lumiera 0.pre.04~rc.1
»edit your freedom«
Loading...
Searching...
No Matches
format-obj.hpp File Reference

Simple functions to represent objects, for debugging and diagnostics. More...

Go to the source code of this file.

Description

Simple functions to represent objects, for debugging and diagnostics.

The helpers provided here are rather commonplace, but written in a way to incur only modest header inclusion load. It should be OK to use them even on interface headers in widespread use.

  • util::toString() performs a failsafe to-String conversion, thereby preferring a built-in conversion operator, falling back to a lexical conversion (boost) or just an unmangled and simplified type string as default.
  • util::typedString() combines this with an always visible type display
  • lib::meta::demangleCxx() uses the built-in compiler support to translate a mangled type-ID (as given by typeid(TY).name()) into a readable, fully qualified C++ type name. This is only supported for GNU compatible compilers.

    Todo:
    is it possible to stash away the boost::lexical_cast behind a custom facade, the way we did it for boost::format? This would reduce inclusion cost...
See also
FormatHelper_test
frontend for boost::format, printf-style

Definition in file format-obj.hpp.

#include "lib/symbol.hpp"
#include "lib/meta/trait.hpp"
#include <boost/lexical_cast.hpp>

Namespaces

namespace  std
 STL namespace.
 
namespace  lib
 Implementation namespace for support and library code.
 
namespace  lib::meta
 
namespace  util
 
namespace  util::anonymous_namespace{format-obj.hpp}
 

Typedefs

using ostream = basic_ostream< char, char_traits< char > >
 
template<typename X >
using enable_LexicalConversion = lib::meta::enable_if< lib::meta::use_LexicalConversion< X > >
 toggle to prefer specialisation with direct lexical conversion
 
template<typename SP >
using show_SmartPointer = lib::meta::enable_if< lib::meta::is_smart_ptr< typename lib::meta::Strip< SP >::TypeReferred > >
 

Classes

struct  StringConv< X, enable_LexicalConversion< X > >
 
struct  StringConv< SP, show_SmartPointer< SP > >
 
struct  StringConv< double >
 explicit specialisation to control precision of double values. More...
 
struct  StringConv< float >
 
struct  StringConv< bool >
 

Functions

string demangleCxx (Literal rawName)
 Fallback type-ID:
 
string humanReadableTypeID (lib::Literal)
 pretty-print an internal C++ type representation
 
string primaryTypeComponent (lib::Literal)
 extract core name component from a raw type spec
 
string sanitisedFullTypeName (lib::Literal)
 build a sanitised ID from full type name
 
string showDouble (double) noexcept
 pretty-print a double in (rounded) fixed-point format
 
string showFloat (float val) noexcept
 
string showSize (size_t val) noexcept
 
string showAdr (void const *addr) noexcept
 pretty-print an address as hex-suffix
 
ostream & showAdr (std::ostream &, void const *addr)
 preconfigured format for pretty-printing of addresses
 
string showHash (size_t hash, uint showBytes=8) noexcept
 renders the size_t in hex, optionally only trailing bytes
 
std::string showHashLSB (size_t hash) noexcept
 
string showDecimal (double) noexcept
 show maximum reproducible decimal representation
 
string showDecimal (float val) noexcept
 
string showDecimal (f128 val) noexcept
 
string showComplete (double) noexcept
 show enough decimal digits to represent every distinct value
 
string showComplete (float val) noexcept
 
string showComplete (f128 val) noexcept
 
template<typename TY >
std::string toString (TY const &val) noexcept
 get some string representation of any object, reliably.
 
template<typename TY >
std::string typedString (TY const &val) noexcept
 indicate type and possibly a (custom) conversion to string