BDE 4.14.0 Production release
Loading...
Searching...
No Matches
bslstl_ostream.h
Go to the documentation of this file.
1/// @file bslstl_ostream.h
2///
3/// The content of this file has been pre-processed for Doxygen.
4///
5
6
7// bslstl_ostream.h -*-C++-*-
8#ifndef INCLUDED_BSLSTL_OSTREAM
9#define INCLUDED_BSLSTL_OSTREAM
10
11#include <bsls_ident.h>
12BSLS_IDENT("$Id: $")
13
14/// @defgroup bslstl_ostream bslstl_ostream
15/// @brief Provide aliases and implementations matching standard <ostream>.
16/// @addtogroup bsl
17/// @{
18/// @addtogroup bslstl
19/// @{
20/// @addtogroup bslstl_ostream
21/// @{
22///
23/// <h1> Outline </h1>
24/// * <a href="#bslstl_ostream-purpose"> Purpose</a>
25/// * <a href="#bslstl_ostream-description"> Description </a>
26///
27/// # Purpose {#bslstl_ostream-purpose}
28/// Provide aliases and implementations matching standard <ostream>.
29///
30/// **Canonical header:** bsl_ostream.h
31///
32/// # Description {#bslstl_ostream-description}
33/// This component is for internal use only. Please include
34/// `<bsl_ostream.h>` instead. This component provides a namespace for
35/// implementations for standard `osynstream` I/O manipulators.
36/// @}
37/** @} */
38/** @} */
39
40/** @addtogroup bsl
41 * @{
42 */
43/** @addtogroup bslstl
44 * @{
45 */
46/** @addtogroup bslstl_ostream
47 * @{
48 */
49
50#include <bslstl_iosfwd.h>
51#include <bslstl_ios.h>
52#include <bslstl_syncbufbase.h>
53
54#include <bsls_platform.h>
55
56#include <ostream>
57
58#ifndef BDE_DONT_ALLOW_TRANSITIVE_INCLUDES
59#include <bsls_nativestd.h>
60#endif // BDE_DONT_ALLOW_TRANSITIVE_INCLUDES
61
62namespace bsl {
63 // Import selected symbols into bsl namespace
64
65 using std::basic_ostream;
66 using std::endl;
67 using std::ends;
68 using std::flush;
69 using std::ostream;
70 using std::wostream;
71
72 // This file transitively includes standard <exception> header, so the
73 // following symbol needs to be added into bsl namespace.
74 using std::exception;
75
76 /// If, for the specified `stream`, `stream.rdbuf()` is a
77 /// `basic_syncbuf<CHAR,TRAITS,ALLOCATOR>`, make `stream` emit (i.e.,
78 /// transmit data to the wrapped stream buffer) when flushed, otherwise
79 /// has no effect. Return `stream`.
80 template <class CHAR, class TRAITS>
81 basic_ostream<CHAR,TRAITS>& emit_on_flush(
82 basic_ostream<CHAR,TRAITS>& stream);
83
84 /// Flush the specified `stream` as if by calling `stream.flush()`.
85 /// Then, if `stream.rdbuf()` actually points to a
86 /// `basic_syncbuf<CHAR,TRAITS,ALLOCATOR>` `buf`, call `buf.emit()`.
87 /// Return `stream`.
88 template <class CHAR, class TRAITS>
89 basic_ostream<CHAR,TRAITS>& flush_emit(basic_ostream<CHAR,TRAITS>& stream);
90
91 /// If, for the specified `stream`, `stream.rdbuf()` is a
92 /// `basic_syncbuf<CHAR,TRAITS,ALLOCATOR>`, make `stream` not emit
93 /// (i.e., don't transmit data to the wrapped stream buffer) when
94 /// flushed, otherwise has no effect. Return `stream`.
95 template <class CHAR, class TRAITS>
96 basic_ostream<CHAR,TRAITS>& noemit_on_flush(
97 basic_ostream<CHAR,TRAITS>& stream);
98
99#ifndef BDE_OMIT_INTERNAL_DEPRECATED
100 // Export additional names, leaked to support transitive dependencies in
101 // higher level (non BDE) Bloomberg code.
102# if !defined(BSLS_PLATFORM_CMP_MSVC) && __cplusplus < 201703L
103 // As some of these names are removed from C++17, take a sledgehammer to
104 // crack this nut, and remove all non-standard exports.
105 using std::bad_exception;
106 using std::basic_ios;
107 using std::basic_streambuf;
108 using std::bidirectional_iterator_tag;
109 using std::ctype;
110 using std::ctype_base;
111 using std::ctype_byname;
112 using std::forward_iterator_tag;
113 using std::input_iterator_tag;
114 using std::ios_base;
115 using std::istreambuf_iterator;
116 using std::iterator;
117 using std::locale;
118 using std::numpunct;
119 using std::numpunct_byname;
120 using std::ostreambuf_iterator;
121 using std::output_iterator_tag;
122 using std::random_access_iterator_tag;
123 using std::set_terminate;
124 using std::set_unexpected;
125 using std::swap;
126 using std::terminate;
127 using std::terminate_handler;
128 using std::uncaught_exception;
129 using std::unexpected;
130 using std::unexpected_handler;
131 using std::use_facet;
132# endif // MSVC, or C++2017
133#endif // BDE_OMIT_INTERNAL_DEPRECATED
134
135// ============================================================================
136// INLINE FUNCTION DEFINITIONS
137// ============================================================================
138
139template <class CHAR, class TRAITS>
140basic_ostream<CHAR,TRAITS>& emit_on_flush(basic_ostream<CHAR,TRAITS>& stream)
141{
142 using BloombergLP::bslstl::SyncBufBase;
143 if (SyncBufBase *p = dynamic_cast<SyncBufBase*>(stream.rdbuf())) {
144 BloombergLP::bslstl::SyncBufBaseUtil::setEmitOnSync(p, true);
145 }
146 return stream;
147}
148
149template <class CHAR, class TRAITS>
150basic_ostream<CHAR,TRAITS>& flush_emit(basic_ostream<CHAR,TRAITS>& stream)
151{
152 using BloombergLP::bslstl::SyncBufBase;
153 stream.flush();
154 if (SyncBufBase *p = dynamic_cast<SyncBufBase*>(stream.rdbuf())) {
155 typename basic_ostream<CHAR,TRAITS>::sentry ok(stream);
156 if (!ok) {
157 stream.setstate(ios_base::badbit);
158 }
159 else {
160 if (!BloombergLP::bslstl::SyncBufBaseUtil::emit(p)) {
161 stream.setstate(ios_base::badbit);
162 }
163 }
164 }
165 return stream;
166}
167
168template <class CHAR, class TRAITS>
169basic_ostream<CHAR,TRAITS>& noemit_on_flush(basic_ostream<CHAR,TRAITS>& stream)
170{
171 using BloombergLP::bslstl::SyncBufBase;
172 if (SyncBufBase *p = dynamic_cast<SyncBufBase*>(stream.rdbuf())) {
173 BloombergLP::bslstl::SyncBufBaseUtil::setEmitOnSync(p, false);
174 }
175 return stream;
176}
177
178} // close package namespace
179
180#endif
181
182// ----------------------------------------------------------------------------
183// Copyright 2023 Bloomberg Finance L.P.
184//
185// Licensed under the Apache License, Version 2.0 (the "License");
186// you may not use this file except in compliance with the License.
187// You may obtain a copy of the License at
188//
189// http://www.apache.org/licenses/LICENSE-2.0
190//
191// Unless required by applicable law or agreed to in writing, software
192// distributed under the License is distributed on an "AS IS" BASIS,
193// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
194// See the License for the specific language governing permissions and
195// limitations under the License.
196// ----------------------------- END-OF-FILE ----------------------------------
197
198/** @} */
199/** @} */
200/** @} */
#define BSLS_IDENT(str)
Definition bsls_ident.h:195
Definition bdlb_printmethods.h:283
basic_ostream< CHAR, TRAITS > & emit_on_flush(basic_ostream< CHAR, TRAITS > &stream)
Definition bslstl_ostream.h:140
basic_ostream< CHAR, TRAITS > & noemit_on_flush(basic_ostream< CHAR, TRAITS > &stream)
Definition bslstl_ostream.h:169
basic_ostream< CHAR, TRAITS > & flush_emit(basic_ostream< CHAR, TRAITS > &stream)
Definition bslstl_ostream.h:150
void swap(TYPE &a, TYPE &b)