Boost.UI
User Interface Boost library
stream.hpp
Go to the documentation of this file.
1 // Copyright (c) 2018 Kolya Kosenko
2 
3 // Distributed under the Boost Software License, Version 1.0.
4 // See http://www.boost.org/LICENSE_1_0.txt
5 
7 
8 #ifndef BOOST_UI_STREAM_HPP
9 #define BOOST_UI_STREAM_HPP
10 
11 #include <boost/ui/config.hpp>
12 
13 #ifdef BOOST_HAS_PRAGMA_ONCE
14 #pragma once
15 #endif
16 
17 #include <sstream>
18 
19 #include <boost/ui/string.hpp>
20 
21 namespace boost {
22 namespace ui {
23 
26 
27 class BOOST_UI_DECL uiostringstream
28 {
29 public:
32 
34  uiostringstream(const uistring& value) : m_buffer(value) {}
35 
38  {
39  return func(*this);
40  }
41 
44  {
45  m_buffer += to_uistring(value);
46  return *this;
47  }
48  uiostringstream& operator<<(unsigned short value)
49  {
50  m_buffer += to_uistring(value);
51  return *this;
52  }
54  {
55  m_buffer += to_uistring(value);
56  return *this;
57  }
58  uiostringstream& operator<<(unsigned int value)
59  {
60  m_buffer += to_uistring(value);
61  return *this;
62  }
64  {
65  m_buffer += to_uistring(value);
66  return *this;
67  }
68  uiostringstream& operator<<(unsigned long value)
69  {
70  m_buffer += to_uistring(value);
71  return *this;
72  }
73  uiostringstream& operator<<(long long value)
74  {
75  m_buffer += to_uistring(value);
76  return *this;
77  }
78  uiostringstream& operator<<(unsigned long long value)
79  {
80  m_buffer += to_uistring(value);
81  return *this;
82  }
83  uiostringstream& operator<<(float value);
84  uiostringstream& operator<<(double value);
86  {
87  m_buffer += ascii(value ? "1" : "0");
88  return *this;
89  }
91  {
92  m_buffer += value;
93  return *this;
94  }
95  uiostringstream& operator<<(const char* value)
96  {
97  m_buffer += value;
98  return *this;
99  }
100  uiostringstream& operator<<(const std::string& value)
101  {
102  m_buffer += value;
103  return *this;
104  }
105  uiostringstream& operator<<(wchar_t value)
106  {
107  m_buffer += value;
108  return *this;
109  }
110  uiostringstream& operator<<(const wchar_t* value)
111  {
112  m_buffer += value;
113  return *this;
114  }
115  uiostringstream& operator<<(const std::wstring& value)
116  {
117  m_buffer += value;
118  return *this;
119  }
120 #ifndef BOOST_NO_CXX11_CHAR16_T
121  uiostringstream& operator<<(char16_t value)
122  {
123  m_buffer += value;
124  return *this;
125  }
126  uiostringstream& operator<<(const char16_t* value)
127  {
128  m_buffer += value;
129  return *this;
130  }
131  uiostringstream& operator<<(const std::u16string& value)
132  {
133  m_buffer += value;
134  return *this;
135  }
136 #endif
137 #ifndef BOOST_NO_CXX11_CHAR32_T
138  uiostringstream& operator<<(char32_t value)
139  {
140  m_buffer += value;
141  return *this;
142  }
143  uiostringstream& operator<<(const char32_t* value)
144  {
145  m_buffer += value;
146  return *this;
147  }
148  uiostringstream& operator<<(const std::u32string& value)
149  {
150  m_buffer += value;
151  return *this;
152  }
153 #endif
154  template <class T>
155  uiostringstream& operator<<(const T& value)
156  {
157  std::wostringstream ss;
158  ss << value;
159  m_buffer += ss.str();
160  return *this;
161  }
163 
165  void swap(uiostringstream& other) { m_buffer.swap(other.m_buffer); }
166 
168  uistring str() const { return m_buffer; }
169 
171  void str(const uistring& value) { m_buffer = value; }
172 
173 private:
174  uistring m_buffer;
175 };
176 
177 } // namespace ui
178 } // namespace boost
179 
180 namespace std {
181 
185 
189 {
190  return os << '\n';
191 }
192 
193 } // namespace std
194 
195 #endif // BOOST_UI_STREAM_HPP
boost::ui::uiostringstream::operator<<
uiostringstream & operator<<(unsigned long long value)
Inserts data into stream.
Definition: stream.hpp:78
boost::ui::uistring
Helper class to convert string between UI and application logic only.
Definition: string.hpp:49
boost::ui::uiostringstream::operator<<
uiostringstream & operator<<(unsigned short value)
Inserts data into stream.
Definition: stream.hpp:48
config.hpp
Configuration options.
boost::ui::uiostringstream::operator<<
uiostringstream & operator<<(long long value)
Inserts data into stream.
Definition: stream.hpp:73
boost
Boost C++ libraries namespace.
Definition: window.hpp:19
boost::ui::operator<<
std::basic_ostream< char, Traits > & operator<<(std::basic_ostream< char, Traits > &os, const uistring &str)
Writes string into the stream.
Definition: string_io.hpp:31
boost::ui::uiostringstream::operator<<
uiostringstream & operator<<(unsigned long value)
Inserts data into stream.
Definition: stream.hpp:68
boost::ui::uiostringstream::operator<<
uiostringstream & operator<<(const char16_t *value)
Inserts data into stream.
Definition: stream.hpp:126
boost::ui::uiostringstream::operator<<
uiostringstream & operator<<(const std::u16string &value)
Inserts data into stream.
Definition: stream.hpp:131
string.hpp
String class and operations.
std::endl
boost::ui::uiostringstream & endl(boost::ui::uiostringstream &os)
Manipulator that inserts newline character into stream.
Definition: stream.hpp:188
boost::ui::uiostringstream::operator<<
uiostringstream & operator<<(const T &value)
Inserts data into stream.
Definition: stream.hpp:155
boost::ui::uiostringstream::operator<<
uiostringstream & operator<<(int value)
Inserts data into stream.
Definition: stream.hpp:53
boost::ui::uiostringstream::swap
void swap(uiostringstream &other)
Exchanges contents of the streams.
Definition: stream.hpp:165
boost::ui::uiostringstream::operator<<
uiostringstream & operator<<(const wchar_t *value)
Inserts data into stream.
Definition: stream.hpp:110
boost::ui::uiostringstream::operator<<
uiostringstream & operator<<(char32_t value)
Inserts data into stream.
Definition: stream.hpp:138
boost::ui::uiostringstream::uiostringstream
uiostringstream()
Creates empty stream.
Definition: stream.hpp:31
boost::ui::ascii
uistring ascii(const char *str)
Constructs uistring from 7-bit ASCII encoded string.
Definition: string.hpp:402
boost::ui::uiostringstream::operator<<
uiostringstream & operator<<(const std::wstring &value)
Inserts data into stream.
Definition: stream.hpp:115
boost::ui::uiostringstream::operator<<
uiostringstream & operator<<(char16_t value)
Inserts data into stream.
Definition: stream.hpp:121
boost::ui::uiostringstream::uiostringstream
uiostringstream(const uistring &value)
Creates stream and adds value to it.
Definition: stream.hpp:34
boost::ui::uiostringstream::str
uistring str() const
Returns collected data as a string.
Definition: stream.hpp:168
boost::ui::uiostringstream::operator<<
uiostringstream & operator<<(char value)
Inserts data into stream.
Definition: stream.hpp:90
boost::ui::uiostringstream
Output string stream that collects data for UI.
Definition: stream.hpp:27
boost::ui::uiostringstream::operator<<
uiostringstream & operator<<(long value)
Inserts data into stream.
Definition: stream.hpp:63
boost::ui::to_uistring
uistring to_uistring(int value)
Converts numeric value to uistring.
std
Standard C++ namespace.
Definition: string_io.hpp:117
boost::ui::uiostringstream::operator<<
uiostringstream & operator<<(const std::u32string &value)
Inserts data into stream.
Definition: stream.hpp:148
boost::ui::uiostringstream::operator<<
uiostringstream & operator<<(const std::string &value)
Inserts data into stream.
Definition: stream.hpp:100
boost::ui::uiostringstream::str
void str(const uistring &value)
Resets built-in collected data with value.
Definition: stream.hpp:171
boost::ui::uiostringstream::operator<<
uiostringstream & operator<<(unsigned int value)
Inserts data into stream.
Definition: stream.hpp:58
std::swap
void swap(boost::ui::uistring &a, boost::ui::uistring &b)
Specializes the std::swap algorithm.
Definition: string.hpp:612
boost::ui::uiostringstream::operator<<
uiostringstream & operator<<(const char *value)
Inserts data into stream.
Definition: stream.hpp:95
boost::ui::uiostringstream::operator<<
uiostringstream & operator<<(boost::ui::uiostringstream &(*func)(boost::ui::uiostringstream &))
Process stream manipulator.
Definition: stream.hpp:37
boost::ui::uiostringstream::operator<<
uiostringstream & operator<<(short value)
Inserts data into stream.
Definition: stream.hpp:43
boost::ui::uiostringstream::operator<<
uiostringstream & operator<<(bool value)
Inserts data into stream.
Definition: stream.hpp:85
boost::ui::uiostringstream::operator<<
uiostringstream & operator<<(const char32_t *value)
Inserts data into stream.
Definition: stream.hpp:143
boost::ui::uiostringstream::operator<<
uiostringstream & operator<<(wchar_t value)
Inserts data into stream.
Definition: stream.hpp:105