Bela
Real-time, ultra-low-latency audio and sensor processing system for BeagleBone Black
Loading...
Searching...
No Matches
JSONValue.h
1/*
2 * File JSONValue.h part of the SimpleJSON Library - http://mjpa.in/json
3 *
4 * Copyright (C) 2010 Mike Anchor
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining a copy
7 * of this software and associated documentation files (the "Software"), to deal
8 * in the Software without restriction, including without limitation the rights
9 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 * copies of the Software, and to permit persons to whom the Software is
11 * furnished to do so, subject to the following conditions:
12 *
13 * The above copyright notice and this permission notice shall be included in
14 * all copies or substantial portions of the Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22 * THE SOFTWARE.
23 */
24
25#ifndef _JSONVALUE_H_
26#define _JSONVALUE_H_
27
28#include <vector>
29#include <string>
30
31#include "JSON.h"
32
33class JSON;
34
35enum JSONType { JSONType_Null, JSONType_String, JSONType_Bool, JSONType_Number, JSONType_Array, JSONType_Object };
36
37class JSONValue
38{
39 friend class JSON;
40
41 public:
42 JSONValue(/*NULL*/);
43 JSONValue(const wchar_t *m_char_value);
44 JSONValue(const std::wstring &m_string_value);
45 JSONValue(bool m_bool_value);
46 JSONValue(double m_number_value);
47 JSONValue(int m_integer_value);
48 JSONValue(const JSONArray &m_array_value);
49 JSONValue(const JSONObject &m_object_value);
50 JSONValue(const JSONValue &m_source);
51 ~JSONValue();
52
53 bool IsNull() const;
54 bool IsString() const;
55 bool IsBool() const;
56 bool IsNumber() const;
57 bool IsArray() const;
58 bool IsObject() const;
59
60 const std::wstring &AsString() const;
61 bool AsBool() const;
62 double AsNumber() const;
63 const JSONArray &AsArray() const;
64 const JSONObject &AsObject() const;
65
66 std::size_t CountChildren() const;
67 bool HasChild(std::size_t index) const;
68 JSONValue *Child(std::size_t index);
69 bool HasChild(const wchar_t* name) const;
70 JSONValue *Child(const wchar_t* name);
71 std::vector<std::wstring> ObjectKeys() const;
72
73 std::wstring Stringify(bool const prettyprint = false) const;
74 protected:
75 static JSONValue *Parse(const wchar_t **data);
76
77 private:
78 static std::wstring StringifyString(const std::wstring &str);
79 std::wstring StringifyImpl(size_t const indentDepth) const;
80 static std::wstring Indent(size_t depth);
81
82 JSONType type;
83
84 union
85 {
86 bool bool_value;
87 double number_value;
88 std::wstring *string_value;
89 JSONArray *array_value;
90 JSONObject *object_value;
91 };
92
93};
94
95#endif
Definition JSON.h:96