BDE 4.39.x Production Release
Loading...
Searching...
No Matches
ball_recordformatterfunctor.h
Go to the documentation of this file.
1/// @file ball_recordformatterfunctor.h
2///
3/// The content of this file has been pre-processed for Doxygen.
4///
5
6
7// ball_recordformatterfunctor.h -*-C++-*-
8#ifndef INCLUDED_BALL_RECORDFORMATTERFUNCTOR
9#define INCLUDED_BALL_RECORDFORMATTERFUNCTOR
10
11#include <bsls_ident.h>
12BSLS_IDENT("$Id: $")
13
14/// @defgroup ball_recordformatterfunctor ball_recordformatterfunctor
15/// @brief Provide a typedef for the record formatter functor.
16/// @addtogroup bal
17/// @{
18/// @addtogroup ball
19/// @{
20/// @addtogroup ball_recordformatterfunctor
21/// @{
22///
23/// <h1> Outline </h1>
24/// * <a href="#ball_recordformatterfunctor-purpose"> Purpose</a>
25/// * <a href="#ball_recordformatterfunctor-classes"> Classes </a>
26/// * <a href="#ball_recordformatterfunctor-description"> Description </a>
27/// * <a href="#ball_recordformatterfunctor-usage"> Usage </a>
28/// * <a href="#ball_recordformatterfunctor-example-1-defining-a-record-formatter-function"> Example 1: Defining a Record Formatter Function </a>
29///
30/// # Purpose {#ball_recordformatterfunctor-purpose}
31/// Provide a typedef for the record formatter functor.
32///
33/// # Classes {#ball_recordformatterfunctor-classes}
34///
35/// - ball::RecordFormatterFunctor: struct containing formatter functor typedef
36///
37/// @see ball_record, ball_recordformatterregistryutil
38///
39/// # Description {#ball_recordformatterfunctor-description}
40/// This component provides a `struct`,
41/// `ball::RecordFormatterFunctor`, that contains a single typedef, `Type`,
42/// which is the type of the functor used for formatting log records to a
43/// stream.
44///
45/// ## Usage {#ball_recordformatterfunctor-usage}
46///
47///
48/// This section illustrates intended use of this component.
49///
50/// ### Example 1: Defining a Record Formatter Function {#ball_recordformatterfunctor-example-1-defining-a-record-formatter-function}
51///
52///
53/// Suppose we want to define a simple function that formats log records. We
54/// can use `ball::RecordFormatterFunctor::Type` to declare a functor that
55/// conforms to the expected signature.
56///
57/// First, we include the necessary headers and define a simple formatting
58/// function:
59/// @code
60/// void myFormatter(bsl::ostream& stream, const ball::Record& record)
61/// {
62/// stream << "Log: " << record.fixedFields().message();
63/// }
64/// @endcode
65/// Then, we can assign this function to a variable of the functor type:
66/// @code
67/// ball::RecordFormatterFunctor::Type formatter = &myFormatter;
68/// @endcode
69/// Finally, we can use this functor to format a record:
70/// @code
71/// ball::RecordAttributes attr;
72/// attr.setMessage("Hello");
73/// ball::Record record(attr, ball::UserFields());
74///
75/// bsl::ostringstream oss;
76/// formatter(oss, record);
77/// assert(oss.str() == "Log: Hello");
78/// @endcode
79/// @}
80/** @} */
81/** @} */
82
83/** @addtogroup bal
84 * @{
85 */
86/** @addtogroup ball
87 * @{
88 */
89/** @addtogroup ball_recordformatterfunctor
90 * @{
91 */
92
93#include <balscm_version.h>
94
95#include <bsl_functional.h>
96#include <bsl_iosfwd.h>
97
98
99namespace ball {
100
101class Record;
102
103 // =============================
104 // struct RecordFormatterFunctor
105 // =============================
106
107/// This struct provides a namespace for a typedef of the functor used for
108/// formatting log records to a stream.
109///
110/// See @ref ball_recordformatterfunctor
112
113 /// `Type` is the type of the functor used for formatting log records
114 /// to a stream.
115 typedef bsl::function<void(bsl::ostream&, const Record&)> Type;
116};
117
118} // close package namespace
119
120
121#endif // INCLUDED_BALL_RECORDFORMATTERFUNCTOR
122
123// ----------------------------------------------------------------------------
124// Copyright 2025 Bloomberg Finance L.P.
125//
126// Licensed under the Apache License, Version 2.0 (the "License");
127// you may not use this file except in compliance with the License.
128// You may obtain a copy of the License at
129//
130// http://www.apache.org/licenses/LICENSE-2.0
131//
132// Unless required by applicable law or agreed to in writing, software
133// distributed under the License is distributed on an "AS IS" BASIS,
134// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
135// See the License for the specific language governing permissions and
136// limitations under the License.
137// ----------------------------- END-OF-FILE ----------------------------------
138
139/** @} */
140/** @} */
141/** @} */
Definition ball_record.h:176
Forward declaration.
Definition bslstl_function.h:946
#define BSLS_IDENT(str)
BSLS_IDENT() - insert string into .comment binary segment (if supported)
Definition bsls_ident.h:238
Definition ball_administration.h:214
Definition ball_recordformatterfunctor.h:111
bsl::function< void(bsl::ostream &, const Record &)> Type
Definition ball_recordformatterfunctor.h:115