AnCH Framework 0.2
Another C++ Hack: C++23 utility libraries
Loading...
Searching...
No Matches
reader.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 <any>
27
28#include "json/readerContext.hpp"
29#include "json/mappingError.hpp"
30#include "events/observable.hpp"
31
32namespace anch::json {
33
41 enum class EventType {
42
44 VNULL = 0,
45
48
51
54
57
60
63
66
69
72
73 };
74
82 class ANCH_JSON_EXPORT JSONItem {
83
84 // Attributes +
85 private:
88
90 std::any _value;
91 // Attributes -
92
93 // Constructors +
94 public:
98 JSONItem() = delete;
99
107 // Constructors -
108
109 // Destructor +
110 public:
114 virtual ~JSONItem() noexcept;
115 // Destructor -
116
117 // Accessors +
118 public:
125
131 const std::any& getValue() const;
132 // Accessors -
133
134 };
135
147 class ANCH_JSON_EXPORT Reader:
149 public anch::events::Observable<std::streamsize>,
151 private anch::json::ReaderContext {
152
153 // Constructors +
154 public:
158 Reader() = delete;
159
165 Reader(const Reader& reader) = delete;
166
172 Reader(Reader&& reader) = delete;
173
182 Reader(std::istream& is, const anch::json::MappingOptions& options);
183 // Constructors -
184
185 // Destructor +
186 public:
192 virtual ~Reader();
193 // Destructor -
194
195 // Methods +
196 public:
201 void parse() noexcept;
202
209
215 anch::events::Observable<std::streamsize>& sizeObs();
216
223
224 protected:
231 virtual std::streamsize refillBuffer();
232
233 private:
237 void parseField();
238
242 void parseObject();
243
247 void parseValue();
248
252 void parseArray();
253 // Methods -
254
255 };
256
257}
258
259#include "json/impl/reader.hpp"
Definition reader.hpp:82
virtual ~JSONItem() noexcept
JSONItem(anch::json::EventType type, anch::json::ReaderContext &context)
const std::any & getValue() const
anch::json::EventType getType() const
Mapping error.
Definition mappingError.hpp:84
JSON reader context.
Definition readerContext.hpp:44
anch::json::MappingOptions options
Definition readerContext.hpp:52
Reader(std::istream &is, const anch::json::MappingOptions &options)
virtual std::streamsize refillBuffer()
anch::events::Observable< anch::json::MappingError > & errorObs()
anch::events::Observable< JSONItem > & itemObs()
anch::events::Observable< std::streamsize > & sizeObs()
Reader(Reader &&reader)=delete
void parse() noexcept
Reader(const Reader &reader)=delete
Events management namespace.
Definition event.hpp:25
JSON namespace.
Definition constants.hpp:27
EventType
Definition reader.hpp:41
@ BEGIN_ARRAY
Definition reader.hpp:68
@ END_ARRAY
Definition reader.hpp:71
@ BEGIN_OBJECT
Definition reader.hpp:62
@ NUMBER
Definition reader.hpp:56
@ FIELD
Definition reader.hpp:53
@ STRING
Definition reader.hpp:59
@ VNULL
Definition reader.hpp:44
@ FALSE
Definition reader.hpp:50
@ END_OBJECT
Definition reader.hpp:65
@ TRUE
Definition reader.hpp:47
AnCH framework base namespace.
Definition app.hpp:30
JSON mapping options.
Definition mappingOptions.hpp:38