AnCH Framework 0.2
Another C++ Hack: C++23 utility libraries
Loading...
Searching...
No Matches
writerContext.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 <ostream>
25#include <streambuf>
26#include <string_view>
27#include <string>
28#include <functional>
29#include <stdint.h>
30#include <deque>
31
32#include "json/mappingOptions.hpp"
33
34namespace anch::json {
35
45 class ANCH_JSON_EXPORT WriterContext {
46
47 // Attributes +
48 public:
50 std::ostream& output;
51
52 private:
55
57 std::deque<bool> _firsts;
58
60 std::streambuf* _sbuf;
61 // Attributes -
62
63 // Constructors +
64 public:
68 WriterContext() = delete;
69
75 WriterContext(const WriterContext& context) = delete;
76
82 WriterContext(WriterContext&& context) = delete;
83
90 WriterContext(std::ostream& os, const anch::json::MappingOptions& options) noexcept;
91 // Constructors -
92
93 // Destructor +
94 public:
100 virtual ~WriterContext() noexcept;
101 // Destructor -
102
103 // Methods +
104 public:
112 const anch::json::MappingOptions& options() const noexcept;
113
121 bool writeNull(const std::string& field);
122
129 bool writeEmptyArray(const std::string& field);
130
137 bool writeEmptyObject(const std::string& field);
138
145 void writeField(const std::string& field);
146
154 void writeRawField(std::string_view field);
155
160
164 void endArray();
165
170
174 void endObject();
175
179 void next();
180
187 void write(char c);
188
195 void write(std::string_view str);
196
206 template<typename T>
207 void writeNumber(T value);
208
215 void writeString(std::string_view str);
216
224 void writeEscaped(std::string_view str);
225
226 private:
230 void indent();
231
237 void writeEscapeSequence(char c);
238 // Methods -
239
240 };
241
242}
243
244#include "json/impl/writerContext.hpp"
void writeString(std::string_view str)
virtual ~WriterContext() noexcept
bool writeEmptyArray(const std::string &field)
bool writeNull(const std::string &field)
void writeRawField(std::string_view field)
void writeField(const std::string &field)
void writeEscaped(std::string_view str)
WriterContext(std::ostream &os, const anch::json::MappingOptions &options) noexcept
WriterContext(const WriterContext &context)=delete
WriterContext(WriterContext &&context)=delete
bool writeEmptyObject(const std::string &field)
const anch::json::MappingOptions & options() const noexcept
std::ostream & output
Definition writerContext.hpp:50
JSON namespace.
Definition constants.hpp:27
AnCH framework base namespace.
Definition app.hpp:30
JSON mapping options.
Definition mappingOptions.hpp:38