Phoxonics  1.0
Object Oriented FDTD Software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
Formatter.hpp
Go to the documentation of this file.
1 /*
2  * Formatter.hpp
3  *
4  * Created on: Oct 25, 2014
5  * Author: nano
6  */
7 
8 #ifndef FORMATTER_HPP_
9 #define FORMATTER_HPP_
10 
11 #include <string> // std::string
12 #include <iostream> // std::cout
13 #include <sstream> // std::stringstream, std::stringbuf
14 
15 namespace phoxonics {
16 namespace common {
17 
18 class Formatter {
19 public:
21  }
22  ;
24  }
25  ;
26 
27  template<typename T>
28  Formatter& operator <<(const T & value) {
29  stream_ << value;
30  return *this;
31  }
32 
33  std::string str() const {
34  return stream_.str();
35  }
36  ;
37 
38  operator std::string() const {
39  return stream_.str();
40  }
41  ;
42 
45  };
46 
48  return stream_.str();
49  }
50 
51 private:
52  std::stringstream stream_;
53 
54  Formatter(const Formatter &);
55  Formatter & operator =(Formatter &);
56 };
57 
58 } /* namespace common */
59 } /* namespace phoxonics */
60 
61 // usage
62 //throw std::runtime_error(Formatter() << foo << 13 << ", bar" << myData);
63 
64 #endif /* FORMATTER_HPP_ */
~Formatter()
Definition: Formatter.hpp:23
Formatter & operator<<(const T &value)
Definition: Formatter.hpp:28
Definition: CommonBase.hpp:14
Formatter()
Definition: Formatter.hpp:20
std::string operator>>(ConvertToString)
Definition: Formatter.hpp:47
ConvertToString
Definition: Formatter.hpp:43
Definition: Formatter.hpp:44
std::string str() const
Definition: Formatter.hpp:33
Definition: Formatter.hpp:18