Sourcemeta Core 0.0.0
Loading...
Searching...
No Matches
jsonl_iterator.h
1#ifndef SOURCEMETA_CORE_JSONL_ITERATOR_H_
2#define SOURCEMETA_CORE_JSONL_ITERATOR_H_
3
4#ifndef SOURCEMETA_CORE_JSONL_EXPORT
5#include <sourcemeta/core/jsonl_export.h>
6#endif
7
8#include <sourcemeta/core/json_value.h>
9
10#include <cstddef> // std::ptrdiff_t
11#include <cstdint> // std::uint64_t
12#include <istream> // std::basic_istream
13#include <iterator> // std::forward_iterator_tag
14#include <memory> // std::unique_ptr
15
16namespace sourcemeta::core {
17
23class SOURCEMETA_CORE_JSONL_EXPORT ConstJSONLIterator {
24public:
26 ConstJSONLIterator(std::basic_istream<JSON::Char, JSON::CharTraits> *stream);
28 using iterator_category = std::forward_iterator_tag;
29 using difference_type = std::ptrdiff_t;
30 using value_type = JSON;
31 using pointer = const value_type *;
32 using reference = const value_type &;
33
34 auto operator*() const -> reference;
35 auto operator->() const -> pointer;
36 auto operator++() -> ConstJSONLIterator &;
37
38 SOURCEMETA_CORE_JSONL_EXPORT friend auto
39 operator==(const ConstJSONLIterator &left, const ConstJSONLIterator &right)
40 -> bool;
41
42private:
43 std::uint64_t line{0};
44 std::uint64_t column{0};
45 auto parse_next() -> JSON;
46 std::basic_istream<JSON::Char, JSON::CharTraits> *data{};
47
48// Exporting symbols that depends on the standard C++ library is considered
49// safe.
50// https://learn.microsoft.com/en-us/cpp/error-messages/compiler-warnings/compiler-warning-level-2-c4275?view=msvc-170&redirectedfrom=MSDN
51#if defined(_MSC_VER)
52#pragma warning(disable : 4251)
53#endif
54 // Use PIMPL idiom to hide internal details, mainly
55 // templated members, which are tricky to DLL-export.
56 struct Internal;
57 std::unique_ptr<Internal> internal{};
58#if defined(_MSC_VER)
59#pragma warning(default : 4251)
60#endif
61};
62
63} // namespace sourcemeta::core
64
65#endif
Definition json_value.h:39
ConstJSONLIterator(std::basic_istream< JSON::Char, JSON::CharTraits > *stream)
Construct an iterator over the JSON documents in a stream.