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