JPathNavigator.h
Go to the documentation of this file.
1/*
2 * This file is part of ArmarX.
3 *
4 * Copyright (C) 2012-2016, High Performance Humanoid Technologies (H2T),
5 * Karlsruhe Institute of Technology (KIT), all rights reserved.
6 *
7 * ArmarX is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License version 2 as
9 * published by the Free Software Foundation.
10 *
11 * ArmarX is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <http://www.gnu.org/licenses/>.
18 *
19 * @author Simon Ottenhaus (simon dot ottenhaus at kit dot edu)
20 * @copyright http://www.gnu.org/licenses/gpl-2.0.txt
21 * GNU General Public License
22 */
23
24#pragma once
25
26#include <memory>
27
28#include "JsonArray.h"
29#include "JsonData.h"
30#include "JsonObject.h"
31#include "JsonValue.h"
32
33namespace armarx
34{
35 class JPathNavigator
36 {
37 private:
38 JPathNavigator(const JsonDataPtr& data, int index, const std::string& key);
39
40 public:
41 JPathNavigator(const JsonDataPtr& data);
42
43 bool isArray() const;
44 bool isObject() const;
45 bool isValue() const;
46 bool isString() const;
47 bool isBool() const;
48 bool isNull() const;
49 bool isNumber() const;
50 bool isInt() const;
51 bool isValid() const;
52
53 void checkValid() const;
54
55 std::vector<JPathNavigator> select(const std::string& expr, bool limitToOne = false) const;
56 JPathNavigator selectSingleNode(const std::string& expr) const;
57 bool remove(const std::string& key);
58 void remove(uint index);
59
60 JsonObjectPtr asObject() const;
61 JsonArrayPtr asArray() const;
62 JsonValuePtr asValue() const;
63
64 std::string asString() const;
65 float asFloat() const;
66 int asInt() const;
67 bool asBool() const;
68
69 JsonDataPtr getData() const;
70 int getIndex() const;
71 std::string getKey() const;
72
73 private:
74 JsonDataPtr data;
75 int index;
76 std::string key;
77 void select(const std::vector<std::string>& parts,
78 size_t partIndex,
79 std::vector<JPathNavigator>& result,
80 bool limitToOne = false) const;
81 };
82} // namespace armarx
std::string asString() const
JsonArrayPtr asArray() const
JPathNavigator selectSingleNode(const std::string &expr) const
JsonValuePtr asValue() const
std::vector< JPathNavigator > select(const std::string &expr, bool limitToOne=false) const
bool remove(const std::string &key)
std::string getKey() const
JsonObjectPtr asObject() const
JsonDataPtr getData() const
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< JsonObject > JsonObjectPtr
Definition JsonObject.h:34
std::shared_ptr< JsonData > JsonDataPtr
Definition JsonData.h:31
std::shared_ptr< JsonArray > JsonArrayPtr
Definition JsonArray.h:32