Open Lighting Architecture: include/ola/web/JsonWriter.h Source File

| 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
28
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
45
49 class JsonWriter : public JsonValueConstVisitorInterface,
50 JsonObjectPropertyVisitor {
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
85
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};
102
103} // namespace web
104} // namespace ola
105#endif // INCLUDE_OLA_WEB_JSONWRITER_H_
Json.h
Basic data types used to represent elements in a JSON document.
Macro.h
Helper macros.
ola::web::JsonArray
An array of JSON values. Arrays in JSON can contain values of different types.
Definition Json.h:1043
ola::web::JsonObject
A JSON object. JSON Objects are key : value mappings, similar to dictionaries in Python.
Definition Json.h:899
ola::web::JsonValue
The base class for JSON values.
Definition Json.h:119
ola::web::JsonWriter::AsString
static std::string AsString(const JsonValue &value)
Get the string representation of the JsonValue.
Definition JsonWriter.cpp:38
ola::web::JsonWriter::Write
static void Write(std::ostream *output, const JsonValue &value)
Write the string representation of the JsonValue to a ostream.
Definition JsonWriter.cpp:33
ola::web
Classes to deal with web services.
Definition Json.cpp:29
ola
The namespace containing all OLA symbols.
Definition Credentials.cpp:44