File: staj_cursor.md

package info (click to toggle)
jsoncons 1.3.2-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 17,584 kB
  • sloc: cpp: 136,382; sh: 33; makefile: 5
file content (63 lines) | stat: -rw-r--r-- 2,732 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
### jsoncons::staj_cursor

```cpp
#include <jsoncons/staj_cursor.hpp>

typedef basic_staj_cursor<char> staj_cursor
```

The `staj_cursor` interface supports forward, read-only, access to JSON and JSON-like data formats.

The `staj_cursor` is designed to iterate over stream events until `done()` returns `true`.
The `next()` function causes the reader to advance to the next stream event. The `current()` function
returns the current stream event. The data can be accessed using the [staj_event](basic_staj_event.md) 
interface. When `next()` is called, copies of data previously accessed may be invalidated.

#### Destructor

    virtual ~basic_staj_cursor() noexcept = default;

#### Member functions

    virtual bool done() const = 0;
Check if there are no more events.

    virtual const staj_event& current() const = 0;
Returns the current [staj_event](basic_staj_event.md).

    virtual void read_to(json_visitor& visitor) = 0;
Sends the parse events from the current event to the
matching completion event to the supplied [visitor](basic_json_visitor.md)
E.g., if the current event is `begin_object`, sends the `begin_object`
event and all inbetween events until the matching `end_object` event.
If a parsing error is encountered, throws a [ser_error](ser_error.md).

    virtual void read_to(json_visitor& visitor,
                        std::error_code& ec) = 0;
Sends the parse events from the current event to the
matching completion event to the supplied [visitor](basic_json_visitor.md)
E.g., if the current event is `begin_object`, sends the `begin_object`
event and all inbetween events until the matching `end_object` event.
If a parsing error is encountered, sets `ec`.

    virtual void next() = 0;
Get the next event. If a parsing error is encountered, throws a [ser_error](ser_error.md).

    virtual void next(std::error_code& ec) = 0;
Get the next event. If a parsing error is encountered, sets `ec`.

    virtual const ser_context& context() const = 0;
Returns the current [context](ser_context.md)

#### Non-member functions

    template <typename T,typename CharT,typename Json=std::conditional<is_basic_json<T>::value,T,basic_json<CharT>>::type>
    staj_array_view<Json,T> staj_array(basic_staj_cursor<CharT>& cursor);
Create a view of the parse events as an array of items of type `T`. 
The current event type must be `staj_event_type::begin_array`.

    template <typename Key,typename T,typename CharT,typename Json=std::conditional<is_basic_json<T>::value,T,basic_json<CharT>>::type>
    staj_object_view<Key, T, Json> staj_object(basic_staj_cursor<CharT>& cursor);
Create a view of the parse events as an object of key-value pairs.
The current event type must be `staj_event_type::begin_object`.