Embedded Template Library 1.0
Loading...
Searching...
No Matches
basic_string_stream.h
Go to the documentation of this file.
1
2
3/******************************************************************************
4The MIT License(MIT)
5
6Embedded Template Library.
7https://github.com/ETLCPP/etl
8https://www.etlcpp.com
9
10Copyright(c) 2020 John Wellbelove
11
12Permission is hereby granted, free of charge, to any person obtaining a copy
13of this software and associated documentation files(the "Software"), to deal
14in the Software without restriction, including without limitation the rights
15to use, copy, modify, merge, publish, distribute, sublicense, and / or sell
16copies of the Software, and to permit persons to whom the Software is
17furnished to do so, subject to the following conditions :
18
19The above copyright notice and this permission notice shall be included in all
20copies or substantial portions of the Software.
21
22THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
23IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
24FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.IN NO EVENT SHALL THE
25AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
26LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
27OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
28SOFTWARE.
29******************************************************************************/
30
31#ifndef ETL_BASIC_STRING_STREAM_INCLUDED
32#define ETL_BASIC_STRING_STREAM_INCLUDED
33
35
36#include "platform.h"
37#include "to_string.h"
38
39namespace etl
40{
41 template <typename TFormat, typename TIString, typename TStringView>
43 {
44 public:
45
47 typedef TIString istring_type;
48 typedef typename TIString::value_type value_type;
49 typedef typename TIString::pointer pointer;
50 typedef typename TIString::const_pointer const_pointer;
51
52 //*************************************************************************
54 //*************************************************************************
56 : text(text_)
57 {
58 }
59
60 //*************************************************************************
62 //*************************************************************************
64 : text(text_)
65 , format(spec_)
66 {
67 }
68
69 //*************************************************************************
71 //*************************************************************************
73 {
74 format = spec_;
75 }
76
77 //*************************************************************************
79 //*************************************************************************
80 const TFormat& get_format() const
81 {
82 return format;
83 }
84
85 //*************************************************************************
87 //*************************************************************************
89 {
90 return text;
91 }
92
93 //*************************************************************************
95 //*************************************************************************
96 const TIString& str() const
97 {
98 return text;
99 }
100
101 //*************************************************************************
103 //*************************************************************************
104 void str(const value_type* p)
105 {
106 text.assign(p);
107 }
108
109 //*************************************************************************
111 //*************************************************************************
112 void str(const TIString& is)
113 {
114 text.assign(is);
115 }
116
117 //*************************************************************************
119 //*************************************************************************
120
121 //*********************************
123 //*********************************
125 {
126 ss.format = fmt;
127 return ss;
128 }
129
130 //*********************************
132 //*********************************
138
139 //*********************************
141 //*********************************
147
148 //*********************************
150 //*********************************
151 template <typename TChar>
157
158 //*********************************
160 //*********************************
162 {
163 ss.format.precision(fmt.precision);
164 return ss;
165 }
166
167 //*********************************
169 //*********************************
171 {
172 ss.format.boolalpha(fmt.boolalpha);
173 return ss;
174 }
175
176 //*********************************
178 //*********************************
180 {
181 ss.format.upper_case(fmt.upper_case);
182 return ss;
183 }
184
185 //*********************************
187 //*********************************
189 {
190 ss.format.show_base(fmt.show_base);
191 return ss;
192 }
193
194 //*********************************
196 //*********************************
198 {
199 ss.format.left();
200 return ss;
201 }
202
203 //*********************************
205 //*********************************
207 {
208 ss.format.right();
209 return ss;
210 }
211
212 //*********************************
214 //*********************************
216 {
217 etl::to_string(view, ss.text, ss.format, true);
218 return ss;
219 }
220
221 //*********************************
223 //*********************************
225 {
226 TStringView view(p);
227 ss << view;
228 return ss;
229 }
230
231 //*********************************
233 //*********************************
235 {
236 TStringView view(p);
237 ss << view;
238 return ss;
239 }
240
241 //*********************************
243 //*********************************
245 {
246 etl::to_string(t, ss.text, ss.format, true);
247 return ss;
248 }
249
250 //*********************************
252 //*********************************
253 template <template <size_t> class TString, size_t SIZE>
255 {
256 const TIString& itext = t;
257 etl::to_string(itext, ss.str(), ss.get_format(), true);
258 return ss;
259 }
260
261 //*********************************
263 //*********************************
264 template <typename T>
266 {
267 etl::to_string(value, ss.text, ss.format, true);
268 return ss;
269 }
270
271 private:
272
273 TIString& text;
274 TFormat format;
275
276 basic_string_stream(const basic_string_stream&) ETL_DELETE;
278 };
279}
280
281#endif
Definition basic_string_stream.h:43
void str(const value_type *p)
Resets the stream to the supplied string.
Definition basic_string_stream.h:104
basic_string_stream(TIString &text_)
Construct from text.
Definition basic_string_stream.h:55
void str(const TIString &is)
Resets the stream to the supplied string.
Definition basic_string_stream.h:112
friend basic_string_stream & operator<<(basic_string_stream &ss, const TFormat &fmt)
Stream operators.
Definition basic_string_stream.h:124
TIString & str()
Get a reference to the current string.
Definition basic_string_stream.h:88
void set_format(const TFormat &spec_)
Set the format fmt.
Definition basic_string_stream.h:72
const TIString & str() const
Get a const reference to the current string.
Definition basic_string_stream.h:96
const TFormat & get_format() const
Get a const reference to the format fmt.
Definition basic_string_stream.h:80
basic_string_stream(TIString &text_, const TFormat &spec_)
Construct from text and format fmt.
Definition basic_string_stream.h:63
bitset_ext
Definition absolute.h:38
etl::enable_if<!etl::is_same< T, etl::istring >::value &&!etl::is_same< T, etl::string_view >::value, constetl::istring & >::type to_string(const T value, etl::istring &str, bool append=false)
Definition to_string.h:50
pair holds two objects of arbitrary type
Definition utility.h:164
Definition basic_format_spec.h:48
Definition basic_format_spec.h:104
Definition basic_format_spec.h:71
Definition basic_format_spec.h:126
Definition basic_format_spec.h:82
Definition basic_format_spec.h:131
Definition basic_format_spec.h:115
Definition basic_format_spec.h:93
Definition basic_format_spec.h:59