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 "JsonData.h"
24 
25 #include <memory>
26 
27 namespace armarx
28 {
29  class JsonValue;
30  using JsonValuePtr = std::shared_ptr<JsonValue>;
31 
33 
34  class JsonValue : public JsonData
35  {
36  friend class StructuralJsonParser;
37  public:
39 
40  JsonValue(const std::string& value);
41  JsonValue(int value);
42  JsonValue(long value);
43  JsonValue(float value);
44  JsonValue(double value);
45 
46  static JsonValuePtr Null();
47  static JsonValuePtr True();
48  static JsonValuePtr False();
49  static JsonValuePtr Create(const std::string& value);
50  static JsonValuePtr Create(int value);
51  static JsonValuePtr Create(long value);
52  static JsonValuePtr Create(float value);
53  static JsonValuePtr Create(double value);
54 
55  static JsonValuePtr CreateRaw(Type type, const std::string& value);
56  static bool CheckValue(Type type, const std::string& value);
57 
58  static bool CheckNumber(const std::string& value);
59  static bool CheckInt(const std::string& value);
60  static bool CheckBool(const std::string& value);
61  static bool CheckNull(const std::string& value);
62 
63 
64  void writeJson(const JsonWriterPtr& writer) override;
65 
66  JsonValuePtr toSharedPtr() const;
67 
68  static std::string ToString(int value);
69  static std::string ToString(long value);
70  static std::string ToString(float value);
71  static std::string ToString(double value);
72 
73  std::string asString() const;
74  float asFloat() const;
75  int asInt() const;
76  bool asBool() const;
77 
78  std::string rawValue();
79 
80  JsonDataPtr clone() override;
81 
82  Type getType();
83 
84  private:
85  JsonValue(Type type, const std::string& value);
86  Type type;
87  std::string value;
88 
89  };
90 }
91 
JsonData.h
armarx::JsonValue::eNumber
@ eNumber
Definition: JsonValue.h:38
armarx::JsonValuePtr
std::shared_ptr< JsonValue > JsonValuePtr
Definition: JsonValue.h:30
armarx::JsonValue::rawValue
std::string rawValue()
Definition: JsonValue.cpp:238
armarx::JsonValue::Type
Type
Definition: JsonValue.h:38
armarx::JsonValue::True
static JsonValuePtr True()
Definition: JsonValue.cpp:54
armarx::JsonValue::False
static JsonValuePtr False()
Definition: JsonValue.cpp:59
armarx::JsonValue::CheckInt
static bool CheckInt(const std::string &value)
Definition: JsonValue.cpp:131
armarx::JsonValue::toSharedPtr
JsonValuePtr toSharedPtr() const
Definition: JsonValue.cpp:164
armarx::JsonValue::Create
static JsonValuePtr Create(const std::string &value)
Definition: JsonValue.cpp:65
armarx::JsonValue::clone
JsonDataPtr clone() override
Definition: JsonValue.cpp:243
armarx::JsonWriterPtr
std::shared_ptr< JsonWriter > JsonWriterPtr
Definition: JsonWriter.h:30
armarx::JsonValue::CheckNumber
static bool CheckNumber(const std::string &value)
Definition: JsonValue.cpp:124
armarx::JsonValue::asFloat
float asFloat() const
Definition: JsonValue.cpp:211
armarx::JsonValue
Definition: JsonValue.h:34
armarx::JsonValue::eString
@ eString
Definition: JsonValue.h:38
cxxopts::value
std::shared_ptr< Value > value()
Definition: cxxopts.hpp:926
armarx::JsonValue::eNull
@ eNull
Definition: JsonValue.h:38
armarx::JsonValue::CheckNull
static bool CheckNull(const std::string &value)
Definition: JsonValue.cpp:143
armarx::JsonValue::eBool
@ eBool
Definition: JsonValue.h:38
armarx::JsonData
Definition: JsonData.h:33
armarx::JsonValue::asString
std::string asString() const
Definition: JsonValue.cpp:202
armarx::JsonValue::writeJson
void writeJson(const JsonWriterPtr &writer) override
Definition: JsonValue.cpp:148
armarx::JsonValue::getType
Type getType()
Definition: JsonValue.cpp:249
armarx::JsonValue::ToString
static std::string ToString(int value)
Definition: JsonValue.cpp:170
armarx::JsonValue::CheckValue
static bool CheckValue(Type type, const std::string &value)
Definition: JsonValue.cpp:105
armarx::JsonValue::JsonValue
JsonValue(const std::string &value)
Definition: JsonValue.cpp:29
armarx::JsonDataPtr
std::shared_ptr< JsonData > JsonDataPtr
Definition: JsonData.h:31
armarx::JsonValue::CheckBool
static bool CheckBool(const std::string &value)
Definition: JsonValue.cpp:138
armarx::StructuralJsonParser
Definition: StructuralJsonParser.h:35
armarx::JsonValue::CreateRaw
static JsonValuePtr CreateRaw(Type type, const std::string &value)
Definition: JsonValue.cpp:95
armarx::JsonValue::asBool
bool asBool() const
Definition: JsonValue.cpp:229
armarx
This file offers overloads of toIce() and fromIce() functions for STL container types.
Definition: ArmarXTimeserver.cpp:28
armarx::JsonValue::Null
static JsonValuePtr Null()
Definition: JsonValue.cpp:49
armarx::JsonValue::asInt
int asInt() const
Definition: JsonValue.cpp:220