NAP
jsonwriter.h
1 /* This Source Code Form is subject to the terms of the Mozilla Public
2  * License, v. 2.0. If a copy of the MPL was not distributed with this
3  * file, You can obtain one at https://mozilla.org/MPL/2.0/. */
4 
5 #pragma once
6 
7 // Local Includes
8 #include "writer.h"
9 
10 // External Includes
11 #include <utility/dllexport.h>
12 #include <rapidjson/prettywriter.h>
13 #include <rapidjson/document.h>
14 
15 namespace nap
16 {
17  namespace rtti
18  {
19  class NAPAPI JSONWriter : public Writer
20  {
21  public:
22  JSONWriter();
23 
27  std::string GetJSON();
28 
32  bool supportsEmbeddedPointers() const override { return true; }
33 
39  bool start(const ObjectList& rootObjects) override;
40 
44  bool finish() override;
45 
49  bool startRootObject(const rtti::TypeInfo& type) override;
50 
54  bool finishRootObject() override;
55 
59  bool startCompound(const rtti::TypeInfo& type) override;
60 
64  bool finishCompound() override;
65 
69  bool startArray(int length) override;
70 
74  bool finishArray() override;
75 
79  bool writeProperty(const std::string& propertyName) override;
80 
84  bool writePointer(const std::string& pointeeID) override;
85 
89  bool writePrimitive(const rtti::TypeInfo& type, const rtti::Variant& value) override;
90 
91  private:
92  rapidjson::StringBuffer mStringBuffer; // The string buffer we're writing to
93  rapidjson::PrettyWriter<rapidjson::StringBuffer> mWriter; // The json writer itself
94  };
95  }
96 }
nap::rtti::Writer
Definition: writer.h:32
nap::rtti::JSONWriter
Definition: jsonwriter.h:19
nap::rtti::ObjectList
std::vector< Object * > ObjectList
Definition: rttiutilities.h:34
nap
Definition: templateapp.h:17
nap::rtti::Variant
rttr::variant Variant
Definition: typeinfo.h:143
nap::rtti::JSONWriter::supportsEmbeddedPointers
bool supportsEmbeddedPointers() const override
Definition: jsonwriter.h:32
nap::rtti::TypeInfo
rttr::type TypeInfo
Definition: typeinfo.h:140