CBMC
format.h
Go to the documentation of this file.
1 /*******************************************************************\
2 
3 Module:
4 
5 Author: Daniel Kroening, kroening@kroening.com
6 
7 \*******************************************************************/
8 
9 #ifndef CPROVER_UTIL_FORMAT_H
10 #define CPROVER_UTIL_FORMAT_H
11 
12 #include <iosfwd>
13 #include <sstream>
14 #include <string>
15 
18 template <typename T>
20 {
21 public:
22  explicit format_containert(const T &_o) : o(_o)
23  {
24  }
25 
26  const T &o;
27 };
28 
29 template <typename T>
30 static inline std::ostream &
31 operator<<(std::ostream &os, const format_containert<T> &f)
32 {
33  return format_rec(os, f.o);
34 }
35 
36 template <typename T>
37 static inline format_containert<T> format(const T &o)
38 {
39  return format_containert<T>(o);
40 }
41 
42 template <typename T>
43 std::string format_to_string(const T &o)
44 {
45  std::ostringstream oss;
46  oss << format(o);
47  return oss.str();
48 }
49 
50 #endif // CPROVER_UTIL_FORMAT_H
The below enables convenient syntax for feeding objects into streams, via stream << format(o)
Definition: format.h:20
format_containert(const T &_o)
Definition: format.h:22
const T & o
Definition: format.h:26
std::string format_to_string(const T &o)
Definition: format.h:43
static format_containert< T > format(const T &o)
Definition: format.h:37
static std::ostream & operator<<(std::ostream &os, const format_containert< T > &f)
Definition: format.h:31
static std::ostream & format_rec(std::ostream &os, const multi_ary_exprt &src)
This formats a multi-ary expression, adding parentheses where indicated by bracket_subexpression.
Definition: format_expr.cpp:95