Outline
Purpose
Provide a value-semantic type for location in a JSON document.
Classes
- See also
- bdljsn_jsonutil, bdljsn_json
Description
This component provides a single, unconstrained (value-semantic) attribute class, bdljsn::Location
, that is used to describe a location in a (JSON) document. Location is expressed by the offset
(attrbute) in bytes from the start of the document. See {jsonutil
} for utilities that may provide bdljsn::Location
values when reporting error states.
Attributes
Name Type Default
------------------ ------------- -------
offset bsl::uint64_t 0
offset
: the offset into the JSON document
Usage
This section illustrates intended use of this component.
Example 1: Basic Syntax
This example exercises each of the methods of the bdljsn::Location
class.
First, create a bdljsn::Location
object (having the default value):
assert(0 == locationA.
offset());
Definition bdljsn_location.h:168
bsl::uint64_t offset() const
Return the offset attribute of this object.
Definition bdljsn_location.h:334
Then, set locationA
to some other offset:
assert(1 == locationA.
offset());
Location & setOffset(bsl::uint64_t value)
Set the "offset" attribute of this object to the specified value.
Definition bdljsn_location.h:318
Next, use the value constructor to create a second location having the same offset as the first:
assert(1 == locationB.offset());
assert(locationA == locationB);
Then, set the second location to the maximum offset:
const bsl::uint64_t maxOffset = bsl::numeric_limits<bsl::uint64_t>::max();
locationB.setOffset(maxOffset);
assert(maxOffset == locationB.offset());
Next, create another Location
that is a copy of the one at ‘maxOffset’:
assert(locationB == locationC);
Then, set the first location back to the default state:
assert(0 == locationA.
offset());
Location & reset()
Definition bdljsn_location.h:311
Next, print the value of each:
bsl::cout << locationA << "\n"
<< locationB << bsl::endl;
bsl::cout << "\n";
locationC.
print(bsl::cout, 2, 3);
bsl::ostream & print(bsl::ostream &stream, int level=0, int spacesPerLevel=4) const
and observe:
0
18446744073709551615
[
offset = 18446744073709551615
]
Finally, set each location equal to the first:
locationC = locationB = locationA;
assert(0 == locationA.
offset());
assert(0 == locationB.offset());
assert(0 == locationC.offset());