JsonValue.h
Go to the documentation of this file.
1/*
2* This file is part of ArmarX.
3*
4* ArmarX is free software; you can redistribute it and/or modify
5* it under the terms of the GNU General Public License version 2 as
6* published by the Free Software Foundation.
7*
8* ArmarX is distributed in the hope that it will be useful, but
9* WITHOUT ANY WARRANTY; without even the implied warranty of
10* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11* GNU General Public License for more details.
12*
13* You should have received a copy of the GNU General Public License
14* along with this program. If not, see <http://www.gnu.org/licenses/>.
15*
16* @author Simon Ottenhaus (simon dot ottenhaus at kit dot edu)
17* @copyright http://www.gnu.org/licenses/gpl-2.0.txt
18* GNU General Public License
19*/
20
21#pragma once
22
23#include <memory>
24
25#include "JsonData.h"
26
27namespace armarx
28{
29 class JsonValue;
30 using JsonValuePtr = std::shared_ptr<JsonValue>;
31
33
34 class JsonValue : public JsonData
35 {
37
38 public:
46
47 JsonValue(const std::string& value);
48 JsonValue(int value);
49 JsonValue(long value);
50 JsonValue(float value);
51 JsonValue(double value);
52
53 static JsonValuePtr Null();
54 static JsonValuePtr True();
55 static JsonValuePtr False();
56 static JsonValuePtr Create(const std::string& value);
57 static JsonValuePtr Create(int value);
58 static JsonValuePtr Create(long value);
59 static JsonValuePtr Create(float value);
60 static JsonValuePtr Create(double value);
61
62 static JsonValuePtr CreateRaw(Type type, const std::string& value);
63 static bool CheckValue(Type type, const std::string& value);
64
65 static bool CheckNumber(const std::string& value);
66 static bool CheckInt(const std::string& value);
67 static bool CheckBool(const std::string& value);
68 static bool CheckNull(const std::string& value);
69
70
71 void writeJson(const JsonWriterPtr& writer) override;
72
74
75 static std::string ToString(int value);
76 static std::string ToString(long value);
77 static std::string ToString(float value);
78 static std::string ToString(double value);
79
80 std::string asString() const;
81 float asFloat() const;
82 int asInt() const;
83 bool asBool() const;
84
85 std::string rawValue();
86
87 JsonDataPtr clone() override;
88
89 Type getType();
90
91 private:
92 JsonValue(Type type, const std::string& value);
93 Type type;
94 std::string value;
95 };
96} // namespace armarx
static JsonValuePtr Null()
Definition JsonValue.cpp:51
static JsonValuePtr Create(const std::string &value)
Definition JsonValue.cpp:72
std::string asString() const
static JsonValuePtr CreateRaw(Type type, const std::string &value)
static JsonValuePtr True()
Definition JsonValue.cpp:58
static bool CheckInt(const std::string &value)
static JsonValuePtr False()
Definition JsonValue.cpp:65
static bool CheckNumber(const std::string &value)
void writeJson(const JsonWriterPtr &writer) override
static bool CheckNull(const std::string &value)
std::string rawValue()
float asFloat() const
static std::string ToString(int value)
JsonValuePtr toSharedPtr() const
bool asBool() const
int asInt() const
JsonDataPtr clone() override
static bool CheckValue(Type type, const std::string &value)
static bool CheckBool(const std::string &value)
JsonValue(const std::string &value)
Definition JsonValue.cpp:30
friend class StructuralJsonParser
Definition JsonValue.h:36
This file offers overloads of toIce() and fromIce() functions for STL container types.
std::shared_ptr< JsonValue > JsonValuePtr
Definition JsonValue.h:30
std::shared_ptr< JsonData > JsonDataPtr
Definition JsonData.h:31
std::shared_ptr< JsonWriter > JsonWriterPtr
Definition JsonWriter.h:30