AnCH Framework 0.2
Another C++ Hack: C++23 utility libraries
Loading...
Searching...
No Matches
readerContext.hpp
1/*
2 ANCH Framework: ANother C++ Hack is a C++ framework based on C++23 standard
3 Copyright (C) 2020 Vincent Lachenal
4
5 This file is part of ANCH Framework.
6
7 ANCH Framework is free software: you can redistribute it and/or modify
8 it under the terms of the GNU Lesser General Public License as published by
9 the Free Software Foundation, either version 3 of the License, or
10 (at your option) any later version.
11
12 ANCH Framework is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU Lesser General Public License for more details.
16
17 You should have received a copy of the GNU Lesser General Public License
18 along with ANCH Framework. If not, see <https://www.gnu.org/licenses/>.
19*/
20#pragma once
21
22#include "anch-json-export.hpp"
23
24#include <istream>
25#include <string>
26#include <optional>
27#include <utility>
28#include <functional>
29#include <stdint.h>
30
31#include "json/mappingOptions.hpp"
32
33namespace anch::json {
34
44 class ANCH_JSON_EXPORT ReaderContext {
45
46 // Attributes +
47 public:
49 std::istream& input;
50
53
55 std::string pbuf;
56
58 uint32_t offset;
59
61 std::size_t bufferSize;
62
64 char* buffer;
65
67 std::size_t read;
68
70 std::size_t depth;
71
72 // Attributes -
73
74 // Constructors +
75 public:
79 ReaderContext() = delete;
80
86 ReaderContext(const ReaderContext& context) = delete;
87
93 ReaderContext(ReaderContext&& context) = delete;
94
104 // Constructors -
105
106 // Destructor +
107 public:
113 virtual ~ReaderContext() noexcept;
114 // Destructor -
115
116 // Methods +
117 public:
125 char discard();
126
133
144 bool next(char& current);
145
149 void back();
150
158
162 void leaveLevel() noexcept;
163
164 protected:
172 virtual std::streamsize refillBuffer();
173
179 void checkPayloadSize() const;
180
181 private:
187 [[noreturn]] void throwDepthError();
188 // Methods -
189
190 };
191
201 class ANCH_JSON_EXPORT DepthGuard {
202
203 // Attributes +
204 private:
207 // Attributes -
208
209 // Constructors +
210 public:
219
225 DepthGuard(const DepthGuard& guard) = delete;
226 // Constructors -
227
228 // Destructor +
229 public:
233 ~DepthGuard() noexcept;
234 // Destructor -
235
236 };
237
238}
239
240#include "json/impl/readerContext.hpp"
DepthGuard(anch::json::ReaderContext &context)
DepthGuard(const DepthGuard &guard)=delete
JSON reader context.
Definition readerContext.hpp:44
std::size_t read
Definition readerContext.hpp:67
virtual std::streamsize refillBuffer()
anch::json::MappingOptions options
Definition readerContext.hpp:52
char * buffer
Definition readerContext.hpp:64
ReaderContext(const ReaderContext &context)=delete
std::string pbuf
Definition readerContext.hpp:55
std::size_t bufferSize
Definition readerContext.hpp:61
uint32_t offset
Definition readerContext.hpp:58
void leaveLevel() noexcept
void checkPayloadSize() const
ReaderContext(ReaderContext &&context)=delete
ReaderContext(std::istream &is, const anch::json::MappingOptions &options)
bool next(char &current)
std::istream & input
Definition readerContext.hpp:49
virtual ~ReaderContext() noexcept
std::size_t depth
Definition readerContext.hpp:70
JSON namespace.
Definition constants.hpp:27
JSON mapping options.
Definition mappingOptions.hpp:38