BDE 4.39.x Production Release
Loading...
Searching...
No Matches
baljsn_datumdecoderoptions.h
Go to the documentation of this file.
1/// @file baljsn_datumdecoderoptions.h
2///
3/// The content of this file has been pre-processed for Doxygen.
4///
5
6
7// baljsn_datumdecoderoptions.h -*-C++-*-
8#ifndef INCLUDED_BALJSN_DATUMDECODEROPTIONS
9#define INCLUDED_BALJSN_DATUMDECODEROPTIONS
10
11#include <bsls_ident.h>
12BSLS_IDENT("$Id: $")
13
14/// @defgroup baljsn_datumdecoderoptions baljsn_datumdecoderoptions
15/// @brief Provide options for decoding JSON into a `Datum` object.
16/// @addtogroup bal
17/// @{
18/// @addtogroup baljsn
19/// @{
20/// @addtogroup baljsn_datumdecoderoptions
21/// @{
22///
23/// <h1> Outline </h1>
24/// * <a href="#baljsn_datumdecoderoptions-purpose"> Purpose</a>
25/// * <a href="#baljsn_datumdecoderoptions-classes"> Classes </a>
26/// * <a href="#baljsn_datumdecoderoptions-description"> Description </a>
27/// * <a href="#baljsn_datumdecoderoptions-attributes"> Attributes </a>
28/// * <a href="#baljsn_datumdecoderoptions-usage"> Usage </a>
29/// * <a href="#baljsn_datumdecoderoptions-example-1-creating-and-populating-an-options-object"> Example 1: Creating and Populating an Options Object </a>
30///
31/// # Purpose {#baljsn_datumdecoderoptions-purpose}
32/// Provide options for decoding JSON into a `Datum` object.
33///
34/// # Classes {#baljsn_datumdecoderoptions-classes}
35///
36/// - baljsn::DatumDecoderOptions: options for decoding JSON into a `Datum`
37///
38/// @see baljsn_datumutil
39///
40/// # Description {#baljsn_datumdecoderoptions-description}
41/// This component provides a single, simply constrained
42/// (value-semantic) attribute class, `baljsn::DatumDecoderOptions`, that is
43/// used to specify options for decoding `Datum` objects in the JSON format (see
44/// `baljsn::DatumUtil`).
45///
46/// ## Attributes {#baljsn_datumdecoderoptions-attributes}
47///
48///
49/// @code
50/// Name Type Default Simple Constraints
51/// ------------------ ----------- ------- ------------------
52/// maxNestedDepth int 64 > 0
53/// @endcode
54/// * `maxNestedDepth`: the maximum depth to which JSON objects and arrays are
55/// allowed to be nested before the JSON decoder reports an error. For
56/// example, if `maxNestedDepth` is 8, and a JSON text has 9 consecutive open
57/// brackets (`[`) the decoding will return an error. This option can be
58/// used to prevent poorly formed, or malicious JSON text from causing a
59/// stack overflow.
60///
61/// ## Usage {#baljsn_datumdecoderoptions-usage}
62///
63///
64/// This section illustrates intended use of this component.
65///
66/// ### Example 1: Creating and Populating an Options Object {#baljsn_datumdecoderoptions-example-1-creating-and-populating-an-options-object}
67///
68///
69/// This component is designed to be used at a higher level to set the options
70/// for decoding `Datum` objects in the JSON format. This example shows how to
71/// create and populate an options object.
72///
73/// First, we default-construct a `baljsn::DatumDecoderOptions` object:
74/// @code
75/// const int MAX_NESTED_DEPTH = 16;
76///
77/// baljsn::DatumDecoderOptions options;
78/// assert(64 == options.maxNestedDepth());
79/// @endcode
80/// Finally, we populate that object to limit the maximum nested depth using a
81/// pre-defined limit:
82/// @code
83/// options.setMaxNestedDepth(MAX_NESTED_DEPTH);
84/// assert(MAX_NESTED_DEPTH == options.maxNestedDepth());
85/// @endcode
86/// @}
87/** @} */
88/** @} */
89
90/** @addtogroup bal
91 * @{
92 */
93/** @addtogroup baljsn
94 * @{
95 */
96/** @addtogroup baljsn_datumdecoderoptions
97 * @{
98 */
99
100#include <balscm_version.h>
101
102#include <bslalg_typetraits.h>
103
104#include <bsl_limits.h>
105#include <bsl_iosfwd.h>
106
107#include <bsls_assert.h>
108#include <bsls_objectbuffer.h>
109#include <bsls_review.h>
110
111
112
113namespace baljsn { class DatumDecoderOptions; }
114namespace baljsn {
115
116 // =========================
117 // class DatumDecoderOptions
118 // =========================
119
120/// This simply constrained (value-semantic) attribute class specifies options
121/// for decoding `Datum` objects in the JSON format. See the @ref baljsn_datumdecoderoptions-attributes section for information on the class attributes.
122///
123/// \note Note that the class
124/// invariants are identically the constraints on the individual attributes.
125///
126/// See @ref baljsn_datumdecoderoptions
128
129 // INSTANCE DATA
130
131 // maximum nesting level for JSON objects and arrays
132 int d_maxNestedDepth;
133
134 public:
135 // CONSTANTS
137
138 public:
139 // CREATORS
140
141 /// Create an object of type `DatumDecoderOptions` having the default
142 /// value.
144
145 /// Create an object of type `DatumDecoderOptions` having the value of the
146 /// specified `original` object.
148
149 /// Destroy this object.
151
152 // MANIPULATORS
153
154 /// Assign to this object the value of the specified `rhs` object.
156
157 /// Reset this object to the default value (i.e., its value upon default
158 /// construction).
159 void reset();
160
161 /// Set the "maxNestedDepth" attribute of this object to the specified
162 /// `value`.
163 void setMaxNestedDepth(int value);
164
165 // ACCESSORS
166
167 /// Return the "maxNestedDepth" attribute of this object.
168 int maxNestedDepth() const;
169
170 // Aspects
171
172 /// Format this object to the specified output `stream` at the optionally
173 /// specified indentation `level` and return a reference to the modifiable
174 /// `stream`. If `level` is specified, optionally specify
175 /// `spacesPerLevel`, the number of spaces per indentation level for this
176 /// and all of its nested objects. Each line is indented by the absolute
177 /// value of `level * spacesPerLevel`. If `level` is negative, suppress
178 /// indentation of the first line. If `spacesPerLevel` is negative,
179 /// suppress line breaks and format the entire output on one line. If
180 /// `stream` is initially invalid, this operation has no effect.
181 ///
182 /// \note Note that a trailing newline is provided in multiline mode only.
183 bsl::ostream& print(bsl::ostream& stream,
184 int level = 0,
185 int spacesPerLevel = 4) const;
186};
187
188// FREE OPERATORS
189
190/// Return `true` if the specified `lhs` and `rhs` attribute objects have
191/// the same value, and `false` otherwise. Two attribute objects have the
192/// same value if each respective attribute has the same value.
193inline
194bool operator==(const DatumDecoderOptions& lhs,
195 const DatumDecoderOptions& rhs);
196
197/// Return `true` if the specified `lhs` and `rhs` attribute objects do not
198/// have the same value, and `false` otherwise. Two attribute objects do
199/// not have the same value if one or more respective attributes differ in
200/// values.
201inline
202bool operator!=(const DatumDecoderOptions& lhs,
203 const DatumDecoderOptions& rhs);
204
205/// Format the specified `rhs` to the specified output `stream` and return a
206/// reference to the modifiable `stream`.
207inline
208bsl::ostream& operator<<(bsl::ostream& stream, const DatumDecoderOptions& rhs);
209
210// ============================================================================
211// INLINE FUNCTION DEFINITIONS
212// ============================================================================
213
214 // -------------------------
215 // class DatumDecoderOptions
216 // -------------------------
217
218inline
220{
221 BSLS_ASSERT(0 < value);
222
223 d_maxNestedDepth = value;
224}
225
226// ACCESSORS
227inline
229{
230 return d_maxNestedDepth;
231}
232
233} // close package namespace
234
235// FREE OPERATORS
236
237inline
240{
241 return lhs.maxNestedDepth() == rhs.maxNestedDepth();
242}
243
244inline
247{
248 return lhs.maxNestedDepth() != rhs.maxNestedDepth();
249}
250
251inline
252bsl::ostream& baljsn::operator<<(bsl::ostream& stream,
254{
255 return rhs.print(stream, 0, -1);
256}
257
258
259#endif
260
261// ----------------------------------------------------------------------------
262// Copyright 2020 Bloomberg Finance L.P.
263//
264// Licensed under the Apache License, Version 2.0 (the "License");
265// you may not use this file except in compliance with the License.
266// You may obtain a copy of the License at
267//
268// http://www.apache.org/licenses/LICENSE-2.0
269//
270// Unless required by applicable law or agreed to in writing, software
271// distributed under the License is distributed on an "AS IS" BASIS,
272// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
273// See the License for the specific language governing permissions and
274// limitations under the License.
275// ----------------------------- END-OF-FILE ----------------------------------
276
277/** @} */
278/** @} */
279/** @} */
Definition baljsn_datumdecoderoptions.h:127
DatumDecoderOptions(const DatumDecoderOptions &original)
int maxNestedDepth() const
Return the "maxNestedDepth" attribute of this object.
Definition baljsn_datumdecoderoptions.h:228
void setMaxNestedDepth(int value)
Definition baljsn_datumdecoderoptions.h:219
DatumDecoderOptions & operator=(const DatumDecoderOptions &rhs)
Assign to this object the value of the specified rhs object.
static const int s_DEFAULT_INITIALIZER_MAX_NESTED_DEPTH
Definition baljsn_datumdecoderoptions.h:136
bsl::ostream & print(bsl::ostream &stream, int level=0, int spacesPerLevel=4) const
~DatumDecoderOptions()
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
Definition baljsn_convertfromjsonoptions.h:112
bool operator==(const DatumDecoderOptions &lhs, const DatumDecoderOptions &rhs)
bsl::ostream & operator<<(bsl::ostream &stream, const DatumDecoderOptions &rhs)
bool operator!=(const DatumDecoderOptions &lhs, const DatumDecoderOptions &rhs)
ALLOCATOR const STRING_VIEW_LIKE_TYPE & rhs
Definition bslstl_string.h:3918
ALLOCATOR & lhs
Definition bslstl_string.h:3917