Inexor
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
StringFormatter.hpp
Go to the documentation of this file.
1 #pragma once
2 
3 #include <sstream>
4 #include <string>
5 
6 namespace inexor {
7 namespace util {
8 
19  protected:
20 
21  std::ostringstream sbuf;
22 
23  StringFormatter() : sbuf(std::ios_base::out | std::ios_base::ate) {}
24 
25  StringFormatter(const StringFormatter& other) : sbuf(std::ostringstream::ate)
26  {
27  sbuf.str(other.sbuf.str()); // TODO move ?? other solution?
28  }
29 
30  public:
32  class FmtMark {
33  public:
34  template <typename T>
37  f << s;
38  return f;
39  }
40  };
41 
42  template <typename T>
44  sbuf << s;
45  return *this;
46  }
47 
48  operator std::string() {
49  return sbuf.str();
50  }
51  };
52 
55  extern StringFormatter::FmtMark fmt;
56 }
57 }
StringFormatter(const StringFormatter &other)
Definition: StringFormatter.hpp:25
Format strings with a one-liner.
Definition: StringFormatter.hpp:18
StringFormatter::FmtMark fmt
Marker that starts formatting a string.
Definition: StringFormatter.cpp:5
StringFormatter()
Definition: StringFormatter.hpp:23
ICOMMAND * f(float *a, float *b), floatret(*a **b)
StringFormatter operator<<(T s)
Definition: StringFormatter.hpp:35
std::ostringstream sbuf
Definition: StringFormatter.hpp:21
StringFormatter & operator<<(T s)
Definition: StringFormatter.hpp:43
char string[MAXSTRLEN]
cube-strings (char arrays of fixed size).
Definition: cube_types.hpp:18
Definition: StringFormatter.hpp:32