Open Lighting Architecture 0.10.9
Loading...
Searching...
No Matches
JsonWriter.h
Go to the documentation of this file.
1/*
2 * This library is free software; you can redistribute it and/or
3 * modify it under the terms of the GNU Lesser General Public
4 * License as published by the Free Software Foundation; either
5 * version 2.1 of the License, or (at your option) any later version.
6 *
7 * This library is distributed in the hope that it will be useful,
8 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
10 * Lesser General Public License for more details.
11 *
12 * You should have received a copy of the GNU Lesser General Public
13 * License along with this library; if not, write to the Free Software
14 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
15 *
16 * JsonWriter.h
17 * Serialize JSON data.
18 * Copyright (C) 2012 Simon Newton
19 */
20
29#ifndef INCLUDE_OLA_WEB_JSONWRITER_H_
30#define INCLUDE_OLA_WEB_JSONWRITER_H_
31
32#include <ola/base/Macro.h>
33#include <ola/web/Json.h>
34#include <stdint.h>
35#include <ostream>
36#include <string>
37
38namespace ola {
39namespace web {
40
51 public:
57 static void Write(std::ostream *output, const JsonValue &value);
58
63 static std::string AsString(const JsonValue &value);
64
68 void Visit(const JsonString &value);
69 void Visit(const JsonBool &value);
70 void Visit(const JsonNull &value);
71 void Visit(const JsonRawValue &value);
72 void Visit(const JsonObject &value);
73 void Visit(const JsonArray &value);
74 void Visit(const JsonUInt &value);
75 void Visit(const JsonUInt64 &value);
76 void Visit(const JsonInt &value);
77 void Visit(const JsonInt64 &value);
78 void Visit(const JsonDouble &value);
79
80 void VisitProperty(const std::string &property, const JsonValue &value);
81
86 private:
87 std::ostream *m_output;
88 unsigned int m_indent;
89 std::string m_separator;
90
91 explicit JsonWriter(std::ostream *output)
92 : m_output(output),
93 m_indent(0),
94 m_separator("") {
95 }
96
100 static const unsigned int DEFAULT_INDENT = 2;
101};
103} // namespace web
104} // namespace ola
105#endif // INCLUDE_OLA_WEB_JSONWRITER_H_
Basic data types used to represent elements in a JSON document.
Helper macros.
An array of JSON values. Arrays in JSON can contain values of different types.
Definition Json.h:1043
A Bool value.
Definition Json.h:774
A double value.
Definition Json.h:654
A signed 64bit int value.
Definition Json.h:581
A signed 32bit int value.
Definition Json.h:447
The null value.
Definition Json.h:818
A JSON object. JSON Objects are key : value mappings, similar to dictionaries in Python.
Definition Json.h:899
A class used to visit Json values within a JsonObject.
Definition Json.h:1226
A raw value, useful if you want to cheat.
Definition Json.h:850
A string value.
Definition Json.h:279
An unsigned 64bit int value.
Definition Json.h:513
An unsigned 32bit int value.
Definition Json.h:380
The const interface for the JsonValueVisitor class.
Definition Json.h:99
The base class for JSON values.
Definition Json.h:119
A class to serialize a JSONValue to text.
Definition JsonWriter.h:50
static std::string AsString(const JsonValue &value)
Get the string representation of the JsonValue.
Definition JsonWriter.cpp:38
static void Write(std::ostream *output, const JsonValue &value)
Write the string representation of the JsonValue to a ostream.
Definition JsonWriter.cpp:33
The namespace containing all OLA symbols.
Definition Credentials.cpp:44