aboutsummaryrefslogtreecommitdiffstats
path: root/contrib/libs/jinja2cpp/src/binding/rapid_json_serializer.h
blob: 66e26c14da7632d8def3956378a51fca0c85a934 (plain) (blame)
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
#ifndef JINJA2CPP_SRC_RAPID_JSON_SERIALIZER_H
#define JINJA2CPP_SRC_RAPID_JSON_SERIALIZER_H

#include "../internal_value.h"

#include <rapidjson/document.h>
#include <rapidjson/rapidjson.h>

#include <memory>

namespace jinja2
{
namespace rapidjson_serializer
{

class ValueWrapper
{
    friend class DocumentWrapper;

public:
    ValueWrapper(ValueWrapper&&) = default;
    ValueWrapper& operator=(ValueWrapper&&) = default;

    std::string AsString(uint8_t indent = 0) const;

private:
    ValueWrapper(rapidjson::Value&& value, std::shared_ptr<rapidjson::Document> document);

    rapidjson::Value m_value;
    std::shared_ptr<rapidjson::Document> m_document;
};

class DocumentWrapper
{
public:
    DocumentWrapper();

    DocumentWrapper(DocumentWrapper&&) = default;
    DocumentWrapper& operator=(DocumentWrapper&&) = default;

    ValueWrapper CreateValue(const InternalValue& value) const;

private:
    std::shared_ptr<rapidjson::Document> m_document;
};

} // namespace rapidjson_serializer
} // namespace jinja2

#endif // JINJA2CPP_SRC_RAPID_JSON_SERIALIZER_H