BDE 4.14.0 Production release
Loading...
Searching...
No Matches
bsltf_streamutil.h
Go to the documentation of this file.
1/// @file bsltf_streamutil.h
2///
3/// The content of this file has been pre-processed for Doxygen.
4///
5
6
7// bsltf_streamutil.h -*-C++-*-
8#ifndef INCLUDED_BSLTF_STREAMUTIL
9#define INCLUDED_BSLTF_STREAMUTIL
10
11#ifndef INCLUDED_BSLS_IDENT
12#include <bsls_ident.h>
13#endif
14BSLS_IDENT("$Id: $")
15
16/// @defgroup bsltf_streamutil bsltf_streamutil
17/// @brief Provide streaming output operators for bsltf-defined types.
18/// @addtogroup bsl
19/// @{
20/// @addtogroup bsltf
21/// @{
22/// @addtogroup bsltf_streamutil
23/// @{
24///
25/// <h1> Outline </h1>
26/// * <a href="#bsltf_streamutil-purpose"> Purpose</a>
27/// * <a href="#bsltf_streamutil-classes"> Classes </a>
28///
29/// # Purpose {#bsltf_streamutil-purpose}
30/// Provide streaming output operators for bsltf-defined types.
31///
32/// # Classes {#bsltf_streamutil-classes}
33///
34///
35/// @see bslim_testutil, bslmt_testutil
36///
37/// @}
38/** @} */
39/** @} */
40
41/** @addtogroup bsl
42 * @{
43 */
44/** @addtogroup bsltf
45 * @{
46 */
47/** @addtogroup bsltf_streamutil
48 * @{
49 */
50
51//@DESCRIPTION: BDE components that define types normally define the
52// 'operator<<' used to stream the type out to standard library streams.
53// 'bsltf' components cannot do this for two reasons:
54//
55//: 1 Output should be based on the 'getIdentifier' method, and those methods
56//: are all static members of 'TemplateTestFacility', so a streaming operator
57//: cannot be defined in the components where the 'bsltf' types are defined,
58//: since those components are below 'TemplateTestFacility'.
59//:
60//: 2 It is our policy that all output in 'bsl' be done with 'printf'-style
61//: output until above 'bsl+bslhdrs', where 'bsl::ostream' is defined. The
62//: 'bsltf' package is far below 'bsl+bslhdrs'.
63//
64// We put the streaming operators here, above 'TemplateTestFacility', solving
65// concern 1, and make the 'stream' parameter of these 'operator<<' functions
66// be a template parameter, so that the functions can be defined without
67// needing 'bsl::ostream' to be declared, solving concern 2.
68//
69///Usage
70///-----
71// We have defined a 'cout' object that can stream 'int's and 'const char *'
72// null-terminated strings. Note that the operators defined by this component
73// require only that the left-hand argument be able to stream 'int's, so our
74// 'cout' more than satisfies this requirement.
75//
76// Then, in 'main', we define a 'bsltf::SimpleTestType' object 'st':
77//..
78// BloombergLP::bsltf::SimpleTestType st;
79//..
80// Now, we do some output, assigning 'st' several different values and
81// streaming them out:
82//..
83// cout << "Several values of 'st': ";
84//
85// for (int ii = 0; ii <= 100; ii += 20) {
86// st.setData(ii);
87//
88// cout << (ii ? ", " : "") << st;
89// }
90// cout << "\n";
91//..
92// Finally, we observe the output, which is:
93//..
94// Several values of 'st': 0, 20, 40, 60, 80, 100
95//..
96
97#ifndef INCLUDED_BSLSCM_VERSION
98#include <bslscm_version.h>
99#endif
100
101#ifndef INCLUDED_BSLTF_TEMPLATETESTFACILITY
103#endif
104
105
106namespace bsltf {
107
108// ============================================================================
109// INLINE DEFINITIONS
110// ============================================================================
111
112// FREE OPERATORS
113
114/// Stream the integer representing the value of the specified `object` to
115/// the specified `stream`. Return `stream`.
116template <class STREAM>
117inline
118STREAM& operator<<(STREAM& stream,
120{
121 stream << TemplateTestFacility::getIdentifier(object);
122 return stream;
123}
124
125/// Stream the integer representing the value of the specified `object` to
126/// the specified `stream`. Return `stream`.
127template <class STREAM>
128inline
129STREAM& operator<<(STREAM& stream,
130 const AllocBitwiseMoveableTestType& object)
131{
132 stream << TemplateTestFacility::getIdentifier(object);
133 return stream;
134}
135
136/// Stream the integer representing the value of the specified `object` to
137/// the specified `stream`. Return `stream`.
138template <class STREAM>
139inline
140STREAM& operator<<(STREAM& stream,
141 const AllocEmplacableTestType& object)
142{
143 stream << TemplateTestFacility::getIdentifier(object);
144 return stream;
145}
146
147/// Stream the integer representing the value of the specified `object` to
148/// the specified `stream`. Return `stream`.
149template <class STREAM>
150inline
151STREAM& operator<<(STREAM& stream,
152 const AllocTestType& object)
153{
154 stream << TemplateTestFacility::getIdentifier(object);
155 return stream;
156}
157
158/// Stream the integer representing the value of the specified `object` to
159/// the specified `stream`. Return `stream`.
160template <class STREAM>
161inline
162STREAM& operator<<(STREAM& stream,
163 const BitwiseCopyableTestType& object)
164{
165 stream << TemplateTestFacility::getIdentifier(object);
166 return stream;
167}
168
169/// Stream the integer representing the value of the specified `object` to
170/// the specified `stream`. Return `stream`.
171template <class STREAM>
172inline
173STREAM& operator<<(STREAM& stream,
174 const BitwiseMoveableTestType& object)
175{
176 stream << TemplateTestFacility::getIdentifier(object);
177 return stream;
178}
179
180/// Stream the integer representing the value of the specified `object` to
181/// the specified `stream`. Return `stream`.
182template <class STREAM>
183inline
184STREAM& operator<<(STREAM& stream,
185 const EmplacableTestType& object)
186{
187 stream << TemplateTestFacility::getIdentifier(object);
188 return stream;
189}
190
191/// Stream the integer representing the value of the specified `object` to
192/// the specified `stream`. Return `stream`.
193template <class STREAM>
194inline
195STREAM& operator<<(STREAM& stream,
196 const EnumeratedTestType::Enum& object)
197{
198 stream << TemplateTestFacility::getIdentifier(object);
199 return stream;
200}
201
202/// Stream the integer representing the value of the specified `object` to
203/// the specified `stream`. Return `stream`.
204template <class STREAM>
205inline
206STREAM& operator<<(STREAM& stream,
207 const MovableAllocTestType& object)
208{
209 stream << TemplateTestFacility::getIdentifier(object);
210 return stream;
211}
212
213/// Stream the integer representing the value of the specified `object` to
214/// the specified `stream`. Return `stream`.
215template <class STREAM>
216inline
217STREAM& operator<<(STREAM& stream,
218 const MovableTestType& object)
219{
220 stream << TemplateTestFacility::getIdentifier(object);
221 return stream;
222}
223
224/// Stream the integer representing the value of the specified `object` to
225/// the specified `stream`. Return `stream`.
226template <class STREAM>
227inline
228STREAM& operator<<(STREAM& stream,
229 const MoveOnlyAllocTestType& object)
230{
231 stream << TemplateTestFacility::getIdentifier(object);
232 return stream;
233}
234
235/// Stream the integer representing the value of the specified `object` to
236/// the specified `stream`. Return `stream`.
237template <class STREAM>
238inline
239STREAM& operator<<(STREAM& stream,
240 const NonAssignableTestType& object)
241{
242 stream << TemplateTestFacility::getIdentifier(object);
243 return stream;
244}
245
246/// Stream the integer representing the value of the specified `object` to
247/// the specified `stream`. Return `stream`.
248template <class STREAM>
249inline
250STREAM& operator<<(STREAM& stream,
251 const NonCopyConstructibleTestType& object)
252{
253 stream << TemplateTestFacility::getIdentifier(object);
254 return stream;
255}
256
257/// Stream the integer representing the value of the specified `object` to
258/// the specified `stream`. Return `stream`.
259template <class STREAM>
260inline
261STREAM& operator<<(STREAM& stream,
263{
264 stream << TemplateTestFacility::getIdentifier(object);
265 return stream;
266}
267
268/// Stream the integer representing the value of the specified `object` to
269/// the specified `stream`. Return `stream`.
270template <class STREAM>
271inline
272STREAM& operator<<(STREAM& stream,
273 const NonEqualComparableTestType& object)
274{
275 stream << TemplateTestFacility::getIdentifier(object);
276 return stream;
277}
278
279/// Stream the integer representing the value of the specified `object` to
280/// the specified `stream`. Return `stream`.
281template <class STREAM>
282inline
283STREAM& operator<<(STREAM& stream,
284 const NonOptionalAllocTestType& object)
285{
286 stream << TemplateTestFacility::getIdentifier(object);
287 return stream;
288}
289
290/// Stream the integer representing the value of the specified `object` to
291/// the specified `stream`. Return `stream`.
292template <class STREAM>
293inline
294STREAM& operator<<(STREAM& stream,
295 const NonTypicalOverloadsTestType& object)
296{
297 stream << TemplateTestFacility::getIdentifier(object);
298 return stream;
299}
300
301/// Stream the integer representing the value of the specified `object` to
302/// the specified `stream`. Return `stream`.
303template <class STREAM>
304inline
305STREAM& operator<<(STREAM& stream,
306 const SimpleTestType& object)
307{
308 stream << TemplateTestFacility::getIdentifier(object);
309 return stream;
310}
311
312/// Stream the integer representing the value of the specified `object` to
313/// the specified `stream`. Return `stream`.
314template <class STREAM, class ALLOC>
315inline
316STREAM& operator<<(STREAM& stream,
317 const StdAllocTestType<ALLOC>& object)
318{
319 stream << TemplateTestFacility::getIdentifier(object);
320 return stream;
321}
322
323/// Stream the integer representing the value of the specified `object` to
324/// the specified `stream`. Return `stream`.
325template <class STREAM>
326inline
327STREAM& operator<<(STREAM& stream,
328 const UnionTestType& object)
329{
330 stream << TemplateTestFacility::getIdentifier(object);
331 return stream;
332}
333
334} // close package namespace
335
336
337#endif
338
339// ----------------------------------------------------------------------------
340// Copyright 2018 Bloomberg Finance L.P.
341//
342// Licensed under the Apache License, Version 2.0 (the "License");
343// you may not use this file except in compliance with the License.
344// You may obtain a copy of the License at
345//
346// http://www.apache.org/licenses/LICENSE-2.0
347//
348// Unless required by applicable law or agreed to in writing, software
349// distributed under the License is distributed on an "AS IS" BASIS,
350// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
351// See the License for the specific language governing permissions and
352// limitations under the License.
353// ----------------------------- END-OF-FILE ----------------------------------
354
355/** @} */
356/** @} */
357/** @} */
Definition bsltf_allocbitwisemoveabletesttype.h:136
Definition bsltf_allocemplacabletesttype.h:236
Definition bsltf_alloctesttype.h:149
Definition bsltf_bitwisecopyabletesttype.h:131
Definition bsltf_bitwisemoveabletesttype.h:131
Definition bsltf_emplacabletesttype.h:104
Definition bsltf_movablealloctesttype.h:153
Definition bsltf_movabletesttype.h:148
Definition bsltf_moveonlyalloctesttype.h:147
Definition bsltf_nonassignabletesttype.h:104
Definition bsltf_noncopyconstructibletesttype.h:105
Definition bsltf_nondefaultconstructibletesttype.h:97
Definition bsltf_nonequalcomparabletesttype.h:103
Definition bsltf_nonoptionalalloctesttype.h:139
Definition bsltf_nontypicaloverloadstesttype.h:114
Definition bsltf_simpletesttype.h:130
Definition bsltf_stdalloctesttype.h:164
#define BSLS_IDENT(str)
Definition bsls_ident.h:195
Definition bsltf_allocargumenttype.h:92
STREAM & operator<<(STREAM &stream, const TemplateTestFacility::MethodPtr &object)
Definition bsltf_streamutil.h:118
Enum
Definition bsltf_enumeratedtesttype.h:94
int(TemplateTestFacility_StubClass::* MethodPtr)()
Definition bsltf_templatetestfacility.h:658
static int getIdentifier(const TYPE &object)
Definition bsltf_templatetestfacility.h:1944
Definition bsltf_uniontesttype.h:107