BDE 4.39.x Production Release
Loading...
Searching...
No Matches
bslfmt_print_ostream_imp.h
Go to the documentation of this file.
1/// @file bslfmt_print_ostream_imp.h
2///
3/// The content of this file has been pre-processed for Doxygen.
4///
5
6
7// bslfmt_print_ostream_imp.h -*-C++-*-
8#ifndef INCLUDED_BSLFMT_PRINT_OSTREAM_IMP
9#define INCLUDED_BSLFMT_PRINT_OSTREAM_IMP
10
11#include <bsls_ident.h>
12BSLS_IDENT("$Id: $")
13
14/// @defgroup bslfmt_print_ostream_imp bslfmt_print_ostream_imp
15/// @brief Provide a standard compliant `print(ostream)` implementation.
16/// @addtogroup bsl
17/// @{
18/// @addtogroup bslfmt
19/// @{
20/// @addtogroup bslfmt_print_ostream_imp
21/// @{
22///
23/// <h1> Outline </h1>
24/// * <a href="#bslfmt_print_ostream_imp-purpose"> Purpose</a>
25/// * <a href="#bslfmt_print_ostream_imp-classes"> Classes </a>
26/// * <a href="#bslfmt_print_ostream_imp-canonical-header"> Canonical Header </a>
27/// * <a href="#bslfmt_print_ostream_imp-description"> Description </a>
28///
29/// # Purpose {#bslfmt_print_ostream_imp-purpose}
30/// Provide a standard compliant `print(ostream)` implementation.
31///
32/// # Classes {#bslfmt_print_ostream_imp-classes}
33///
34///
35/// # Canonical Header {#bslfmt_print_ostream_imp-canonical-header}
36/// bsl_ostream.h
37///
38/// @see ISO C++ Standard, <ostream>, <print>
39///
40/// # Description {#bslfmt_print_ostream_imp-description}
41/// This component provides, in the `BloombergLP::bslfmt`
42/// namespace, the `print` and related functions exposed by the standard
43/// <ostream> header. These are available for C++03 and later.
44/// @}
45/** @} */
46/** @} */
47
48/** @addtogroup bsl
49 * @{
50 */
51/** @addtogroup bslfmt
52 * @{
53 */
54/** @addtogroup bslfmt_print_ostream_imp
55 * @{
56 */
57
58#include <bslscm_version.h>
59
60#include <bslfmt_format.h>
61
62#include <bslstl_string.h>
63#include <bslstl_stringview.h>
64
65#include <ostream>
66
67#if BSLS_COMPILERFEATURES_SIMULATE_CPP11_FEATURES
68// clang-format off
69// Include version that can be compiled with C++03
70// Generated on Wed Nov 19 07:03:37 2025
71// Command line: sim_cpp11_features.pl bslfmt_print_ostream_imp.h
72
73# define COMPILING_BSLFMT_PRINT_OSTREAM_IMP_H
75# undef COMPILING_BSLFMT_PRINT_OSTREAM_IMP_H
76
77// clang-format on
78#else
79
80#if defined(BSLS_COMPILERFEATURES_SUPPORT_ALIAS_TEMPLATES) && \
81 defined(BSLS_COMPILERFEATURES_SUPPORT_VARIADIC_TEMPLATES)
82# define BSLFMT_FORMAT_STRING_PARAMETER bsl::format_string<t_ARGS...>
83#else
84// We cannot define format_string<t_ARGS...> in a C++03 compliant manner, so
85// have to use non-template versions instead.
86# define BSLFMT_FORMAT_STRING_PARAMETER bsl::format_string
87#endif
88
89
90namespace bslfmt {
91
92 // --------------
93 // FREE FUNCTIONS
94 // --------------
95
96#if !BSLS_COMPILERFEATURES_SIMULATE_CPP11_FEATURES
97/// Format the specified `args` using `bsl::format_to` according to the
98/// specification given by the specified `fmt`, and write the result of this
99/// operation to the specified `stream`. In the event of formatting error
100/// throw the exception @ref format_error , in the event of I/O error throw the
101/// exception @ref system_error , on allocation failure throw @ref bad_alloc .
102///
103/// \pre The behavior is undefined unless `stream` is a valid pointer to an output C
104/// stream.
105template <class... t_ARGS>
106void print(std::ostream& stream,
108 t_ARGS&&... args);
109
110/// Format the specified `args` using `bsl::format_to` according to the
111/// specification given by the specified `fmt`, append `\n`, and write the
112/// result of this operation to the specified `stream`. In the event of
113/// formatting error throw the exception @ref format_error , in the event of I/O
114/// error throw the exception @ref system_error , on allocation failure throw `bad_alloc`.
115///
116/// \pre The behavior is undefined unless `stream` is a valid pointer
117/// to an output C stream.
118template <class... t_ARGS>
119void println(std::ostream& stream,
121 t_ARGS&&... args);
122#endif
123
124/// Write `\n` to the specified `stream`.
125/// \pre The behavior is undefined unless
126/// `stream` is a valid pointer to an output C stream.
127void println(std::ostream& stream);
128
129/// Format the specified `args` using `bsl::vformat_to` according to the
130/// specification given by the specified `fmt`, and write the result of this
131/// operation to the specified `stream`. In the event of formatting error
132/// throw the exception @ref format_error , in the event of I/O error throw the
133/// exception @ref system_error , on allocation failure throw @ref bad_alloc .
134///
135/// \pre The behavior is undefined unless `stream` is a valid pointer to an output C
136/// stream.
137void vprint_nonunicode(std::ostream& stream,
139 bsl::format_args args);
140
141/// Format the specified `args` using `bsl::vformat_to` according to the
142/// specification given by the specified `fmt`, and write the result of this
143/// operation to the specified `stream`. In the event of formatting error
144/// throw the exception @ref format_error , in the event of I/O error throw the
145/// exception @ref system_error , on allocation failure throw @ref bad_alloc .
146///
147/// \pre The behavior is undefined unless `stream` is a valid pointer to an output C
148/// stream.
149void vprint_unicode(std::ostream& stream,
151 bsl::format_args args);
152
153// ============================================================================
154// INLINE DEFINITIONS
155// ============================================================================
156
157 // --------------
158 // FREE FUNCTIONS
159 // --------------
160
161#if !BSLS_COMPILERFEATURES_SIMULATE_CPP11_FEATURES
162template <class... t_ARGS>
163inline
164void print(std::ostream& stream,
166 t_ARGS&&... args)
167{
169 fmt.get(),
170 bsl::make_format_args(args...));
171}
172
173template <class... t_ARGS>
174inline
175void println(std::ostream& stream,
177 t_ARGS&&... args)
178{
179 bslfmt::print(stream,
180 "{}\n",
181 bsl::vformat(fmt.get(), bsl::make_format_args(args...)));
182}
183#endif
184
185inline
186void println(std::ostream& stream)
187{
188 bslfmt::print(stream, "\n");
189}
190
191} // close package namespace
192
193
194#undef BSLFMT_FORMAT_STRING_PARAMETER
195
196#endif // End C++11 code
197
198#endif
199
200// ----------------------------------------------------------------------------
201// Copyright 2025 Bloomberg Finance L.P.
202//
203// Licensed under the Apache License, Version 2.0 (the "License");
204// you may not use this file except in compliance with the License.
205// You may obtain a copy of the License at
206//
207// http://www.apache.org/licenses/LICENSE-2.0
208//
209// Unless required by applicable law or agreed to in writing, software
210// distributed under the License is distributed on an "AS IS" BASIS,
211// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
212// See the License for the specific language governing permissions and
213// limitations under the License.
214// ----------------------------- END-OF-FILE ----------------------------------
215
216/** @} */
217/** @} */
218/** @} */
Definition bslstl_stringview.h:471
#define BSLFMT_FORMAT_STRING_PARAMETER
Definition bslfmt_format_imp.h:209
#define BSLS_IDENT(str)
BSLS_IDENT() - insert string into .comment binary segment (if supported)
Definition bsls_ident.h:238
Definition bslfmt_enablestreamedformatter.h:130
void print(BSLFMT_FORMAT_STRING_PARAMETER fmt, t_ARGS &&... args)
Definition bslfmt_print_imp.h:263
void vprint_unicode(bsl::string_view fmt, bsl::format_args args)
Definition bslfmt_print_imp.h:300
void println()
Write \n into stdout.
Definition bslfmt_print_imp.h:288
void vprint_nonunicode(bsl::string_view fmt, bsl::format_args args)
Definition bslfmt_print_imp.h:294