BDE 4.14.0 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: `emit_on_flush`, `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.
125
126 // CLASS METHODS
127
128 /// Atomically transfer any characters buffered by the specified
129 /// `syncBuf` object to the wrapped stream buffer, so that it appears in
130 /// the output stream as a contiguous sequence of characters. The
131 /// wrapped stream buffer is flushed if and only if a call was made to
132 /// `sync` since the most recent call to `emit` or construction. Return
133 /// `true` if `get_wrapped() != nullptr`, and all of the characters in
134 /// the associated output were successfully transferred, and the flush
135 /// (if any) succeeded; return `false` otherwise. The behavior is
136 /// undefined unless `syncBuf` is not null.
137 static bool emit(SyncBufBase *syncBuf);
138
139 /// Set the "emit-on-sync" property of the synchronized buffer to the
140 /// specified `value`. If "emit-on-sync" is `true`, the synchronized
141 /// buffer will emit (see `emitInternal`) its buffered contents on a
142 /// call to `sync` (or `pubsync`); otherwise the synchronized buffer
143 /// will not be emitted on a `sync`. The behavior is undefined unless
144 /// `syncBuf` is not null.
145 static void setEmitOnSync(SyncBufBase *syncBuf, bool value);
146};
147
148
149 // ---------------------
150 // class SyncBufBaseUtil
151 // ---------------------
152
153// CLASS METHODS
154inline
156{
157 BSLS_ASSERT(syncBuf);
158 return syncBuf->emitInternal();
159}
160
161inline
163{
164 BSLS_ASSERT(syncBuf);
165 syncBuf->setEmitOnSync(value);
166}
167
168} // close package namespace
169
170
171#endif
172
173// ----------------------------------------------------------------------------
174// Copyright 2023 Bloomberg Finance L.P.
175//
176// Licensed under the Apache License, Version 2.0 (the "License");
177// you may not use this file except in compliance with the License.
178// You may obtain a copy of the License at
179//
180// http://www.apache.org/licenses/LICENSE-2.0
181//
182// Unless required by applicable law or agreed to in writing, software
183// distributed under the License is distributed on an "AS IS" BASIS,
184// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
185// See the License for the specific language governing permissions and
186// limitations under the License.
187// ----------------------------- END-OF-FILE ----------------------------------
188
189/** @} */
190/** @} */
191/** @} */
Definition bslstl_syncbufbase.h:88
virtual ~SyncBufBase()
Destroy this object.
#define BSLS_ASSERT(X)
Definition bsls_assert.h:1804
#define BSLS_IDENT(str)
Definition bsls_ident.h:195
#define BSLS_KEYWORD_NOEXCEPT
Definition bsls_keyword.h:632
Definition bslstl_algorithm.h:82
Internal utils.
Definition bslstl_syncbufbase.h:124
static bool emit(SyncBufBase *syncBuf)
Definition bslstl_syncbufbase.h:155
static void setEmitOnSync(SyncBufBase *syncBuf, bool value)
Definition bslstl_syncbufbase.h:162