BDE 4.39.x Production Release
Loading...
Searching...
No Matches
baljsn_jsontokenizer.h
Go to the documentation of this file.
1/// @file baljsn_jsontokenizer.h
2///
3/// The content of this file has been pre-processed for Doxygen.
4///
5
6
7// baljsn_jsontokenizer.h -*-C++-*-
8#ifndef INCLUDED_BALJSN_JSONTOKENIZER
9#define INCLUDED_BALJSN_JSONTOKENIZER
10
11#include <bsls_ident.h>
12BSLS_IDENT("$Id: $")
13
14/// @defgroup baljsn_jsontokenizer baljsn_jsontokenizer
15/// @brief Provide a tokenizer for viewing parts of a `bdljsn::Json` object.
16/// @addtogroup bal
17/// @{
18/// @addtogroup baljsn
19/// @{
20/// @addtogroup baljsn_jsontokenizer
21/// @{
22///
23/// <h1> Outline </h1>
24/// * <a href="#baljsn_jsontokenizer-purpose"> Purpose</a>
25/// * <a href="#baljsn_jsontokenizer-classes"> Classes </a>
26/// * <a href="#baljsn_jsontokenizer-description"> Description </a>
27/// * <a href="#baljsn_jsontokenizer-tokens"> Tokens </a>
28/// * <a href="#baljsn_jsontokenizer-json-object-members"> JSON Object Members </a>
29/// * <a href="#baljsn_jsontokenizer-json-array-elements"> JSON Array Elements </a>
30/// * <a href="#baljsn_jsontokenizer-usage"> Usage </a>
31/// * <a href="#baljsn_jsontokenizer-example-1-basic-usage"> Example 1: Basic Usage </a>
32///
33/// # Purpose {#baljsn_jsontokenizer-purpose}
34/// Provide a tokenizer for viewing parts of a `bdljsn::Json` object.
35///
36/// # Classes {#baljsn_jsontokenizer-classes}
37///
38/// - baljsn::JsonTokenizer: tokenizer for viewing parts of a `bdljsn::Json`
39///
40/// @see baljsn_decoder, baljsn_tokenizer, baljsn_converter
41///
42/// # Description {#baljsn_jsontokenizer-description}
43/// This component provides a class, `baljsn::JsonTokenizer`, that
44/// iterates through the structure of a `bdljsn::Json` object and provides
45/// Json type and (for some types) value data for each subordinate
46/// `bdljsn::Json` object. The top-level `bdljsn::Json` object must be of
47/// either `bdljsn::JsonArray` or `bdldjn::JsonObject` type. Both of those
48/// types can contain subordinate objects that are themselves either arrays or
49/// objects or any of the four scalar types. The structure is traversed in
50/// depth-first order.
51///
52/// The set of tokens returned by this tokenizer is isomorphic with the tokens
53/// returned by @ref baljsn_tokenizer for use by @ref baljsn_decoder . The only
54/// significant difference is that the latter tokenizer always returns values as
55/// `bsl::string_view`s whereas this tokenizer returns `bsl::string_view` for
56/// element names (the name portion of a `bdljsn::JsonObject` member) but the
57/// value of an element value (the value portion of a `bdljsn::JsonObject`
58/// member or an element of a `bdljsn::JsonArray) is returned as a
59/// `const bdljsn::Json *`.
60///
61/// ## Tokens {#baljsn_jsontokenizer-tokens}
62///
63///
64/// The basic usage pattern for this tokenizer is to iteratively call
65/// the `advanceToNextToken` method. If the return value is 0 (success)
66/// the enumerated token value can be obtained by calling the `tokenType`
67/// method. `advanceToNextToken` fails when the tokenizer has been advanced
68/// past the last token.
69///
70/// The following table lists describes the set of enumerated values that
71/// can be returned by this tokenizer.
72/// @code
73/// +-----------------+--------------------+-----------------------------+
74/// |Enumerator |Description | Value |
75/// +-----------------+--------------------+-----------------------------+
76/// |e_BEGIN |starting token | none |
77/// |e_ELEMENT_NAME |element name | value(bsl::string_view *) |
78/// |e_START_OBJECT |start of an object | none |
79/// |e_END_OBJECT |end of an object | none |
80/// |e_START_ARRAY |start of an array | none |
81/// |e_END_ARRAY |end of an array | none |
82/// |e_ELEMENT_VALUE |scalar element value| value(const bdljsn::Json **)|
83/// |e_ERROR |error token | none |
84/// +-----------------+--------------------+-----------------------------+
85/// @endcode
86/// Note that `e_BEGIN` is *never* returned by `tokenType`. That token type is
87/// the "prior" token that is discarded in the first call to
88/// `advanceToNextToken` after construction or `reset`.
89///
90/// Notice that two of the enumerated values -- `e_ELEMENT_NAME` and
91/// `e_ELEMENT_VALUE` -- have additional information that can be obtained via
92/// the appropriate `value` overload.
93///
94/// ### JSON Object Members {#baljsn_jsontokenizer-json-object-members}
95///
96///
97/// Recall that JSON Objects consist of sequences of name/value pairs called
98/// "members". `e_ELEMENT_NAME` is returned when the tokenizer is positioned to
99/// the name portion of a member and `e_ELEMENT_VALUE` is returned when
100/// the tokenizer is advanced to the associated scalar value. The appropriate
101/// `value` overload is used to get the actual member name (a
102/// `bsl::string_view`) and member value (a pointer to a `bdljsn::Json` object).
103///
104/// Also recall that the value portion of a member need not be scalar. Those
105/// can also consist of a subordinate JSON object or JSON array, in whice case,
106/// `e_START_OBJECT` or `e_START_ARRAY`, repsectively, are returned.
107///
108/// ### JSON Array Elements {#baljsn_jsontokenizer-json-array-elements}
109///
110///
111/// `e_ELEMENT_VALUE` is also returned for each scalar element when
112/// the tokenizer is advancing through an array and `value` is invoked to
113/// get the value of that element. If the element is non-scalar -- i.e.,
114/// a subordinate object or array -- the appropriate `e_START_*` token is
115/// returned.
116///
117/// ## Usage {#baljsn_jsontokenizer-usage}
118///
119///
120/// This section illustrates intended use of this component.
121///
122/// ## Example 1: Basic Usage {#baljsn_jsontokenizer-example-1-basic-usage}
123///
124///
125/// The `baljsn::JsonTokenizer` allows the user to iteratively examine each of
126/// the piece-parts of a `bdljsn::Json` object having arbitrary complexity
127/// --- containing subordinate `JsonArray`s/`JsonObject`s --- as well as the
128/// scalar `Json` types. Suppose one must visualize a `bdljsn::Json` object
129/// having modest complexity:
130/// @code
131/// { "name" : "Bob",
132/// "homeAddress" : { "street" : "Lexington Ave",
133/// "city" : "New York City",
134/// "state" : "New York"
135/// },
136/// "age" : 21
137/// }
138/// @endcode
139/// First, create `JsonDoc`, an ASCII string an representation of the above JSON
140/// document (having required escape sequences and quoting) -- elided.
141///
142/// Then, create `json`, the programmatic representation of the JSON document.
143/// @code
144/// bdljsn::Json json;
145/// int rc = bdljsn::JsonUtil::read(&json, JsonDoc);
146/// assert(0 == rc);
147/// @endcode
148/// Next, define two macros and an array of indentation strings to simplify the
149/// formatting code.
150/// @code
151/// const char *const indents[] = { "" // Four spaces per level.
152/// , " "
153/// , " "
154/// , " "
155/// };
156///
157/// #define PRINT(L, X) bsl::cout << indents[L] << (X) << bsl::endl;
158///
159/// #define PRINTV(L, X, V) bsl::cout \$
160/// << indents[L] \$
161/// << (X) << ": " \$
162/// << (V) << bsl::endl;
163///
164/// int level = 0; // indentation level
165/// @endcode
166/// Then, create `tokenizer`, a `baljsn::JsonTokenizer`, that will generate
167/// a sequence of tokens (and sometimes values as well) for the previously
168/// initialized `json` object.
169/// @code
170/// baljsn::JsonTokenizer tokenizer(&json);
171///
172/// while (0 == tokenizer.advanceToNextToken()) {
173/// @endcode
174/// Now, for each token in the sequence, dispatch to the appropriate action.
175/// In each case, we output the value of the token at the current level of
176/// indentation.
177///
178/// For tokens that indicate the start of an `JsonArray` or `JsonObject`, we
179/// increase the level of indentation. That level is decreased when the end of
180/// the `JsonArray` or `JsonObject` is reported.
181///
182/// We expect two tokens to be generated for each member of a `JsonObject`: the
183/// element name and an associated value. In such cases we use the `value`
184/// method of extract the name (provided via `bsl::string_view`) and the value
185/// (itself a `bdljsn::Json` object).
186///
187/// Be aware that a `e_ELEMENT_VALUE` is also returned for each scalar element
188/// of a `JsonArray` -- not featured in this example.
189/// @code
190/// baljsn::JsonTokenizer::TokenType tokenType = tokenizer.tokenType();
191///
192/// switch(tokenType) {
193/// case baljsn::JsonTokenizer::e_START_ARRAY: {
194/// PRINT(level, tokenType);
195/// ++level;
196/// } break;
197/// case baljsn::JsonTokenizer::e_END_ARRAY: {
198/// --level;
199/// PRINT(level, tokenType);
200/// } break;
201/// case baljsn::JsonTokenizer::e_START_OBJECT: {
202/// PRINT(level, tokenType);
203/// ++level;
204/// } break;
205/// case baljsn::JsonTokenizer::e_END_OBJECT: {
206/// --level;
207/// PRINT(level, tokenType);
208/// } break;
209/// case baljsn::JsonTokenizer::e_ELEMENT_NAME: {
210/// bsl::string_view sv;
211/// int rc = tokenizer.value(&sv);
212/// assert(0 == rc);
213///
214/// PRINTV(level, tokenType, sv);
215/// } break;
216/// case baljsn::JsonTokenizer::e_ELEMENT_VALUE: {
217/// const bdljsn::Json *jp;
218/// int rc = tokenizer.value(&jp);
219/// assert(0 == rc);
220/// assert( jp);
221/// assert(!jp->isArray());
222/// assert(!jp->isObject());
223///
224/// PRINTV(level, tokenType, *jp);
225/// } break;
226/// case baljsn::JsonTokenizer::e_ERROR: {
227/// PRINT(level, tokenType);
228/// } break;
229/// default: {
230/// assert(false && !"reachable");
231/// }
232/// }
233/// }
234/// @endcode
235/// Notice, that the `e_ELEMENT_VALUE` is always associated with a scalar
236/// `bdljsn::Json` object. If the value portion of a member is itself an
237/// `JsonArray` (or `JsonObject`) then expect `e_START_ARRAY` (or
238/// `e_START_OBJECT`) at that point.
239///
240/// Finally, we can inspect the output for this `bdljsn::Json` object:
241/// @code
242/// START_OBJECT
243/// ELEMENT_NAME: homeAddress
244/// START_OBJECT
245/// ELEMENT_NAME: state
246/// ELEMENT_VALUE: "New York"
247/// ELEMENT_NAME: city
248/// ELEMENT_VALUE: "New York City"
249/// ELEMENT_NAME: street
250/// ELEMENT_VALUE: "Lexington Ave"
251/// END_OBJECT
252/// ELEMENT_NAME: age
253/// ELEMENT_VALUE: 21
254/// ELEMENT_NAME: name
255/// ELEMENT_VALUE: "Bob"
256/// END_OBJECT
257/// @endcode
258/// @}
259/** @} */
260/** @} */
261
262/** @addtogroup bal
263 * @{
264 */
265/** @addtogroup baljsn
266 * @{
267 */
268/** @addtogroup baljsn_jsontokenizer
269 * @{
270 */
271
272#include <bdlscm_version.h>
273
274#include <baljsn_tokenizer.h> // for interface type used by `Decoder`.
275
276//#include <bdlma_bufferedsequentialallocator.h>
277
278#include <bdljsn_json.h> // `bdljsn::Json`,
279 // `bdljsn::JsonObject`, and
280 // `bdljsn::JsonArray`
281#include <bdljsn_jsonnull.h>
282#include <bdljsn_jsonnumber.h>
283
284#include <bdlb_variant.h>
285
286#include <bslma_aatypeutil.h>
287#include <bslma_allocatorutil.h>
288#include <bslma_bslallocator.h>
289
290#include <bsla_unreachable.h>
291
292#include <bsls_assert.h>
293#include <bsls_types.h>
294
295#include <bsl_deque.h>
296#include <bsl_iomanip.h>
297#include <bsl_ios.h>
298#include <bsl_ostream.h>
299#include <bsl_stack.h>
300#include <bsl_streambuf.h>
301#include <bsl_string.h>
302#include <bsl_string_view.h>
303
304
305namespace baljsn {
306
307class JsonTokenizer;
308
309 // =====================
310 // JsonTokenizer_Visitor
311 // =====================
312
313/// This class provides a mechanism for extracting token information from a
314/// `bdljsn::Json` object, transferring that information to a parent
315/// `baljsn::JsonTokenizer` object (which considers this visitor a `friend`),
316/// and, if appropriate, arranging for the visiting of a subordinate
317/// `bdljsn::Json` object.
318///
319/// See @ref baljsn_jsontokenizer
321
322 // DATA
323 JsonTokenizer *d_tokenizer_p; // parent object (held, not owned)
324
325 // PRIVATE TYPES
326 typedef JsonTokenizer JT;
327
328 public:
329 // CREATORS
330
331 /// Create a `JsonTokenizer_Visitor` object that, when used via the `visit`
332 /// method of a `bdljsn::Json` object, transfers token information to the
333 /// specified `tokenizer`.
334 explicit JsonTokenizer_Visitor(JsonTokenizer *tokenizer);
335
336 /// Destroy this `JsonTokenizer_Visitor` object.
338
339 // ACCESSORS
340 void operator()(const bdljsn::JsonObject& object ) const;
341 void operator()(const bdljsn::JsonArray& array ) const;
342
343 // No-ops: 'bsl::string', `JsonNumber`, `bool`, and `JsonNull`
344 template <class TYPE>
345 void operator()(const TYPE& parameter) const;
346};
347
348 // ===================
349 // class JsonTokenizer
350 // ===================
351
352/// This class implements a mechanism that makes the organization and values of
353/// a non-scalar `bdljsn::Json` object available as a series of tokens. Some
354/// tokens have associated values. See @ref baljsn_jsontokenizer-tokens .
355///
356/// See @ref baljsn_jsontokenizer
358
359 public:
360
361 // TYPES
362
364 e_BEGIN = 1 // starting token
365 , e_ELEMENT_NAME // element name
366 , e_START_OBJECT // start of an object
367 , e_END_OBJECT // end of an object
368 , e_START_ARRAY // start of an array
369 , e_END_ARRAY // end of an array
370 , e_ELEMENT_VALUE // element value of a simple (scalar) type
371 , e_ERROR // error token
372 };
373
375
376 private:
377 // PRIVATE TYPES
379 typedef const bdljsn::Json *ElementValue;
380
381 typedef bdlb::Variant <ElementName, ElementValue> TokenValue;
382
383 struct Token {
384 TokenType d_tokenType; // Token type.
385 TokenValue d_tokenValue; // Array element, member name, member value,
386 // or unset -- depending on `d_tokenType`.
387 };
388
389 enum State {
390 e_JSON_START = 0 // at the start of an `JsonArray` or `JsonObject`
391 , e_JSON_BODY // at an interior array element or object member
392 , e_JSON_END // at the end of the `JsonArray` or `JsonObject`
393 };
394
395 typedef bdljsn::JsonArray ::ConstIterator ElementItr;
396 typedef bdljsn::JsonObject::ConstIterator MemberItr;
397
398 typedef bdlb::Variant <ElementItr, MemberItr> Position;
399
400 struct Context {
401 State d_state; // beginging/middle/end of non-scalar
402 const bdljsn::Json *d_json_p; // the non-scalar `Json` being examined
403 Position d_position; // position within the non-scalar
404 };
405
406 typedef bsl::deque<Token> TokenList;
407 typedef bsl::stack<Context> ContextStack;
408
409 TokenList d_tokenList; // Token(s) staged for `tokenType()`.
410 // Note: List size is 2 after
411 // processing an `JsonObject` member
412 // an 1 otherwise.
413
414 ContextStack d_contextStack; // State of examination of the
415 // specified `Json` object.
416
417 JsonTokenizer_Visitor d_visitor; // Visitor object for extracting
418 // token information.
419
420 // DATA
421 static const Token s_BEGIN; // Preformed token for `tokenType()`.
422 static const Token s_START_OBJECT; // " "
423 static const Token s_END_OBJECT; // " "
424 static const Token s_START_ARRAY; // " "
425 static const Token s_END_ARRAY; // " "
426 static const Token s_ERROR; // " "
427
428 // PRIVATE MANIPULATORS
429 int getNextToken();
430
431 // PRIVATE ACCESSORS
432 void printTokens() const;
433
434 // FRIENDS
436
437 private:
438 // NOT IMPLEMENTED
439 JsonTokenizer(const JsonTokenizer&); // = delete;
440 JsonTokenizer& operator=(const JsonTokenizer&); // = delete
441
442 public:
443
444 // CLASS METHODS
445
446 /// Write the string representation of the specified enumeration `value`
447 /// to the specified output `stream`, and return a reference to
448 /// `stream`. Optionally specify an initial indentation `level`, whose
449 /// absolute value is incremented recursively for nested objects. If
450 /// `level` is specified, optionally specify `spacesPerLevel`, whose
451 /// absolute value indicates the number of spaces per indentation level
452 /// for this and all of its nested objects. If `level` is negative,
453 /// suppress indentation of the first line. If `spacesPerLevel` is
454 /// negative, format the entire output on one line, suppressing all but
455 /// the initial indentation (as governed by `level`). See `toAscii` for
456 /// what constitutes the string representation of a
457 /// `JsonTokenizer::TokenType` value.
458 static bsl::ostream& print(bsl::ostream& stream,
460 int level = 0,
461 int spacesPerLevel = 4);
462
463 /// Return the non-modifiable string representation corresponding to the
464 /// specified enumeration `value`, if it exists, and a unique (error)
465 /// string otherwise. The string representation of `value` matches its
466 /// corresponding enumerator name with the "e_" prefix elided. For
467 /// example:
468 /// @code
469 /// bsl::cout << DstPolicy::toAscii(JsonTokenizer::e_ELEMENT_VALUE);
470 /// @endcode
471 /// will print the following on standard output:
472 /// @code
473 /// ELEMENT_VALUE
474 /// @endcode
475 ///
476 /// \note Note that specifying a `value` that does not match any of the
477 /// enumerators will result in a string representation that is distinct
478 /// from any of those corresponding to the enumerators, but is otherwise
479 /// unspecified.
480 static const char *toAscii(TokenType value);
481
482 // CREATORS
483
484 /// Create a `JsonTokenizer` object. Optionally specify an `allocator`
485 /// (e.g., the address of a `bslma::Allocator` object) to supply
486 /// memory; otherwise, the default allocator is used. No tokens can
487 /// be generated until a source `bdljsn::Json` object is specified
488 /// via the `reset` method.
490 explicit JsonTokenizer(const allocator_type& allocator);
491
492 /// Create a `JsonTokenizer` object that can supply a series of tokens
493 /// describing the specified `json` object. Optionally specify an
494 /// `allocator` (e.g., the address of a `bslma::Allocator` object) to
495 /// supply memory; otherwise, the default allocator is used.
496 ///
497 /// \pre The behavior is undefined unless `json->isArray()` or `json->isObject()`.
498 ///
499 /// \note Note that `json` can also be specified via the `reset` method.
500 JsonTokenizer(const bdljsn::Json *json,
501 const allocator_type& allocator = allocator_type());
502
503 /// Destroy this object.
505
506 // MANIPULATORS
507
508 /// Move to the next token in the source object. Return 0 on success and a
509 /// non-zero value otherwise. The return value is non-zero when there
510 /// are no more tokens in the source object.
511 ///
512 /// \pre The behavior is undefined unless a source object was specified on construction and/or a call to
513 /// `reset`.
515
516 /// Reset this tokenizer to use the specified `json` as a source object
517 /// for tokens. All state associated with a previously specified source object (if any) is discarded.
518 ///
519 /// \pre The behavior is undefined unless
520 /// `json->isArray()` or `json->isObject()`.
521 int reset(const bdljsn::Json *json);
522
523 // ACCESSORS
524
525 /// Return the type of the current token.
526 TokenType tokenType() const;
527
528 /// Load into the specified `data` the value of the current token. Return
529 /// 0 on success and a non-zero value otherwise.
530 ///
531 /// \pre The behavior is undefined unless `e_ELEMENT_NAME == tokenType()`.
532 int value(bsl::string_view *data) const;
533
534 /// Load into the specified `data` the value of the current token. Return
535 /// 0 on success and a non-zero value otherwise.
536 ///
537 /// \pre The behavior is undefined unless `e_ELEMENT_VALUE == tokenType()`.
538 int value(const bdljsn::Json **data) const;
539
540 // Aspects
541
542 /// Return the allocator used by this object to supply memory.
543 ///
544 /// \note Note that if no allocator was supplied at construction the default
545 /// allocator in effect at construction is used.
547};
548
549// FREE OPERATORS
550
551/// Write the string representation of the specified enumeration `value` to
552/// the specified output `stream` in a single-line format, and return a
553/// reference to `stream`. See `toAscii` for what constitutes the string
554/// representation of a `baljsn::JsonTokenizer::TokenType` value.
555///
556/// \note Note that this method has the same behavior as
557/// @code
558/// baljsn::JsonTokenizer::print(stream, value, 0, -1);
559/// @endcode
560bsl::ostream& operator<<(bsl::ostream& stream, JsonTokenizer::TokenType value);
561
562} // close package namespace
563
564// ============================================================================
565// INLINE DEFINITIONS
566// ============================================================================
567
568namespace baljsn {
569 // ---------------------
570 // JsonTokenizer_Visitor
571 // ---------------------
572
573// CREATORS
574inline
576: d_tokenizer_p(tokenizer)
577{
578 BSLS_ASSERT(tokenizer);
579}
580
581inline
585
586// ACCESSORS
587template <class TYPE>
588inline
589void JsonTokenizer_Visitor::operator()(const TYPE& parameter) const
590{
591 BSLS_ASSERT_OPT_UNREACHABLE("Unexpected JSON type in visitor");
592 (void) parameter;
593}
594
595 // -------------------
596 // class JsonTokenizer
597 // -------------------
598
599// CREATORS
600inline
602: d_tokenList()
603, d_contextStack()
604, d_visitor(this)
605{
606}
607
608inline
610: d_tokenList (bslma::AllocatorUtil::adapt(allocator))
611, d_contextStack(bslma::AllocatorUtil::adapt(allocator))
612, d_visitor(this)
613{
614}
615
616inline
618 const allocator_type& allocator)
619: d_tokenList (bslma::AllocatorUtil::adapt(allocator))
620, d_contextStack(bslma::AllocatorUtil::adapt(allocator))
621, d_visitor(this)
622{
623 BSLS_ASSERT(json);
624 BSLS_ASSERT(json->isArray() || json->isObject());
625
626 Context context;
627 context.d_json_p = json;
628 context.d_state = json->isArray() ? e_JSON_START :
629 json->isObject() ? e_JSON_START :
630 e_JSON_BODY ;
631 d_contextStack.push(context);
632 d_tokenList.push_back(JsonTokenizer::s_BEGIN);
633}
634
635// MANIPULATORS
636
637inline
638int JsonTokenizer::getNextToken()
639{
640 if (d_contextStack.empty()) {
641 return -1;
642 }
643 Context& context = d_contextStack.top();
644
645 context.d_json_p->visit<void>(d_visitor);
646
647 return 0;
648}
649
650// ACCESSORS
651inline
653{
654 BSLS_ASSERT_SAFE(!d_tokenList.empty());
655
656 return d_tokenList.front().d_tokenType;
657}
658
659inline
661{
662 BSLS_ASSERT(data);
663 BSLS_ASSERT(!d_tokenList.empty());
664 BSLS_ASSERT(e_ELEMENT_NAME == d_tokenList.front().d_tokenType);
665
666 *data = d_tokenList.front().d_tokenValue.the<ElementName>();
667 return 0;
668}
669
670inline
671int JsonTokenizer::value(const bdljsn::Json **data) const
672{
673 BSLS_ASSERT(data);
674 BSLS_ASSERT_SAFE(!d_tokenList.empty());
675 BSLS_ASSERT(e_ELEMENT_VALUE == d_tokenList.front().d_tokenType);
676
677 *data = d_tokenList.front().d_tokenValue.the<ElementValue>();;
678 return 0;
679}
680
681 // Aspects
682
683inline
685{
686 return bslma::AATypeUtil::getAllocatorFromSubobject<allocator_type>(
687 d_tokenList);
688}
689
690} // close package namespace
691
692// FREE OPERATORS
693inline
694bsl::ostream& baljsn::operator<<(bsl::ostream& stream,
695 JsonTokenizer::TokenType value)
696{
697 return JsonTokenizer::print(stream, value, 0, -1);
698}
699
700
701
702#endif // INCLUDED_BDLJSN_JSONTOKENIZER
703
704// ----------------------------------------------------------------------------
705// Copyright 2025 Bloomberg Finance L.P.
706//
707// Licensed under the Apache License, Version 2.0 (the "License");
708// you may not use this file except in compliance with the License.
709// You may obtain a copy of the License at
710//
711// http://www.apache.org/licenses/LICENSE-2.0
712//
713// Unless required by applicable law or agreed to in writing, software
714// distributed under the License is distributed on an "AS IS" BASIS,
715// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
716// See the License for the specific language governing permissions and
717// limitations under the License.
718// ----------------------------- END-OF-FILE ----------------------------------
719
720/** @} */
721/** @} */
722/** @} */
Definition baljsn_jsontokenizer.h:320
void operator()(const bdljsn::JsonObject &object) const
~JsonTokenizer_Visitor()
Destroy this JsonTokenizer_Visitor object.
Definition baljsn_jsontokenizer.h:582
JsonTokenizer_Visitor(JsonTokenizer *tokenizer)
Definition baljsn_jsontokenizer.h:575
void operator()(const bdljsn::JsonArray &array) const
Definition baljsn_jsontokenizer.h:357
TokenType
Definition baljsn_jsontokenizer.h:363
@ e_END_OBJECT
Definition baljsn_jsontokenizer.h:367
@ e_START_ARRAY
Definition baljsn_jsontokenizer.h:368
@ e_END_ARRAY
Definition baljsn_jsontokenizer.h:369
@ e_ERROR
Definition baljsn_jsontokenizer.h:371
@ e_BEGIN
Definition baljsn_jsontokenizer.h:364
@ e_START_OBJECT
Definition baljsn_jsontokenizer.h:366
@ e_ELEMENT_NAME
Definition baljsn_jsontokenizer.h:365
@ e_ELEMENT_VALUE
Definition baljsn_jsontokenizer.h:370
static const char * toAscii(TokenType value)
~JsonTokenizer()
Destroy this object.
JsonTokenizer()
Definition baljsn_jsontokenizer.h:601
allocator_type get_allocator() const
Definition baljsn_jsontokenizer.h:684
int reset(const bdljsn::Json *json)
bsl::allocator allocator_type
Definition baljsn_jsontokenizer.h:374
friend class JsonTokenizer_Visitor
Definition baljsn_jsontokenizer.h:435
TokenType tokenType() const
Return the type of the current token.
Definition baljsn_jsontokenizer.h:652
int value(bsl::string_view *data) const
Definition baljsn_jsontokenizer.h:660
static bsl::ostream & print(bsl::ostream &stream, TokenType value, int level=0, int spacesPerLevel=4)
Definition bdljsn_json.h:551
Definition bdljsn_json.h:1080
Container::const_iterator ConstIterator
Definition bdljsn_json.h:1092
Definition bdljsn_json.h:1461
bool isObject() const
Definition bdljsn_json.h:5082
bool isArray() const
Definition bdljsn_json.h:5058
reference front()
Definition bslstl_deque.h:2154
bool empty() const BSLS_KEYWORD_NOEXCEPT
Definition bslstl_deque.h:2287
Definition bslma_bslallocator.h:588
Definition bslstl_stringview.h:471
Definition bslstl_deque.h:814
void push_back(const VALUE_TYPE &value)
Definition bslstl_deque.h:3719
Definition bslstl_stack.h:412
bool empty() const
Definition bslstl_stack.h:1084
void push(const value_type &value)
Push the specified value onto the top of this stack.
Definition bslstl_stack.h:1032
void swap(stack &other) BSLS_KEYWORD_NOEXCEPT_SPECIFICATION(bsl reference top()
Definition bslstl_stack.h:655
#define BSLS_ASSERT(X)
Definition bsls_assert.h:1976
#define BSLS_ASSERT_SAFE(X)
Definition bsls_assert.h:1917
#define BSLS_ASSERT_OPT_UNREACHABLE(X)
Definition bsls_assert.h:2065
#define BSLS_IDENT(str)
BSLS_IDENT() - insert string into .comment binary segment (if supported)
Definition bsls_ident.h:238
Definition baljsn_convertfromjsonoptions.h:112
bsl::ostream & operator<<(bsl::ostream &stream, const DatumDecoderOptions &rhs)
Definition baljsn_encoder_testtypes.h:76