Chris@16
|
1 /*
|
Chris@101
|
2 * Copyright Andrey Semashev 2007 - 2015.
|
Chris@16
|
3 * Distributed under the Boost Software License, Version 1.0.
|
Chris@16
|
4 * (See accompanying file LICENSE_1_0.txt or copy at
|
Chris@16
|
5 * http://www.boost.org/LICENSE_1_0.txt)
|
Chris@16
|
6 */
|
Chris@16
|
7 /*!
|
Chris@16
|
8 * \file formatting_ostream.hpp
|
Chris@16
|
9 * \author Andrey Semashev
|
Chris@16
|
10 * \date 11.07.2012
|
Chris@16
|
11 *
|
Chris@16
|
12 * The header contains implementation of a string stream used for log record formatting.
|
Chris@16
|
13 */
|
Chris@16
|
14
|
Chris@16
|
15 #ifndef BOOST_LOG_UTILITY_FORMATTING_OSTREAM_HPP_INCLUDED_
|
Chris@16
|
16 #define BOOST_LOG_UTILITY_FORMATTING_OSTREAM_HPP_INCLUDED_
|
Chris@16
|
17
|
Chris@16
|
18 #include <ostream>
|
Chris@16
|
19 #include <string>
|
Chris@16
|
20 #include <memory>
|
Chris@16
|
21 #include <locale>
|
Chris@16
|
22 #include <boost/utility/string_ref_fwd.hpp>
|
Chris@16
|
23 #include <boost/type_traits/remove_cv.hpp>
|
Chris@16
|
24 #include <boost/log/detail/config.hpp>
|
Chris@16
|
25 #include <boost/log/detail/attachable_sstream_buf.hpp>
|
Chris@16
|
26 #include <boost/log/detail/code_conversion.hpp>
|
Chris@16
|
27 #include <boost/log/utility/string_literal_fwd.hpp>
|
Chris@16
|
28 #include <boost/log/utility/formatting_ostream_fwd.hpp>
|
Chris@16
|
29 #include <boost/utility/explicit_operator_bool.hpp>
|
Chris@16
|
30 #include <boost/log/detail/header.hpp>
|
Chris@16
|
31
|
Chris@16
|
32 #ifdef BOOST_HAS_PRAGMA_ONCE
|
Chris@16
|
33 #pragma once
|
Chris@16
|
34 #endif
|
Chris@16
|
35
|
Chris@16
|
36 namespace boost {
|
Chris@16
|
37
|
Chris@16
|
38 BOOST_LOG_OPEN_NAMESPACE
|
Chris@16
|
39
|
Chris@16
|
40 namespace aux {
|
Chris@16
|
41
|
Chris@16
|
42 template< typename T, typename R >
|
Chris@16
|
43 struct enable_if_char_type {};
|
Chris@16
|
44 template< typename R >
|
Chris@16
|
45 struct enable_if_char_type< char, R > { typedef R type; };
|
Chris@16
|
46 template< typename R >
|
Chris@16
|
47 struct enable_if_char_type< wchar_t, R > { typedef R type; };
|
Chris@16
|
48 #if !defined(BOOST_NO_CXX11_CHAR16_T)
|
Chris@16
|
49 template< typename R >
|
Chris@16
|
50 struct enable_if_char_type< char16_t, R > { typedef R type; };
|
Chris@16
|
51 #endif
|
Chris@16
|
52 #if !defined(BOOST_NO_CXX11_CHAR32_T)
|
Chris@16
|
53 template< typename R >
|
Chris@16
|
54 struct enable_if_char_type< char32_t, R > { typedef R type; };
|
Chris@16
|
55 #endif
|
Chris@16
|
56
|
Chris@16
|
57 } // namespace aux
|
Chris@16
|
58
|
Chris@16
|
59 /*!
|
Chris@16
|
60 * \brief Stream wrapper for log records formatting.
|
Chris@16
|
61 *
|
Chris@16
|
62 * This stream wrapper is used by the library for log record formatting. It implements the standard string stream interface
|
Chris@16
|
63 * with a few differences:
|
Chris@16
|
64 *
|
Chris@16
|
65 * \li It does not derive from standard types <tt>std::basic_ostream</tt>, <tt>std::basic_ios</tt> and <tt>std::ios_base</tt>,
|
Chris@16
|
66 * although it tries to implement their interfaces closely. There are a few small differences, mostly regarding <tt>rdbuf</tt>
|
Chris@16
|
67 * and <tt>str</tt> signatures, as well as the supported insertion operator overloads. The actual wrapped stream can be accessed
|
Chris@16
|
68 * through the <tt>stream</tt> methods.
|
Chris@16
|
69 * \li By default, \c bool values are formatted using alphabetical representation rather than numeric.
|
Chris@16
|
70 * \li The stream supports writing strings of character types different from the stream character type. The stream will perform
|
Chris@16
|
71 * character code conversion as needed using the imbued locale.
|
Chris@16
|
72 * \li The stream operates on an external string object rather than on the embedded one. The string can be attached or detached
|
Chris@16
|
73 * from the stream dynamically.
|
Chris@16
|
74 *
|
Chris@16
|
75 * Although <tt>basic_formatting_ostream</tt> does not derive from <tt>std::basic_ostream</tt>, users are not required to add
|
Chris@16
|
76 * special overloads of \c operator<< for it since the stream will by default reuse the operators for <tt>std::basic_ostream</tt>.
|
Chris@16
|
77 * However, one can define special overloads of \c operator<< for <tt>basic_formatting_ostream</tt> if a certain type needs
|
Chris@16
|
78 * special formatting when output to log.
|
Chris@16
|
79 */
|
Chris@16
|
80 template< typename CharT, typename TraitsT, typename AllocatorT >
|
Chris@16
|
81 class basic_formatting_ostream
|
Chris@16
|
82 {
|
Chris@16
|
83 public:
|
Chris@16
|
84 //! Character type
|
Chris@16
|
85 typedef CharT char_type;
|
Chris@16
|
86 //! Character traits
|
Chris@16
|
87 typedef TraitsT traits_type;
|
Chris@16
|
88 //! Memory allocator
|
Chris@16
|
89 typedef AllocatorT allocator_type;
|
Chris@16
|
90 //! Stream buffer type
|
Chris@16
|
91 typedef boost::log::aux::basic_ostringstreambuf< char_type, traits_type, allocator_type > streambuf_type;
|
Chris@16
|
92 //! Target string type
|
Chris@16
|
93 typedef typename streambuf_type::string_type string_type;
|
Chris@16
|
94
|
Chris@16
|
95 //! Stream type
|
Chris@16
|
96 typedef std::basic_ostream< char_type, traits_type > ostream_type;
|
Chris@16
|
97 //! Stream position type
|
Chris@16
|
98 typedef typename ostream_type::pos_type pos_type;
|
Chris@16
|
99 //! Stream offset type
|
Chris@16
|
100 typedef typename ostream_type::off_type off_type;
|
Chris@16
|
101 //! Integer type for characters
|
Chris@16
|
102 typedef typename ostream_type::int_type int_type;
|
Chris@16
|
103
|
Chris@16
|
104 typedef typename ostream_type::failure failure;
|
Chris@16
|
105 typedef typename ostream_type::fmtflags fmtflags;
|
Chris@16
|
106 typedef typename ostream_type::iostate iostate;
|
Chris@16
|
107 typedef typename ostream_type::openmode openmode;
|
Chris@16
|
108 typedef typename ostream_type::seekdir seekdir;
|
Chris@16
|
109 typedef typename ostream_type::Init Init;
|
Chris@16
|
110
|
Chris@16
|
111 typedef typename ostream_type::event event;
|
Chris@16
|
112 typedef typename ostream_type::event_callback event_callback;
|
Chris@16
|
113
|
Chris@16
|
114 class sentry :
|
Chris@16
|
115 public ostream_type::sentry
|
Chris@16
|
116 {
|
Chris@16
|
117 typedef typename ostream_type::sentry base_type;
|
Chris@16
|
118
|
Chris@16
|
119 public:
|
Chris@16
|
120 explicit sentry(basic_formatting_ostream& strm) : base_type(strm.stream())
|
Chris@16
|
121 {
|
Chris@16
|
122 }
|
Chris@16
|
123
|
Chris@16
|
124 BOOST_DELETED_FUNCTION(sentry(sentry const&))
|
Chris@16
|
125 BOOST_DELETED_FUNCTION(sentry& operator= (sentry const&))
|
Chris@16
|
126 };
|
Chris@16
|
127
|
Chris@16
|
128 private:
|
Chris@16
|
129 // Function types
|
Chris@16
|
130 typedef std::ios_base& (*ios_base_manip)(std::ios_base&);
|
Chris@16
|
131 typedef std::basic_ios< char_type, traits_type >& (*basic_ios_manip)(std::basic_ios< char_type, traits_type >&);
|
Chris@16
|
132 typedef ostream_type& (*stream_manip)(ostream_type&);
|
Chris@16
|
133
|
Chris@16
|
134 public:
|
Chris@16
|
135 static BOOST_CONSTEXPR_OR_CONST fmtflags boolalpha = ostream_type::boolalpha;
|
Chris@16
|
136 static BOOST_CONSTEXPR_OR_CONST fmtflags dec = ostream_type::dec;
|
Chris@16
|
137 static BOOST_CONSTEXPR_OR_CONST fmtflags fixed = ostream_type::fixed;
|
Chris@16
|
138 static BOOST_CONSTEXPR_OR_CONST fmtflags hex = ostream_type::hex;
|
Chris@16
|
139 static BOOST_CONSTEXPR_OR_CONST fmtflags internal = ostream_type::internal;
|
Chris@16
|
140 static BOOST_CONSTEXPR_OR_CONST fmtflags left = ostream_type::left;
|
Chris@16
|
141 static BOOST_CONSTEXPR_OR_CONST fmtflags oct = ostream_type::oct;
|
Chris@16
|
142 static BOOST_CONSTEXPR_OR_CONST fmtflags right = ostream_type::right;
|
Chris@16
|
143 static BOOST_CONSTEXPR_OR_CONST fmtflags scientific = ostream_type::scientific;
|
Chris@16
|
144 static BOOST_CONSTEXPR_OR_CONST fmtflags showbase = ostream_type::showbase;
|
Chris@16
|
145 static BOOST_CONSTEXPR_OR_CONST fmtflags showpoint = ostream_type::showpoint;
|
Chris@16
|
146 static BOOST_CONSTEXPR_OR_CONST fmtflags skipws = ostream_type::skipws;
|
Chris@16
|
147 static BOOST_CONSTEXPR_OR_CONST fmtflags unitbuf = ostream_type::unitbuf;
|
Chris@16
|
148 static BOOST_CONSTEXPR_OR_CONST fmtflags uppercase = ostream_type::uppercase;
|
Chris@16
|
149 static BOOST_CONSTEXPR_OR_CONST fmtflags adjustfield = ostream_type::adjustfield;
|
Chris@16
|
150 static BOOST_CONSTEXPR_OR_CONST fmtflags basefield = ostream_type::basefield;
|
Chris@16
|
151 static BOOST_CONSTEXPR_OR_CONST fmtflags floatfield = ostream_type::floatfield;
|
Chris@16
|
152
|
Chris@16
|
153 static BOOST_CONSTEXPR_OR_CONST iostate badbit = ostream_type::badbit;
|
Chris@16
|
154 static BOOST_CONSTEXPR_OR_CONST iostate eofbit = ostream_type::eofbit;
|
Chris@16
|
155 static BOOST_CONSTEXPR_OR_CONST iostate failbit = ostream_type::failbit;
|
Chris@16
|
156 static BOOST_CONSTEXPR_OR_CONST iostate goodbit = ostream_type::goodbit;
|
Chris@16
|
157
|
Chris@16
|
158 static BOOST_CONSTEXPR_OR_CONST openmode app = ostream_type::app;
|
Chris@16
|
159 static BOOST_CONSTEXPR_OR_CONST openmode ate = ostream_type::ate;
|
Chris@16
|
160 static BOOST_CONSTEXPR_OR_CONST openmode binary = ostream_type::binary;
|
Chris@16
|
161 static BOOST_CONSTEXPR_OR_CONST openmode in = ostream_type::in;
|
Chris@16
|
162 static BOOST_CONSTEXPR_OR_CONST openmode out = ostream_type::out;
|
Chris@16
|
163 static BOOST_CONSTEXPR_OR_CONST openmode trunc = ostream_type::trunc;
|
Chris@16
|
164
|
Chris@16
|
165 static BOOST_CONSTEXPR_OR_CONST seekdir beg = ostream_type::beg;
|
Chris@16
|
166 static BOOST_CONSTEXPR_OR_CONST seekdir cur = ostream_type::cur;
|
Chris@16
|
167 static BOOST_CONSTEXPR_OR_CONST seekdir end = ostream_type::end;
|
Chris@16
|
168
|
Chris@16
|
169 static BOOST_CONSTEXPR_OR_CONST event erase_event = ostream_type::erase_event;
|
Chris@16
|
170 static BOOST_CONSTEXPR_OR_CONST event imbue_event = ostream_type::imbue_event;
|
Chris@16
|
171 static BOOST_CONSTEXPR_OR_CONST event copyfmt_event = ostream_type::copyfmt_event;
|
Chris@16
|
172
|
Chris@16
|
173 private:
|
Chris@16
|
174 mutable streambuf_type m_streambuf;
|
Chris@16
|
175 ostream_type m_stream;
|
Chris@16
|
176
|
Chris@16
|
177 public:
|
Chris@16
|
178 /*!
|
Chris@16
|
179 * Default constructor. Creates an empty record that is equivalent to the invalid record handle.
|
Chris@16
|
180 * The stream capability is not available after construction.
|
Chris@16
|
181 *
|
Chris@16
|
182 * \post <tt>!*this == true</tt>
|
Chris@16
|
183 */
|
Chris@16
|
184 basic_formatting_ostream() : m_stream(&m_streambuf)
|
Chris@16
|
185 {
|
Chris@16
|
186 init_stream();
|
Chris@16
|
187 }
|
Chris@16
|
188
|
Chris@16
|
189 /*!
|
Chris@16
|
190 * Initializing constructor. Attaches the string to the constructed stream.
|
Chris@16
|
191 * The string will be used to store the formatted characters.
|
Chris@16
|
192 *
|
Chris@16
|
193 * \post <tt>!*this == false</tt>
|
Chris@16
|
194 * \param str The string buffer to attach.
|
Chris@16
|
195 */
|
Chris@16
|
196 explicit basic_formatting_ostream(string_type& str) :
|
Chris@16
|
197 m_streambuf(str),
|
Chris@16
|
198 m_stream(&m_streambuf)
|
Chris@16
|
199 {
|
Chris@16
|
200 init_stream();
|
Chris@16
|
201 }
|
Chris@16
|
202
|
Chris@16
|
203 /*!
|
Chris@16
|
204 * Destructor. Destroys the record, releases any sinks and attribute values that were involved in processing this record.
|
Chris@16
|
205 */
|
Chris@16
|
206 ~basic_formatting_ostream()
|
Chris@16
|
207 {
|
Chris@16
|
208 if (m_streambuf.storage())
|
Chris@16
|
209 flush();
|
Chris@16
|
210 }
|
Chris@16
|
211
|
Chris@16
|
212 /*!
|
Chris@16
|
213 * Attaches the stream to the string. The string will be used to store the formatted characters.
|
Chris@16
|
214 *
|
Chris@16
|
215 * \param str The string buffer to attach.
|
Chris@16
|
216 */
|
Chris@16
|
217 void attach(string_type& str)
|
Chris@16
|
218 {
|
Chris@16
|
219 m_streambuf.attach(str);
|
Chris@16
|
220 m_stream.clear(ostream_type::goodbit);
|
Chris@16
|
221 }
|
Chris@16
|
222 /*!
|
Chris@16
|
223 * Detaches the stream from the string. Any buffered data is flushed to the string.
|
Chris@16
|
224 */
|
Chris@16
|
225 void detach()
|
Chris@16
|
226 {
|
Chris@16
|
227 m_streambuf.detach();
|
Chris@16
|
228 m_stream.clear(ostream_type::badbit);
|
Chris@16
|
229 }
|
Chris@16
|
230
|
Chris@16
|
231 /*!
|
Chris@16
|
232 * \returns Reference to the attached string. The string must be attached before calling this method.
|
Chris@16
|
233 */
|
Chris@16
|
234 string_type const& str() const
|
Chris@16
|
235 {
|
Chris@16
|
236 string_type* storage = m_streambuf.storage();
|
Chris@16
|
237 BOOST_ASSERT(storage != NULL);
|
Chris@16
|
238
|
Chris@16
|
239 m_streambuf.pubsync();
|
Chris@16
|
240
|
Chris@16
|
241 return *storage;
|
Chris@16
|
242 }
|
Chris@16
|
243
|
Chris@16
|
244 /*!
|
Chris@16
|
245 * \returns Reference to the wrapped stream
|
Chris@16
|
246 */
|
Chris@16
|
247 ostream_type& stream() { return m_stream; }
|
Chris@16
|
248
|
Chris@16
|
249 /*!
|
Chris@16
|
250 * \returns Reference to the wrapped stream
|
Chris@16
|
251 */
|
Chris@16
|
252 ostream_type const& stream() const { return m_stream; }
|
Chris@16
|
253
|
Chris@16
|
254 // std::ios_base method forwarders
|
Chris@16
|
255 fmtflags flags() const { return m_stream.flags(); }
|
Chris@16
|
256 fmtflags flags(fmtflags f) { return m_stream.flags(f); }
|
Chris@16
|
257 fmtflags setf(fmtflags f) { return m_stream.setf(f); }
|
Chris@16
|
258 fmtflags setf(fmtflags f, fmtflags mask) { return m_stream.setf(f, mask); }
|
Chris@16
|
259 void unsetf(fmtflags f) { m_stream.unsetf(f); }
|
Chris@16
|
260
|
Chris@16
|
261 std::streamsize precision() const { return m_stream.precision(); }
|
Chris@16
|
262 std::streamsize precision(std::streamsize p) { return m_stream.precision(p); }
|
Chris@16
|
263
|
Chris@16
|
264 std::streamsize width() const { return m_stream.width(); }
|
Chris@16
|
265 std::streamsize width(std::streamsize w) { return m_stream.width(w); }
|
Chris@16
|
266
|
Chris@16
|
267 std::locale getloc() const { return m_stream.getloc(); }
|
Chris@16
|
268 std::locale imbue(std::locale const& loc) { return m_stream.imbue(loc); }
|
Chris@16
|
269
|
Chris@16
|
270 static int xalloc() { return ostream_type::xalloc(); }
|
Chris@16
|
271 long& iword(int index) { return m_stream.iword(index); }
|
Chris@16
|
272 void*& pword(int index) { return m_stream.pword(index); }
|
Chris@16
|
273
|
Chris@16
|
274 void register_callback(event_callback fn, int index) { m_stream.register_callback(fn, index); }
|
Chris@16
|
275
|
Chris@16
|
276 static bool sync_with_stdio(bool sync = true) { return ostream_type::sync_with_stdio(sync); }
|
Chris@16
|
277
|
Chris@16
|
278 // std::basic_ios method forwarders
|
Chris@16
|
279 BOOST_EXPLICIT_OPERATOR_BOOL()
|
Chris@16
|
280 bool operator! () const { return !m_stream; }
|
Chris@16
|
281
|
Chris@16
|
282 iostate rdstate() const { return m_stream.rdstate(); }
|
Chris@16
|
283 void clear(iostate state = goodbit) { m_stream.clear(state); }
|
Chris@16
|
284 void setstate(iostate state) { m_stream.setstate(state); }
|
Chris@16
|
285 bool good() const { return m_stream.good(); }
|
Chris@16
|
286 bool eof() const { return m_stream.eof(); }
|
Chris@16
|
287 bool fail() const { return m_stream.fail(); }
|
Chris@16
|
288 bool bad() const { return m_stream.bad(); }
|
Chris@16
|
289
|
Chris@16
|
290 iostate exceptions() const { return m_stream.exceptions(); }
|
Chris@16
|
291 void exceptions(iostate s) { m_stream.exceptions(s); }
|
Chris@16
|
292
|
Chris@16
|
293 ostream_type* tie() const { return m_stream.tie(); }
|
Chris@16
|
294 ostream_type* tie(ostream_type* strm) { return m_stream.tie(strm); }
|
Chris@16
|
295
|
Chris@16
|
296 streambuf_type* rdbuf() const { return &m_streambuf; }
|
Chris@16
|
297
|
Chris@16
|
298 basic_formatting_ostream& copyfmt(std::basic_ios< char_type, traits_type >& rhs)
|
Chris@16
|
299 {
|
Chris@16
|
300 m_stream.copyfmt(rhs);
|
Chris@16
|
301 return *this;
|
Chris@16
|
302 }
|
Chris@16
|
303 basic_formatting_ostream& copyfmt(basic_formatting_ostream& rhs)
|
Chris@16
|
304 {
|
Chris@16
|
305 m_stream.copyfmt(rhs.stream());
|
Chris@16
|
306 return *this;
|
Chris@16
|
307 }
|
Chris@16
|
308
|
Chris@16
|
309 char_type fill() const { return m_stream.fill(); }
|
Chris@16
|
310 char_type fill(char_type ch) { return m_stream.fill(ch); }
|
Chris@16
|
311
|
Chris@16
|
312 char narrow(char_type ch, char def) const { return m_stream.narrow(ch, def); }
|
Chris@16
|
313 char_type widen(char ch) const { return m_stream.widen(ch); }
|
Chris@16
|
314
|
Chris@16
|
315 // std::basic_ostream method forwarders
|
Chris@16
|
316 basic_formatting_ostream& flush()
|
Chris@16
|
317 {
|
Chris@16
|
318 m_stream.flush();
|
Chris@16
|
319 return *this;
|
Chris@16
|
320 }
|
Chris@16
|
321
|
Chris@16
|
322 pos_type tellp() { return m_stream.tellp(); }
|
Chris@16
|
323 basic_formatting_ostream& seekp(pos_type pos)
|
Chris@16
|
324 {
|
Chris@16
|
325 m_stream.seekp(pos);
|
Chris@16
|
326 return *this;
|
Chris@16
|
327 }
|
Chris@16
|
328 basic_formatting_ostream& seekp(off_type off, std::ios_base::seekdir dir)
|
Chris@16
|
329 {
|
Chris@16
|
330 m_stream.seekp(off, dir);
|
Chris@16
|
331 return *this;
|
Chris@16
|
332 }
|
Chris@16
|
333
|
Chris@16
|
334 basic_formatting_ostream& put(char_type c)
|
Chris@16
|
335 {
|
Chris@16
|
336 m_stream.put(c);
|
Chris@16
|
337 return *this;
|
Chris@16
|
338 }
|
Chris@16
|
339
|
Chris@16
|
340 template< typename OtherCharT >
|
Chris@16
|
341 typename aux::enable_if_char_type< OtherCharT, basic_formatting_ostream& >::type
|
Chris@16
|
342 put(OtherCharT c)
|
Chris@16
|
343 {
|
Chris@16
|
344 write(&c, 1);
|
Chris@16
|
345 return *this;
|
Chris@16
|
346 }
|
Chris@16
|
347
|
Chris@16
|
348 basic_formatting_ostream& write(const char_type* p, std::streamsize size)
|
Chris@16
|
349 {
|
Chris@16
|
350 m_stream.write(p, size);
|
Chris@16
|
351 return *this;
|
Chris@16
|
352 }
|
Chris@16
|
353
|
Chris@16
|
354 template< typename OtherCharT >
|
Chris@16
|
355 typename aux::enable_if_char_type< OtherCharT, basic_formatting_ostream& >::type
|
Chris@16
|
356 write(const OtherCharT* p, std::streamsize size)
|
Chris@16
|
357 {
|
Chris@16
|
358 sentry guard(*this);
|
Chris@16
|
359 if (guard)
|
Chris@16
|
360 {
|
Chris@16
|
361 m_stream.flush();
|
Chris@16
|
362
|
Chris@16
|
363 string_type* storage = m_streambuf.storage();
|
Chris@16
|
364 aux::code_convert(p, static_cast< std::size_t >(size), *storage, m_stream.getloc());
|
Chris@16
|
365 }
|
Chris@16
|
366
|
Chris@16
|
367 return *this;
|
Chris@16
|
368 }
|
Chris@16
|
369
|
Chris@16
|
370 basic_formatting_ostream& operator<< (ios_base_manip manip)
|
Chris@16
|
371 {
|
Chris@16
|
372 m_stream << manip;
|
Chris@16
|
373 return *this;
|
Chris@16
|
374 }
|
Chris@16
|
375 basic_formatting_ostream& operator<< (basic_ios_manip manip)
|
Chris@16
|
376 {
|
Chris@16
|
377 m_stream << manip;
|
Chris@16
|
378 return *this;
|
Chris@16
|
379 }
|
Chris@16
|
380 basic_formatting_ostream& operator<< (stream_manip manip)
|
Chris@16
|
381 {
|
Chris@16
|
382 m_stream << manip;
|
Chris@16
|
383 return *this;
|
Chris@16
|
384 }
|
Chris@16
|
385
|
Chris@16
|
386 basic_formatting_ostream& operator<< (char c)
|
Chris@16
|
387 {
|
Chris@16
|
388 return this->formatted_write(&c, 1);
|
Chris@16
|
389 }
|
Chris@16
|
390 basic_formatting_ostream& operator<< (const char* p)
|
Chris@16
|
391 {
|
Chris@16
|
392 return this->formatted_write(p, static_cast< std::streamsize >(std::char_traits< char >::length(p)));
|
Chris@16
|
393 }
|
Chris@16
|
394
|
Chris@16
|
395 #if !defined(BOOST_NO_INTRINSIC_WCHAR_T)
|
Chris@16
|
396 basic_formatting_ostream& operator<< (wchar_t c)
|
Chris@16
|
397 {
|
Chris@16
|
398 return this->formatted_write(&c, 1);
|
Chris@16
|
399 }
|
Chris@16
|
400 basic_formatting_ostream& operator<< (const wchar_t* p)
|
Chris@16
|
401 {
|
Chris@16
|
402 return this->formatted_write(p, static_cast< std::streamsize >(std::char_traits< wchar_t >::length(p)));
|
Chris@16
|
403 }
|
Chris@16
|
404 #endif
|
Chris@16
|
405 #if !defined(BOOST_NO_CXX11_CHAR16_T)
|
Chris@16
|
406 basic_formatting_ostream& operator<< (char16_t c)
|
Chris@16
|
407 {
|
Chris@16
|
408 return this->formatted_write(&c, 1);
|
Chris@16
|
409 }
|
Chris@16
|
410 basic_formatting_ostream& operator<< (const char16_t* p)
|
Chris@16
|
411 {
|
Chris@16
|
412 return this->formatted_write(p, static_cast< std::streamsize >(std::char_traits< char16_t >::length(p)));
|
Chris@16
|
413 }
|
Chris@16
|
414 #endif
|
Chris@16
|
415 #if !defined(BOOST_NO_CXX11_CHAR32_T)
|
Chris@16
|
416 basic_formatting_ostream& operator<< (char32_t c)
|
Chris@16
|
417 {
|
Chris@16
|
418 return this->formatted_write(&c, 1);
|
Chris@16
|
419 }
|
Chris@16
|
420 basic_formatting_ostream& operator<< (const char32_t* p)
|
Chris@16
|
421 {
|
Chris@16
|
422 return this->formatted_write(p, static_cast< std::streamsize >(std::char_traits< char32_t >::length(p)));
|
Chris@16
|
423 }
|
Chris@16
|
424 #endif
|
Chris@16
|
425
|
Chris@16
|
426 basic_formatting_ostream& operator<< (bool value)
|
Chris@16
|
427 {
|
Chris@16
|
428 m_stream << value;
|
Chris@16
|
429 return *this;
|
Chris@16
|
430 }
|
Chris@16
|
431 basic_formatting_ostream& operator<< (signed char value)
|
Chris@16
|
432 {
|
Chris@16
|
433 m_stream << value;
|
Chris@16
|
434 return *this;
|
Chris@16
|
435 }
|
Chris@16
|
436 basic_formatting_ostream& operator<< (unsigned char value)
|
Chris@16
|
437 {
|
Chris@16
|
438 m_stream << value;
|
Chris@16
|
439 return *this;
|
Chris@16
|
440 }
|
Chris@16
|
441 basic_formatting_ostream& operator<< (short value)
|
Chris@16
|
442 {
|
Chris@16
|
443 m_stream << value;
|
Chris@16
|
444 return *this;
|
Chris@16
|
445 }
|
Chris@16
|
446 basic_formatting_ostream& operator<< (unsigned short value)
|
Chris@16
|
447 {
|
Chris@16
|
448 m_stream << value;
|
Chris@16
|
449 return *this;
|
Chris@16
|
450 }
|
Chris@16
|
451 basic_formatting_ostream& operator<< (int value)
|
Chris@16
|
452 {
|
Chris@16
|
453 m_stream << value;
|
Chris@16
|
454 return *this;
|
Chris@16
|
455 }
|
Chris@16
|
456 basic_formatting_ostream& operator<< (unsigned int value)
|
Chris@16
|
457 {
|
Chris@16
|
458 m_stream << value;
|
Chris@16
|
459 return *this;
|
Chris@16
|
460 }
|
Chris@16
|
461 basic_formatting_ostream& operator<< (long value)
|
Chris@16
|
462 {
|
Chris@16
|
463 m_stream << value;
|
Chris@16
|
464 return *this;
|
Chris@16
|
465 }
|
Chris@16
|
466 basic_formatting_ostream& operator<< (unsigned long value)
|
Chris@16
|
467 {
|
Chris@16
|
468 m_stream << value;
|
Chris@16
|
469 return *this;
|
Chris@16
|
470 }
|
Chris@16
|
471 #if !defined(BOOST_NO_LONG_LONG)
|
Chris@16
|
472 basic_formatting_ostream& operator<< (long long value)
|
Chris@16
|
473 {
|
Chris@16
|
474 m_stream << value;
|
Chris@16
|
475 return *this;
|
Chris@16
|
476 }
|
Chris@16
|
477 basic_formatting_ostream& operator<< (unsigned long long value)
|
Chris@16
|
478 {
|
Chris@16
|
479 m_stream << value;
|
Chris@16
|
480 return *this;
|
Chris@16
|
481 }
|
Chris@16
|
482 #endif
|
Chris@16
|
483
|
Chris@16
|
484 basic_formatting_ostream& operator<< (float value)
|
Chris@16
|
485 {
|
Chris@16
|
486 m_stream << value;
|
Chris@16
|
487 return *this;
|
Chris@16
|
488 }
|
Chris@16
|
489 basic_formatting_ostream& operator<< (double value)
|
Chris@16
|
490 {
|
Chris@16
|
491 m_stream << value;
|
Chris@16
|
492 return *this;
|
Chris@16
|
493 }
|
Chris@16
|
494 basic_formatting_ostream& operator<< (long double value)
|
Chris@16
|
495 {
|
Chris@16
|
496 m_stream << value;
|
Chris@16
|
497 return *this;
|
Chris@16
|
498 }
|
Chris@16
|
499
|
Chris@16
|
500 basic_formatting_ostream& operator<< (const void* value)
|
Chris@16
|
501 {
|
Chris@16
|
502 m_stream << value;
|
Chris@16
|
503 return *this;
|
Chris@16
|
504 }
|
Chris@16
|
505
|
Chris@16
|
506 basic_formatting_ostream& operator<< (std::basic_streambuf< char_type, traits_type >* buf)
|
Chris@16
|
507 {
|
Chris@16
|
508 m_stream << buf;
|
Chris@16
|
509 return *this;
|
Chris@16
|
510 }
|
Chris@16
|
511
|
Chris@16
|
512 template< typename OtherCharT, typename OtherTraitsT, typename OtherAllocatorT >
|
Chris@16
|
513 friend typename aux::enable_if_char_type< OtherCharT, basic_formatting_ostream& >::type
|
Chris@16
|
514 operator<< (basic_formatting_ostream& strm, std::basic_string< OtherCharT, OtherTraitsT, OtherAllocatorT > const& str)
|
Chris@16
|
515 {
|
Chris@16
|
516 return strm.formatted_write(str.c_str(), static_cast< std::streamsize >(str.size()));
|
Chris@16
|
517 }
|
Chris@16
|
518
|
Chris@16
|
519 template< typename OtherCharT, typename OtherTraitsT >
|
Chris@16
|
520 friend typename aux::enable_if_char_type< OtherCharT, basic_formatting_ostream& >::type
|
Chris@16
|
521 operator<< (basic_formatting_ostream& strm, basic_string_literal< OtherCharT, OtherTraitsT > const& str)
|
Chris@16
|
522 {
|
Chris@16
|
523 return strm.formatted_write(str.c_str(), static_cast< std::streamsize >(str.size()));
|
Chris@16
|
524 }
|
Chris@16
|
525
|
Chris@16
|
526 template< typename OtherCharT, typename OtherTraitsT >
|
Chris@16
|
527 friend typename aux::enable_if_char_type< OtherCharT, basic_formatting_ostream& >::type
|
Chris@16
|
528 operator<< (basic_formatting_ostream& strm, basic_string_ref< OtherCharT, OtherTraitsT > const& str)
|
Chris@16
|
529 {
|
Chris@16
|
530 return strm.formatted_write(str.data(), static_cast< std::streamsize >(str.size()));
|
Chris@16
|
531 }
|
Chris@16
|
532
|
Chris@16
|
533 private:
|
Chris@16
|
534 void init_stream()
|
Chris@16
|
535 {
|
Chris@16
|
536 m_stream.clear(m_streambuf.storage() ? ostream_type::goodbit : ostream_type::badbit);
|
Chris@16
|
537 m_stream.flags
|
Chris@16
|
538 (
|
Chris@16
|
539 ostream_type::dec |
|
Chris@16
|
540 ostream_type::skipws |
|
Chris@16
|
541 ostream_type::boolalpha // this differs from the default stream flags but makes logs look better
|
Chris@16
|
542 );
|
Chris@16
|
543 m_stream.width(0);
|
Chris@16
|
544 m_stream.precision(6);
|
Chris@16
|
545 m_stream.fill(static_cast< char_type >(' '));
|
Chris@16
|
546 }
|
Chris@16
|
547
|
Chris@16
|
548 basic_formatting_ostream& formatted_write(const char_type* p, std::streamsize size)
|
Chris@16
|
549 {
|
Chris@16
|
550 sentry guard(*this);
|
Chris@16
|
551 if (guard)
|
Chris@16
|
552 {
|
Chris@16
|
553 m_stream.flush();
|
Chris@16
|
554
|
Chris@16
|
555 if (m_stream.width() <= size)
|
Chris@16
|
556 m_streambuf.storage()->append(p, static_cast< std::size_t >(size));
|
Chris@16
|
557 else
|
Chris@16
|
558 this->aligned_write(p, size);
|
Chris@16
|
559
|
Chris@16
|
560 m_stream.width(0);
|
Chris@16
|
561 }
|
Chris@16
|
562
|
Chris@16
|
563 return *this;
|
Chris@16
|
564 }
|
Chris@16
|
565
|
Chris@16
|
566 template< typename OtherCharT >
|
Chris@16
|
567 basic_formatting_ostream& formatted_write(const OtherCharT* p, std::streamsize size)
|
Chris@16
|
568 {
|
Chris@16
|
569 sentry guard(*this);
|
Chris@16
|
570 if (guard)
|
Chris@16
|
571 {
|
Chris@16
|
572 m_stream.flush();
|
Chris@16
|
573
|
Chris@16
|
574 if (m_stream.width() <= size)
|
Chris@16
|
575 aux::code_convert(p, static_cast< std::size_t >(size), *m_streambuf.storage(), m_stream.getloc());
|
Chris@16
|
576 else
|
Chris@16
|
577 this->aligned_write(p, size);
|
Chris@16
|
578
|
Chris@16
|
579 m_stream.width(0);
|
Chris@16
|
580 }
|
Chris@16
|
581
|
Chris@16
|
582 return *this;
|
Chris@16
|
583 }
|
Chris@16
|
584
|
Chris@16
|
585 void aligned_write(const char_type* p, std::streamsize size);
|
Chris@16
|
586
|
Chris@16
|
587 template< typename OtherCharT >
|
Chris@16
|
588 void aligned_write(const OtherCharT* p, std::streamsize size);
|
Chris@16
|
589
|
Chris@16
|
590 //! Copy constructor (closed)
|
Chris@16
|
591 BOOST_DELETED_FUNCTION(basic_formatting_ostream(basic_formatting_ostream const& that))
|
Chris@16
|
592 //! Assignment (closed)
|
Chris@16
|
593 BOOST_DELETED_FUNCTION(basic_formatting_ostream& operator= (basic_formatting_ostream const& that))
|
Chris@16
|
594 };
|
Chris@16
|
595
|
Chris@16
|
596 template< typename CharT, typename TraitsT, typename AllocatorT >
|
Chris@16
|
597 BOOST_CONSTEXPR_OR_CONST typename basic_formatting_ostream< CharT, TraitsT, AllocatorT >::fmtflags basic_formatting_ostream< CharT, TraitsT, AllocatorT >::boolalpha;
|
Chris@16
|
598 template< typename CharT, typename TraitsT, typename AllocatorT >
|
Chris@16
|
599 BOOST_CONSTEXPR_OR_CONST typename basic_formatting_ostream< CharT, TraitsT, AllocatorT >::fmtflags basic_formatting_ostream< CharT, TraitsT, AllocatorT >::dec;
|
Chris@16
|
600 template< typename CharT, typename TraitsT, typename AllocatorT >
|
Chris@16
|
601 BOOST_CONSTEXPR_OR_CONST typename basic_formatting_ostream< CharT, TraitsT, AllocatorT >::fmtflags basic_formatting_ostream< CharT, TraitsT, AllocatorT >::fixed;
|
Chris@16
|
602 template< typename CharT, typename TraitsT, typename AllocatorT >
|
Chris@16
|
603 BOOST_CONSTEXPR_OR_CONST typename basic_formatting_ostream< CharT, TraitsT, AllocatorT >::fmtflags basic_formatting_ostream< CharT, TraitsT, AllocatorT >::hex;
|
Chris@16
|
604 template< typename CharT, typename TraitsT, typename AllocatorT >
|
Chris@16
|
605 BOOST_CONSTEXPR_OR_CONST typename basic_formatting_ostream< CharT, TraitsT, AllocatorT >::fmtflags basic_formatting_ostream< CharT, TraitsT, AllocatorT >::internal;
|
Chris@16
|
606 template< typename CharT, typename TraitsT, typename AllocatorT >
|
Chris@16
|
607 BOOST_CONSTEXPR_OR_CONST typename basic_formatting_ostream< CharT, TraitsT, AllocatorT >::fmtflags basic_formatting_ostream< CharT, TraitsT, AllocatorT >::left;
|
Chris@16
|
608 template< typename CharT, typename TraitsT, typename AllocatorT >
|
Chris@16
|
609 BOOST_CONSTEXPR_OR_CONST typename basic_formatting_ostream< CharT, TraitsT, AllocatorT >::fmtflags basic_formatting_ostream< CharT, TraitsT, AllocatorT >::oct;
|
Chris@16
|
610 template< typename CharT, typename TraitsT, typename AllocatorT >
|
Chris@16
|
611 BOOST_CONSTEXPR_OR_CONST typename basic_formatting_ostream< CharT, TraitsT, AllocatorT >::fmtflags basic_formatting_ostream< CharT, TraitsT, AllocatorT >::right;
|
Chris@16
|
612 template< typename CharT, typename TraitsT, typename AllocatorT >
|
Chris@16
|
613 BOOST_CONSTEXPR_OR_CONST typename basic_formatting_ostream< CharT, TraitsT, AllocatorT >::fmtflags basic_formatting_ostream< CharT, TraitsT, AllocatorT >::scientific;
|
Chris@16
|
614 template< typename CharT, typename TraitsT, typename AllocatorT >
|
Chris@16
|
615 BOOST_CONSTEXPR_OR_CONST typename basic_formatting_ostream< CharT, TraitsT, AllocatorT >::fmtflags basic_formatting_ostream< CharT, TraitsT, AllocatorT >::showbase;
|
Chris@16
|
616 template< typename CharT, typename TraitsT, typename AllocatorT >
|
Chris@16
|
617 BOOST_CONSTEXPR_OR_CONST typename basic_formatting_ostream< CharT, TraitsT, AllocatorT >::fmtflags basic_formatting_ostream< CharT, TraitsT, AllocatorT >::showpoint;
|
Chris@16
|
618 template< typename CharT, typename TraitsT, typename AllocatorT >
|
Chris@16
|
619 BOOST_CONSTEXPR_OR_CONST typename basic_formatting_ostream< CharT, TraitsT, AllocatorT >::fmtflags basic_formatting_ostream< CharT, TraitsT, AllocatorT >::skipws;
|
Chris@16
|
620 template< typename CharT, typename TraitsT, typename AllocatorT >
|
Chris@16
|
621 BOOST_CONSTEXPR_OR_CONST typename basic_formatting_ostream< CharT, TraitsT, AllocatorT >::fmtflags basic_formatting_ostream< CharT, TraitsT, AllocatorT >::unitbuf;
|
Chris@16
|
622 template< typename CharT, typename TraitsT, typename AllocatorT >
|
Chris@16
|
623 BOOST_CONSTEXPR_OR_CONST typename basic_formatting_ostream< CharT, TraitsT, AllocatorT >::fmtflags basic_formatting_ostream< CharT, TraitsT, AllocatorT >::uppercase;
|
Chris@16
|
624 template< typename CharT, typename TraitsT, typename AllocatorT >
|
Chris@16
|
625 BOOST_CONSTEXPR_OR_CONST typename basic_formatting_ostream< CharT, TraitsT, AllocatorT >::fmtflags basic_formatting_ostream< CharT, TraitsT, AllocatorT >::adjustfield;
|
Chris@16
|
626 template< typename CharT, typename TraitsT, typename AllocatorT >
|
Chris@16
|
627 BOOST_CONSTEXPR_OR_CONST typename basic_formatting_ostream< CharT, TraitsT, AllocatorT >::fmtflags basic_formatting_ostream< CharT, TraitsT, AllocatorT >::basefield;
|
Chris@16
|
628 template< typename CharT, typename TraitsT, typename AllocatorT >
|
Chris@16
|
629 BOOST_CONSTEXPR_OR_CONST typename basic_formatting_ostream< CharT, TraitsT, AllocatorT >::fmtflags basic_formatting_ostream< CharT, TraitsT, AllocatorT >::floatfield;
|
Chris@16
|
630
|
Chris@16
|
631 template< typename CharT, typename TraitsT, typename AllocatorT >
|
Chris@16
|
632 BOOST_CONSTEXPR_OR_CONST typename basic_formatting_ostream< CharT, TraitsT, AllocatorT >::iostate basic_formatting_ostream< CharT, TraitsT, AllocatorT >::badbit;
|
Chris@16
|
633 template< typename CharT, typename TraitsT, typename AllocatorT >
|
Chris@16
|
634 BOOST_CONSTEXPR_OR_CONST typename basic_formatting_ostream< CharT, TraitsT, AllocatorT >::iostate basic_formatting_ostream< CharT, TraitsT, AllocatorT >::eofbit;
|
Chris@16
|
635 template< typename CharT, typename TraitsT, typename AllocatorT >
|
Chris@16
|
636 BOOST_CONSTEXPR_OR_CONST typename basic_formatting_ostream< CharT, TraitsT, AllocatorT >::iostate basic_formatting_ostream< CharT, TraitsT, AllocatorT >::failbit;
|
Chris@16
|
637 template< typename CharT, typename TraitsT, typename AllocatorT >
|
Chris@16
|
638 BOOST_CONSTEXPR_OR_CONST typename basic_formatting_ostream< CharT, TraitsT, AllocatorT >::iostate basic_formatting_ostream< CharT, TraitsT, AllocatorT >::goodbit;
|
Chris@16
|
639
|
Chris@16
|
640 template< typename CharT, typename TraitsT, typename AllocatorT >
|
Chris@16
|
641 BOOST_CONSTEXPR_OR_CONST typename basic_formatting_ostream< CharT, TraitsT, AllocatorT >::openmode basic_formatting_ostream< CharT, TraitsT, AllocatorT >::app;
|
Chris@16
|
642 template< typename CharT, typename TraitsT, typename AllocatorT >
|
Chris@16
|
643 BOOST_CONSTEXPR_OR_CONST typename basic_formatting_ostream< CharT, TraitsT, AllocatorT >::openmode basic_formatting_ostream< CharT, TraitsT, AllocatorT >::ate;
|
Chris@16
|
644 template< typename CharT, typename TraitsT, typename AllocatorT >
|
Chris@16
|
645 BOOST_CONSTEXPR_OR_CONST typename basic_formatting_ostream< CharT, TraitsT, AllocatorT >::openmode basic_formatting_ostream< CharT, TraitsT, AllocatorT >::binary;
|
Chris@16
|
646 template< typename CharT, typename TraitsT, typename AllocatorT >
|
Chris@16
|
647 BOOST_CONSTEXPR_OR_CONST typename basic_formatting_ostream< CharT, TraitsT, AllocatorT >::openmode basic_formatting_ostream< CharT, TraitsT, AllocatorT >::in;
|
Chris@16
|
648 template< typename CharT, typename TraitsT, typename AllocatorT >
|
Chris@16
|
649 BOOST_CONSTEXPR_OR_CONST typename basic_formatting_ostream< CharT, TraitsT, AllocatorT >::openmode basic_formatting_ostream< CharT, TraitsT, AllocatorT >::out;
|
Chris@16
|
650 template< typename CharT, typename TraitsT, typename AllocatorT >
|
Chris@16
|
651 BOOST_CONSTEXPR_OR_CONST typename basic_formatting_ostream< CharT, TraitsT, AllocatorT >::openmode basic_formatting_ostream< CharT, TraitsT, AllocatorT >::trunc;
|
Chris@16
|
652
|
Chris@16
|
653 template< typename CharT, typename TraitsT, typename AllocatorT >
|
Chris@16
|
654 BOOST_CONSTEXPR_OR_CONST typename basic_formatting_ostream< CharT, TraitsT, AllocatorT >::seekdir basic_formatting_ostream< CharT, TraitsT, AllocatorT >::beg;
|
Chris@16
|
655 template< typename CharT, typename TraitsT, typename AllocatorT >
|
Chris@16
|
656 BOOST_CONSTEXPR_OR_CONST typename basic_formatting_ostream< CharT, TraitsT, AllocatorT >::seekdir basic_formatting_ostream< CharT, TraitsT, AllocatorT >::cur;
|
Chris@16
|
657 template< typename CharT, typename TraitsT, typename AllocatorT >
|
Chris@16
|
658 BOOST_CONSTEXPR_OR_CONST typename basic_formatting_ostream< CharT, TraitsT, AllocatorT >::seekdir basic_formatting_ostream< CharT, TraitsT, AllocatorT >::end;
|
Chris@16
|
659
|
Chris@16
|
660 template< typename CharT, typename TraitsT, typename AllocatorT >
|
Chris@16
|
661 BOOST_CONSTEXPR_OR_CONST typename basic_formatting_ostream< CharT, TraitsT, AllocatorT >::event basic_formatting_ostream< CharT, TraitsT, AllocatorT >::erase_event;
|
Chris@16
|
662 template< typename CharT, typename TraitsT, typename AllocatorT >
|
Chris@16
|
663 BOOST_CONSTEXPR_OR_CONST typename basic_formatting_ostream< CharT, TraitsT, AllocatorT >::event basic_formatting_ostream< CharT, TraitsT, AllocatorT >::imbue_event;
|
Chris@16
|
664 template< typename CharT, typename TraitsT, typename AllocatorT >
|
Chris@16
|
665 BOOST_CONSTEXPR_OR_CONST typename basic_formatting_ostream< CharT, TraitsT, AllocatorT >::event basic_formatting_ostream< CharT, TraitsT, AllocatorT >::copyfmt_event;
|
Chris@16
|
666
|
Chris@16
|
667 template< typename CharT, typename TraitsT, typename AllocatorT >
|
Chris@16
|
668 void basic_formatting_ostream< CharT, TraitsT, AllocatorT >::aligned_write(const char_type* p, std::streamsize size)
|
Chris@16
|
669 {
|
Chris@16
|
670 string_type* const storage = m_streambuf.storage();
|
Chris@16
|
671 typename string_type::size_type const alignment_size =
|
Chris@16
|
672 static_cast< typename string_type::size_type >(m_stream.width() - size);
|
Chris@16
|
673 const bool align_left = (m_stream.flags() & ostream_type::adjustfield) == ostream_type::left;
|
Chris@16
|
674 if (align_left)
|
Chris@16
|
675 {
|
Chris@16
|
676 storage->append(p, static_cast< std::size_t >(size));
|
Chris@16
|
677 storage->append(alignment_size, m_stream.fill());
|
Chris@16
|
678 }
|
Chris@16
|
679 else
|
Chris@16
|
680 {
|
Chris@16
|
681 storage->append(alignment_size, m_stream.fill());
|
Chris@16
|
682 storage->append(p, static_cast< std::size_t >(size));
|
Chris@16
|
683 }
|
Chris@16
|
684 }
|
Chris@16
|
685
|
Chris@16
|
686 template< typename CharT, typename TraitsT, typename AllocatorT >
|
Chris@16
|
687 template< typename OtherCharT >
|
Chris@16
|
688 void basic_formatting_ostream< CharT, TraitsT, AllocatorT >::aligned_write(const OtherCharT* p, std::streamsize size)
|
Chris@16
|
689 {
|
Chris@16
|
690 string_type* const storage = m_streambuf.storage();
|
Chris@16
|
691 typename string_type::size_type const alignment_size =
|
Chris@16
|
692 static_cast< typename string_type::size_type >(m_stream.width() - size);
|
Chris@16
|
693 const bool align_left = (m_stream.flags() & ostream_type::adjustfield) == ostream_type::left;
|
Chris@16
|
694 if (align_left)
|
Chris@16
|
695 {
|
Chris@16
|
696 aux::code_convert(p, static_cast< std::size_t >(size), *storage, m_stream.getloc());
|
Chris@16
|
697 storage->append(alignment_size, m_stream.fill());
|
Chris@16
|
698 }
|
Chris@16
|
699 else
|
Chris@16
|
700 {
|
Chris@16
|
701 storage->append(alignment_size, m_stream.fill());
|
Chris@16
|
702 aux::code_convert(p, static_cast< std::size_t >(size), *storage, m_stream.getloc());
|
Chris@16
|
703 }
|
Chris@16
|
704 }
|
Chris@16
|
705
|
Chris@16
|
706 template< typename CharT, typename TraitsT, typename AllocatorT, typename T >
|
Chris@16
|
707 inline basic_formatting_ostream< CharT, TraitsT, AllocatorT >&
|
Chris@16
|
708 operator<< (basic_formatting_ostream< CharT, TraitsT, AllocatorT >& strm, T const& value)
|
Chris@16
|
709 {
|
Chris@16
|
710 strm.stream() << value;
|
Chris@16
|
711 return strm;
|
Chris@16
|
712 }
|
Chris@16
|
713
|
Chris@101
|
714 template< typename CharT, typename TraitsT, typename AllocatorT, typename T >
|
Chris@101
|
715 inline basic_formatting_ostream< CharT, TraitsT, AllocatorT >&
|
Chris@101
|
716 operator<< (basic_formatting_ostream< CharT, TraitsT, AllocatorT >& strm, T& value)
|
Chris@101
|
717 {
|
Chris@101
|
718 strm.stream() << value;
|
Chris@101
|
719 return strm;
|
Chris@101
|
720 }
|
Chris@101
|
721
|
Chris@101
|
722 #if !defined(BOOST_NO_CXX11_RVALUE_REFERENCES)
|
Chris@101
|
723
|
Chris@101
|
724 template< typename CharT, typename TraitsT, typename AllocatorT, typename T >
|
Chris@101
|
725 inline basic_formatting_ostream< CharT, TraitsT, AllocatorT >&
|
Chris@101
|
726 operator<< (basic_formatting_ostream< CharT, TraitsT, AllocatorT >&& strm, T const& value)
|
Chris@101
|
727 {
|
Chris@101
|
728 static_cast< basic_formatting_ostream< CharT, TraitsT, AllocatorT >& >(strm) << value;
|
Chris@101
|
729 return strm;
|
Chris@101
|
730 }
|
Chris@101
|
731
|
Chris@101
|
732 template< typename CharT, typename TraitsT, typename AllocatorT, typename T >
|
Chris@101
|
733 inline basic_formatting_ostream< CharT, TraitsT, AllocatorT >&
|
Chris@101
|
734 operator<< (basic_formatting_ostream< CharT, TraitsT, AllocatorT >&& strm, T& value)
|
Chris@101
|
735 {
|
Chris@101
|
736 static_cast< basic_formatting_ostream< CharT, TraitsT, AllocatorT >& >(strm) << value;
|
Chris@101
|
737 return strm;
|
Chris@101
|
738 }
|
Chris@101
|
739
|
Chris@101
|
740 #endif // !defined(BOOST_NO_CXX11_RVALUE_REFERENCES)
|
Chris@101
|
741
|
Chris@16
|
742 BOOST_LOG_CLOSE_NAMESPACE // namespace log
|
Chris@16
|
743
|
Chris@16
|
744 } // namespace boost
|
Chris@16
|
745
|
Chris@16
|
746 #include <boost/log/detail/footer.hpp>
|
Chris@16
|
747
|
Chris@16
|
748 #endif // BOOST_LOG_UTILITY_FORMATTING_OSTREAM_HPP_INCLUDED_
|