Tomographer  v5.4
Tomographer C++ Framework Documentation
fmt.h File Reference

(v5.4)

Utilities for formatting strings. More...

#include <cstdio>
#include <cstdarg>
#include <chrono>
#include <string>
#include <sstream>
#include <iostream>
#include <utility>
#include <vector>
#include <iomanip>
#include <functional>
#include <tomographer/tools/cxxutil.h>
+ Include dependency graph for fmt.h:
+ This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

class  Tomographer::Tools::BadFmtsFormat
 Exception for bad printf format. More...
 
struct  Tomographer::Tools::hasOStreamOp< T >
 Traits class to see whether an object exposes a "<<" operator overload for std::ostream. More...
 
class  Tomographer::Tools::ConsoleFormatterHelper
 Minimal tool for formatting console stuff with fixed line width. More...
 
class  Tomographer::Tools::SimpleWordWrapper
 
class  Tomographer::Tools::FmtFootnotes
 Helper to format footnotes in Fmt. More...
 

Namespaces

 Tomographer
 Base namespace for the Tomographer project.
 
 Tomographer::Tools
 Various useful tools.
 

Macros

#define streamstr(tokens)
 Utility macro to format stream tokens to a std::string. More...
 
#define streamcstr(tokens)   streamstr(tokens).c_str()
 Utility macro to format stream tokens to a C string. More...
 

Functions

std::string Tomographer::Tools::vfmts (const char *fmt, va_list vl)
 printf- formatting to a std::string, with va_list pointer More...
 
std::string Tomographer::Tools::fmts (const char *fmt,...)
 printf- format to a std::string More...
 
template<typename T >
_Unspecified Tomographer::Tools::streamIfPossible (const T &obj)
 Utility to stream an object, but only if "<<" overload exists. More...
 
template<typename T >
_Unspecified Tomographer::Tools::streamIfPossible (const T &obj, std::string before, std::string after=std::string(), std::string alternative="<"+std::string(typeid(T).name())+">")
 A slightly more sophisticated alternative to streamIfPossible() More...
 
std::string Tomographer::Tools::fmtDuration (double seconds)
 Format a number of seconds into a human-readable string. More...
 
template<typename Rep , typename Period >
std::string Tomographer::Tools::fmtDuration (std::chrono::duration< Rep, Period > dt)
 Format a std::chrono::duration into a human-readable string. More...
 
std::ostreamTomographer::Tools::operator<< (std::ostream &stream, const FmtFootnotes &f)
 

Detailed Description

Utilities for formatting strings.

Definition in file fmt.h.

Macro Definition Documentation

§ streamcstr

#define streamcstr (   tokens)    streamstr(tokens).c_str()

Utility macro to format stream tokens to a C string.

Shorthand for:

streamstr( tokens ).c_str()

Definition at line 161 of file fmt.h.

§ streamstr

#define streamstr (   tokens)
Value:
dynamic_cast<std::ostringstream&>( \
std::ostringstream().seekp(0) << tokens \
).str() \

Utility macro to format stream tokens to a std::string.

Usage example:

std::string s = streamstr("x is = " << x.transpose());

This is typically useful if you want to feed in C++ objects to a printf()-like function.

Definition at line 149 of file fmt.h.