Tomographer  v2.0
Tomographer C++ Framework Documentation
fmt.h File Reference

(v2.0)

Utilities for formatting strings. More...

#include <cstdio>
#include <cstdarg>
#include <chrono>
#include <string>
#include <sstream>
#include <iostream>
#include <utility>
#include <tomographer2/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...
 

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...
 

Detailed Description

Utilities for formatting strings.

Definition in file fmt.h.

Macro Definition Documentation

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

Utility macro to format stream tokens to a C string.

Shorthand for:

1 streamstr( tokens ).c_str()

Definition at line 157 of file fmt.h.

#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:

1 Eigen::VectorXd x = ...;
2 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 145 of file fmt.h.