Boost.UI
User Interface Boost library
string_io.hpp
Go to the documentation of this file.
1 // Copyright (c) 2017 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_STRING_IO_HPP
9 #define BOOST_UI_STRING_IO_HPP
10 
11 #include <boost/ui/config.hpp>
12 
13 #ifdef BOOST_HAS_PRAGMA_ONCE
14 #pragma once
15 #endif
16 
17 #include <boost/ui/string.hpp>
18 
19 #include <ostream>
20 #include <istream>
21 
22 namespace boost {
23 namespace ui {
24 
27 
28 #ifndef BOOST_UI_NO_STRING_DESTRUCTIVE
29 template <class Traits>
30 std::basic_ostream<char, Traits>&
31 operator<<(std::basic_ostream<char, Traits>& os, const uistring& str)
32 {
33  return os << str.string();
34 }
35 #endif
36 
37 template <class Traits>
38 std::basic_ostream<wchar_t, Traits>&
39 operator<<(std::basic_ostream<wchar_t, Traits>& os, const uistring& str)
40 {
41  return os << str.wstring();
42 }
43 
44 #ifndef BOOST_NO_CXX11_CHAR16_T
45 template <class Traits>
46 std::basic_ostream<char16_t, Traits>&
47 operator<<(std::basic_ostream<char16_t, Traits>& os, const uistring& str)
48 {
49  return os << str.u16string();
50 }
51 #endif
52 
53 #ifndef BOOST_NO_CXX11_CHAR32_T
54 template <class Traits>
55 std::basic_ostream<char32_t, Traits>&
56 operator<<(std::basic_ostream<char32_t, Traits>& os, const uistring& str)
57 {
58  return os << str.u32string();
59 }
60 #endif
61 
63 
66 #ifndef BOOST_UI_NO_CAST_FROM_ASCII
67 template <class Traits>
68 std::basic_istream<char, Traits>&
69 operator>>(std::basic_istream<char, Traits>& is, ui::uistring& str)
70 {
71  std::string temp;
72  is >> temp;
73  str = temp;
74  return is;
75 }
76 #endif
77 
78 template <class Traits>
79 std::basic_istream<wchar_t, Traits>&
80 operator>>(std::basic_istream<wchar_t, Traits>& is, ui::uistring& str)
81 {
82  std::wstring temp;
83  is >> temp;
84  str = temp;
85  return is;
86 }
87 
88 #ifndef BOOST_NO_CXX11_CHAR16_T
89 template <class Traits>
90 std::basic_istream<char16_t, Traits>&
91 operator>>(std::basic_istream<char16_t, Traits>& is, ui::uistring& str)
92 {
93  std::u16string temp;
94  is >> temp;
95  str = temp;
96  return is;
97 }
98 #endif
99 
100 #ifndef BOOST_NO_CXX11_CHAR32_T
101 template <class Traits>
102 std::basic_istream<char32_t, Traits>&
103 operator>>(std::basic_istream<char32_t, Traits>& is, ui::uistring& str)
104 {
105  std::u32string temp;
106  is >> temp;
107  str = temp;
108  return is;
109 }
110 #endif
111 
113 
114 } // namespace ui
115 } // namespace boost
116 
117 namespace std {
118 
121 #ifndef BOOST_UI_NO_CAST_FROM_ASCII
122 template <class Traits>
123 std::basic_istream<char, Traits>&
124 getline(std::basic_istream<char, Traits>& is, boost::ui::uistring& str, char ch = '\n')
125 {
126  std::string temp;
127  std::getline(is, temp, ch);
128  str = temp;
129  return is;
130 }
131 #endif
132 
133 template <class Traits>
134 std::basic_istream<wchar_t, Traits>&
135 getline(std::basic_istream<wchar_t, Traits>& is, boost::ui::uistring& str, wchar_t ch = L'\n')
136 {
137  std::wstring temp;
138  std::getline(is, temp, ch);
139  str = temp;
140  return is;
141 }
142 
143 #ifndef BOOST_NO_CXX11_CHAR16_T
144 template <class Traits>
145 std::basic_istream<char16_t, Traits>&
146 getline(std::basic_istream<char16_t, Traits>& is, boost::ui::uistring& str, char16_t ch = u'\n')
147 {
148  std::u16string temp;
149  std::getline(is, temp, ch);
150  str = temp;
151  return is;
152 }
153 #endif
154 
155 #ifndef BOOST_NO_CXX11_CHAR32_T
156 template <class Traits>
157 std::basic_istream<char32_t, Traits>&
158 getline(std::basic_istream<char32_t, Traits>& is, boost::ui::uistring& str, char32_t ch = U'\n')
159 {
160  std::u32string temp;
161  std::getline(is, temp, ch);
162  str = temp;
163  return is;
164 }
165 #endif
166 
168 
169 } // namespace std
170 
171 #endif // BOOST_UI_STRING_IO_HPP
boost::ui::uistring
Helper class to convert string between UI and application logic only.
Definition: string.hpp:49
boost::ui::operator>>
std::basic_istream< char, Traits > & operator>>(std::basic_istream< char, Traits > &is, ui::uistring &str)
Reads string from the stream.
Definition: string_io.hpp:69
config.hpp
Configuration options.
boost::ui::uistring::u32string
std::u32string u32string() const
Returns UTF-32 std::u32string.
Definition: string.hpp:299
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
std::getline
std::basic_istream< char, Traits > & getline(std::basic_istream< char, Traits > &is, boost::ui::uistring &str, char ch='\n')
Reads characters from the stream into the string.
Definition: string_io.hpp:124
string.hpp
String class and operations.
boost::ui::uistring::wstring
std::wstring wstring() const
Returns Unicode wide std::wstring.
boost::ui::uistring::u16string
std::u16string u16string() const
Returns UTF-16 std::u16string.
Definition: string.hpp:293
std
Standard C++ namespace.
Definition: string_io.hpp:117