Quick Links:

bal | bbl | bdl | bsl

Namespaces

Component bdljsn_location
[Package bdljsn]

Provide a value-semantic type for location in a JSON document. More...

Namespaces

namespace  bdljsn

Detailed Description

Outline
Purpose:
Provide a value-semantic type for location in a JSON document.
Classes:
bdljsn::Location position in a JSON document
See also:
Component bdljsn_jsonutil, Component 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):
  bdljsn::Location locationA;
  assert(0 == locationA.offset());
Then, set locationA to some other offset:
  locationA.setOffset(1);
  assert(1 == locationA.offset());
Next, use the value constructor to create a second location having the same offset as the first:
      bdljsn::Location locationB(1);
      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:
  bdljsn::Location locationC(locationB);
  assert(locationB == locationC);
Then, set the first location back to the default state:
  locationA.reset();
  assert(0                  == locationA.offset());
  assert(bdljsn::Location() == locationA);
Next, print the value of each:
  bsl::cout << locationA << "\n"
            << locationB << bsl::endl;

  bsl::cout << "\n";

  locationC.print(bsl::cout, 2, 3);
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());