BDE 4.39.x Production Release
Loading...
Searching...
No Matches
bslstl_syncbufbase.h
Go to the documentation of this file.
1/// @file bslstl_syncbufbase.h
2///
3/// The content of this file has been pre-processed for Doxygen.
4///
5
6
7// bslstl_syncbufbase.h -*-C++-*-
8#ifndef INCLUDED_BSLSTL_SYNCBUFBASE
9#define INCLUDED_BSLSTL_SYNCBUFBASE
10
11#include <bsls_ident.h>
12BSLS_IDENT("$Id: $")
13
14/// @defgroup bslstl_syncbufbase bslstl_syncbufbase
15/// @brief Provide an allocator-independent base-class for `basic_syncbuf`.
16/// @addtogroup bsl
17/// @{
18/// @addtogroup bslstl
19/// @{
20/// @addtogroup bslstl_syncbufbase
21/// @{
22///
23/// <h1> Outline </h1>
24/// * <a href="#bslstl_syncbufbase-purpose"> Purpose</a>
25/// * <a href="#bslstl_syncbufbase-classes"> Classes </a>
26/// * <a href="#bslstl_syncbufbase-description"> Description </a>
27///
28/// # Purpose {#bslstl_syncbufbase-purpose}
29/// Provide an allocator-independent base-class for @ref basic_syncbuf .
30///
31/// # Classes {#bslstl_syncbufbase-classes}
32///
33/// - bsl::SyncBufBase: allocator-independent base of @ref basic_syncbuf .
34///
35/// @see bslstl_syncbuf
36///
37/// # Description {#bslstl_syncbufbase-description}
38/// This component is for internal use only. Please don't use it
39/// directly.
40///
41/// This component provides a protocol class, `SyncBufBase`, that is intended
42/// for use as a base class for synchronized stream buffers. The `SyncBufBase`
43/// protocol provides methods to emit the synchronized buffer, and mark the
44/// buffer to be emitted on a call to `sync` on an associated stream. This
45/// operations are exposed by `SyncBufBaseUtil` for use by standard functions,
46/// like `bsl::emit_on_flush`, `bsl::noemit_on_flush`, and `bsl::flush_emit`,
47/// while not exposing them into the public interface of derived types (like
48/// @ref basic_syncbuf ) whose interface in defined by an external standard.
49///
50/// Factoring these operations into a non-templatized base class allows
51/// operations (like `bsl::emit_on_flush` etc) to applied to derived objects in
52/// contexts where it is impossible to deduce the `ALLOCATOR` type of the
53/// inheriting synchornized buffer.
54/// @}
55/** @} */
56/** @} */
57
58/** @addtogroup bsl
59 * @{
60 */
61/** @addtogroup bslstl
62 * @{
63 */
64/** @addtogroup bslstl_syncbufbase
65 * @{
66 */
67
68#include <bslscm_version.h>
69
70#include <bsls_assert.h>
71#include <bsls_keyword.h>
72
73
74namespace bslstl {
75
76struct SyncBufBaseUtil; // forward
77
78 // =================
79 // class SyncBufBase
80 // =================
81
82/// Allocator-independent base of @ref basic_syncbuf . Also this is used by the
83/// manipulators: @ref emit_on_flush , @ref noemit_on_flush , @ref flush_emit (the
84/// `ALLOCATOR` template argument cannot be deduced from
85/// `basic_ostream<CHAR_TYPE, CHAR_TRAITS>`).
86///
87/// See @ref bslstl_syncbufbase
89
90 // PRIVATE MANIPULATORS
91
92 /// Atomically transfer any characters buffered by this object to the
93 /// wrapped stream buffer, so that it appears in the output stream as a
94 /// contiguous sequence of characters. The wrapped stream buffer is
95 /// flushed if and only if a call was made to `sync` since the most
96 /// recent call to `emit` or construction. Return `true` if
97 /// `get_wrapped() != nullptr`, and all of the characters in the
98 /// associated output were successfully transferred, and the flush (if
99 /// any) succeeded; return `false` otherwise.
100 virtual bool emitInternal() = 0;
101
102 /// Set the "emit-on-sync" property of the synchronized buffer to the
103 /// specified `value`. If "emit-on-sync" is `true`, the synchronized
104 /// buffer will emit (see `emitInternal`) its buffered contents on a
105 /// call to `sync` (or `pubsync`); otherwise the synchronized buffer
106 /// will not be emitted on a `sync`.
107 virtual void setEmitOnSync(bool value) BSLS_KEYWORD_NOEXCEPT = 0;
108
109 // FRIENDS
110 friend struct SyncBufBaseUtil;
111
112 public:
113 // CREATORS
114
115 /// Destroy this object.
116 virtual ~SyncBufBase();
117};
118
119 // =====================
120 // class SyncBufBaseUtil
121 // =====================
122
123/// Internal utils.
124///
125/// See @ref bslstl_syncbufbase
127
128 // CLASS METHODS
129
130 /// Atomically transfer any characters buffered by the specified
131 /// `syncBuf` object to the wrapped stream buffer, so that it appears in
132 /// the output stream as a contiguous sequence of characters. The
133 /// wrapped stream buffer is flushed if and only if a call was made to
134 /// `sync` since the most recent call to `emit` or construction. Return
135 /// `true` if `get_wrapped() != nullptr`, and all of the characters in
136 /// the associated output were successfully transferred, and the flush
137 /// (if any) succeeded; return `false` otherwise.
138 ///
139 /// \pre The behavior is undefined unless `syncBuf` is not null.
140 static bool emitInternal(SyncBufBase *syncBuf);
141
142 /// Set the "emit-on-sync" property of the synchronized buffer to the
143 /// specified `value`. If "emit-on-sync" is `true`, the synchronized
144 /// buffer will emit (see `emitInternal`) its buffered contents on a
145 /// call to `sync` (or `pubsync`); otherwise the synchronized buffer will not be emitted on a `sync`.
146 ///
147 /// \pre The behavior is undefined unless
148 /// `syncBuf` is not null.
149 static void setEmitOnSync(SyncBufBase *syncBuf, bool value);
150};
151
152
153 // ---------------------
154 // class SyncBufBaseUtil
155 // ---------------------
156
157// CLASS METHODS
158inline
160{
161 BSLS_ASSERT(syncBuf);
162 return syncBuf->emitInternal();
163}
164
165inline
167{
168 BSLS_ASSERT(syncBuf);
169 syncBuf->setEmitOnSync(value);
170}
171
172} // close package namespace
173
174
175#endif
176
177// ----------------------------------------------------------------------------
178// Copyright 2023 Bloomberg Finance L.P.
179//
180// Licensed under the Apache License, Version 2.0 (the "License");
181// you may not use this file except in compliance with the License.
182// You may obtain a copy of the License at
183//
184// http://www.apache.org/licenses/LICENSE-2.0
185//
186// Unless required by applicable law or agreed to in writing, software
187// distributed under the License is distributed on an "AS IS" BASIS,
188// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
189// See the License for the specific language governing permissions and
190// limitations under the License.
191// ----------------------------- END-OF-FILE ----------------------------------
192
193/** @} */
194/** @} */
195/** @} */
Definition bslstl_syncbufbase.h:88
virtual ~SyncBufBase()
Destroy this object.
#define BSLS_ASSERT(X)
Definition bsls_assert.h:1976
#define BSLS_IDENT(str)
BSLS_IDENT() - insert string into .comment binary segment (if supported)
Definition bsls_ident.h:238
#define BSLS_KEYWORD_NOEXCEPT
Definition bsls_keyword.h:674
Definition bslstl_algorithm.h:84
Definition bslstl_syncbufbase.h:126
static void setEmitOnSync(SyncBufBase *syncBuf, bool value)
Definition bslstl_syncbufbase.h:166
static bool emitInternal(SyncBufBase *syncBuf)
Definition bslstl_syncbufbase.h:159