Loading...
Searching...
No Matches
Outlet.h
1/*
2 * JavaScript.h
3 *
4 * Created on: Jan 26, 2026
5 * Author: mpeura
6 */
7
8#ifndef DRAIN_UTIL_OUTLET
9#define DRAIN_UTIL_OUTLET
10
11#include <ostream>
12
13//#include <drain/Sprinter.h>
14
15
16namespace drain {
17
18
19class Outlet {
20
21public:
22
23 inline
24 Outlet(std::ostream & ostr) : dst_ostr(ostr), dst_str(dummy_str){
25 }
26
27 inline
28 Outlet(std::string & s) : dst_ostr(sstr), dst_str(s){
29 }
30
31 template <class T>
32 inline
33 std::ostream & operator<<(const T & x) const {
34 dst_ostr << x;
35 return dst_ostr;
36 }
37
38 inline
39 ~Outlet(){
40 //if (&dst_ostr == &sstr){
41 if (&dst_str != &dummy_str){
42 dst_str.assign(sstr.str());
43 }
44 }
45
46 inline
47 std::ostream & getOStream() const {
48 return dst_ostr;
49 }
50
51protected:
52
53 std::ostream & dst_ostr;
54 std::string & dst_str;
55
56 mutable
57 std::string dummy_str;
58
59 mutable
60 std::stringstream sstr;
61
62};
63
64
65
66
67} // drain::
68
69#endif // DRAIN_OUTLET
Definition Outlet.h:19
Definition DataSelector.cpp:1277