Jpp  18.2.1
the software that should make you happy
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
JPrint.hh
Go to the documentation of this file.
1 #ifndef __JEEP__JPRINT__
2 #define __JEEP__JPRINT__
3 
4 #include <string>
5 #include <ostream>
6 #include <sstream>
7 #include <iomanip>
8 
9 #include "JLang/JManip.hh"
10 #include "Jeep/JStreamToolkit.hh"
11 
12 
13 /**
14  * \file
15  * I/O formatting auxiliaries.
16  * \author mdejong
17  */
18 namespace JEEP {}
19 namespace JPP { using namespace JEEP; }
20 
21 
22 namespace JEEP {
23 
24  /**
25  * Get output stream for conversion to std::string.
26  *
27  * Note that the stream is emptied before use.
28  *
29  * \return output stream
30  */
31  inline std::ostream& getOstream()
32  {
33  static std::ostringstream buffer;
34 
35  buffer.str("");
36 
37  return buffer;
38  }
39 
40 
41  /**
42  * Get output C-string.
43  *
44  * Note that this method is needed to guarentee livetime of underlying std::string.
45  *
46  * \param input input
47  * \return C-string
48  */
49  inline const char* getCString(const std::string& input)
50  {
51  static std::string buffer;
52 
53  buffer = input;
54 
55  return buffer.c_str();
56  }
57 }
58 
59 /**
60  * Auxiliary data structure for streaming of STL containers.
61  *
62  * This manipulator transfers the following stream operation to method JEEP::writeObject
63  * so that all STL containers can directly be printed.
64  */
65 struct JEEPZ
66 {
67 protected:
68  /**
69  * Auxiliary class for format STL containers.
70  */
71  struct JStream
72  {
73  /**
74  * Constructor.
75  *
76  * \param out output stream
77  */
78  JStream(std::ostream& out) :
79  out(out)
80  {}
81 
82 
83  /**
84  * Write value to output stream.
85  *
86  * \param value value
87  * \return this JSTDStreamer
88  */
89  template<class T>
90  std::ostream& operator<<(const T& value)
91  {
92  return JEEP::writeObject(out, value);
93  }
94 
95  private:
96  std::ostream& out;
97  };
98 
99 public:
100  /**
101  * Default constructor.
102  */
104  {}
105 
106 
107  /**
108  * Format specifier.
109  *
110  * \param out output stream
111  * \param format format
112  * \return output stream
113  */
114  friend inline JStream operator<<(std::ostream& out, const JEEPZ& format)
115  {
116  return JStream(out);
117  }
118 };
119 
120 
121 /**
122  * Make string.
123  *
124  * \param A std::ostream compatible construct
125  * \return std::string
126  */
127 #define MAKE_STRING(A) (static_cast<std::ostringstream&>(JEEP::getOstream() << A << std::flush)).str()
128 
129 
130 /**
131  * Make C-string.
132  *
133  * \param A std::ostream compatible construct
134  * \return C-string
135  */
136 #define MAKE_CSTRING(A) JEEP::getCString(MAKE_STRING(A))
137 
138 #endif
std::ostream & out
Definition: JPrint.hh:96
friend JStream operator<<(std::ostream &out, const JEEPZ &format)
Format specifier.
Definition: JPrint.hh:114
const char * getCString(const std::string &input)
Get output C-string.
Definition: JPrint.hh:49
std::ostream & getOstream()
Get output stream for conversion to std::string.
Definition: JParser.hh:70
JEEPZ()
Default constructor.
Definition: JPrint.hh:103
std::ostream & operator<<(const T &value)
Write value to output stream.
Definition: JPrint.hh:90
do set_variable OUTPUT_DIRECTORY $WORKDIR T
then awk string
Auxiliary data structure for streaming of STL containers.
Definition: JPrint.hh:65
I/O manipulators.
JStream(std::ostream &out)
Constructor.
Definition: JPrint.hh:78
Auxiliary class for format STL containers.
Definition: JPrint.hh:71
std::ostream & writeObject(std::ostream &out, const T &object)
Stream output of object.