Jpp test-rotations-old
the software that should make you happy
Loading...
Searching...
No Matches
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
10/**
11 * \file
12 * I/O formatting auxiliaries.
13 * \author mdejong
14 */
15namespace JEEP {}
16namespace JPP { using namespace JEEP; }
17
18
19namespace JEEP {
20
21 /**
22 * Get output stream for conversion to std::string.
23 *
24 * Note that the stream is emptied before use.
25 *
26 * \return output stream
27 */
28 inline std::ostream& getOstream()
29 {
30 static std::ostringstream buffer;
31
32 buffer.str("");
33
34 return buffer;
35 }
36
37
38 /**
39 * Get output C-string.
40 *
41 * Note that this method is needed to guarentee livetime of underlying std::string.
42 *
43 * \param input input
44 * \return C-string
45 */
46 inline const char* getCString(const std::string& input)
47 {
48 static std::string buffer;
49
50 buffer = input;
51
52 return buffer.c_str();
53 }
54}
55
56
57/**
58 * Make string.
59 *
60 * \param A std::ostream compatible construct
61 * \return std::string
62 */
63#define MAKE_STRING(A) (static_cast<std::ostringstream&>(JEEP::getOstream() << A << std::flush)).str()
64
65
66/**
67 * Make C-string.
68 *
69 * \param A std::ostream compatible construct
70 * \return C-string
71 */
72#define MAKE_CSTRING(A) JEEP::getCString(MAKE_STRING(A))
73
74#endif
General puprpose classes and methods.
std::ostream & getOstream()
Get output stream for conversion to std::string.
Definition JPrint.hh:28
const char * getCString(const std::string &input)
Get output C-string.
Definition JPrint.hh:46
This name space includes all other name spaces (except KM3NETDAQ, KM3NET and ANTARES).