BDE 4.14.0 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
122/// section for information on the class attributes. Note that the class
123/// invariants are identically the constraints on the individual attributes.
124///
125/// See @ref baljsn_datumdecoderoptions
127
128 // INSTANCE DATA
129
130 // maximum nesting level for JSON objects and arrays
131 int d_maxNestedDepth;
132
133 public:
134 // CONSTANTS
136
137 public:
138 // CREATORS
139
140 /// Create an object of type `DatumDecoderOptions` having the default
141 /// value.
143
144 /// Create an object of type `DatumDecoderOptions` having the value of the
145 /// specified `original` object.
147
148 /// Destroy this object.
150
151 // MANIPULATORS
152
153 /// Assign to this object the value of the specified `rhs` object.
155
156 /// Reset this object to the default value (i.e., its value upon default
157 /// construction).
158 void reset();
159
160 /// Set the "maxNestedDepth" attribute of this object to the specified
161 /// `value`.
162 void setMaxNestedDepth(int value);
163
164 // ACCESSORS
165
166 /// Return the "maxNestedDepth" attribute of this object.
167 int maxNestedDepth() const;
168
169 // Aspects
170
171 /// Format this object to the specified output `stream` at the optionally
172 /// specified indentation `level` and return a reference to the modifiable
173 /// `stream`. If `level` is specified, optionally specify
174 /// `spacesPerLevel`, the number of spaces per indentation level for this
175 /// and all of its nested objects. Each line is indented by the absolute
176 /// value of `level * spacesPerLevel`. If `level` is negative, suppress
177 /// indentation of the first line. If `spacesPerLevel` is negative,
178 /// suppress line breaks and format the entire output on one line. If
179 /// `stream` is initially invalid, this operation has no effect. Note that
180 /// a trailing newline is provided in multiline mode only.
181 bsl::ostream& print(bsl::ostream& stream,
182 int level = 0,
183 int spacesPerLevel = 4) const;
184};
185
186// FREE OPERATORS
187
188/// Return `true` if the specified `lhs` and `rhs` attribute objects have
189/// the same value, and `false` otherwise. Two attribute objects have the
190/// same value if each respective attribute has the same value.
191inline
192bool operator==(const DatumDecoderOptions& lhs,
193 const DatumDecoderOptions& rhs);
194
195/// Return `true` if the specified `lhs` and `rhs` attribute objects do not
196/// have the same value, and `false` otherwise. Two attribute objects do
197/// not have the same value if one or more respective attributes differ in
198/// values.
199inline
200bool operator!=(const DatumDecoderOptions& lhs,
201 const DatumDecoderOptions& rhs);
202
203/// Format the specified `rhs` to the specified output `stream` and return a
204/// reference to the modifiable `stream`.
205inline
206bsl::ostream& operator<<(bsl::ostream& stream, const DatumDecoderOptions& rhs);
207
208// ============================================================================
209// INLINE FUNCTION DEFINITIONS
210// ============================================================================
211
212 // -------------------------
213 // class DatumDecoderOptions
214 // -------------------------
215
216inline
218{
219 BSLS_ASSERT(0 < value);
220
221 d_maxNestedDepth = value;
222}
223
224// ACCESSORS
225inline
227{
228 return d_maxNestedDepth;
229}
230
231} // close package namespace
232
233// FREE OPERATORS
234
235inline
238{
239 return lhs.maxNestedDepth() == rhs.maxNestedDepth();
240}
241
242inline
245{
246 return lhs.maxNestedDepth() != rhs.maxNestedDepth();
247}
248
249inline
250bsl::ostream& baljsn::operator<<(bsl::ostream& stream,
252{
253 return rhs.print(stream, 0, -1);
254}
255
256
257#endif
258
259// ----------------------------------------------------------------------------
260// Copyright 2020 Bloomberg Finance L.P.
261//
262// Licensed under the Apache License, Version 2.0 (the "License");
263// you may not use this file except in compliance with the License.
264// You may obtain a copy of the License at
265//
266// http://www.apache.org/licenses/LICENSE-2.0
267//
268// Unless required by applicable law or agreed to in writing, software
269// distributed under the License is distributed on an "AS IS" BASIS,
270// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
271// See the License for the specific language governing permissions and
272// limitations under the License.
273// ----------------------------- END-OF-FILE ----------------------------------
274
275/** @} */
276/** @} */
277/** @} */
Definition baljsn_datumdecoderoptions.h:126
DatumDecoderOptions(const DatumDecoderOptions &original)
int maxNestedDepth() const
Return the "maxNestedDepth" attribute of this object.
Definition baljsn_datumdecoderoptions.h:226
void setMaxNestedDepth(int value)
Definition baljsn_datumdecoderoptions.h:217
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:135
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:1804
#define BSLS_IDENT(str)
Definition bsls_ident.h:195
Definition baljsn_datumdecoderoptions.h:113
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)