Argo  1.0
A C++ library for handling JSON.
pointer.hpp
Go to the documentation of this file.
1 #ifndef _json_pointer_hpp_
2 #define _json_pointer_hpp_
3 
4 /*
5  * Copyright (c) 2017 Andrew Haisley
6  *
7  * Permission is hereby granted, free of charge, to any person obtaining a copy
8  * of this software and associated documentation files (the "Software"), to deal
9  * in the Software without restriction, including without limitation the rights
10  * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11  * copies of the Software, and to permit persons to whom the Software is
12  * furnished to do so, subject to the following conditions:
13  *
14  * The above copyright notice and this permission notice shall be included in all
15  * copies or substantial portions of the Software.
16  *
17  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
23  * SOFTWARE.
24  */
25 
27 
28 #include <list>
29 #include <string>
30 
31 #include "common.hpp"
32 
33 namespace NAMESPACE
34 {
41  class pointer
42  {
43  public:
44 
53  class token
54  {
55  public:
56 
58  typedef enum { all_e, object_e, array_e } type_t;
59 
61  token();
62 
64  token(const std::string &name);
65 
67  token(size_t index);
68 
70  type_t get_type() const;
71 
73  const std::string &get_name() const;
74 
76  size_t get_index() const;
77 
78  private:
79 
81  type_t m_type;
82 
84  std::string m_name;
85 
87  size_t m_index;
88  };
89 
94  pointer(const std::string &pointer);
95 
99  const std::list<token> &get_path() const;
100 
101  private:
102 
103  std::list<token> m_path;
104 
105  void build_from_uri_fragment(const std::string &pointer);
106  void build_from_json_string(const std::string &pointer);
107  bool next_token(const std::string &pointer, size_t &start, size_t &end);
108  token translate_uri_token(const std::string &pointer, size_t &start, size_t &end);
109  token translate_jsonp_token(const std::string &pointer, size_t &start, size_t &end);
110  token make_token(const std::string &s);
111  int from_hex(const std::string &s, size_t index);
112  };
113 
115  std::ostream &operator<<(std::ostream &stream, const pointer &p);
116 }
117 
118 #endif
#define NAMESPACE
You can change the namespace of the whole library by changing this value.
Definition: common.hpp:29
Tokens in a JSON pointer.
Definition: pointer.hpp:53
type_t
Different types of pointer tokens.
Definition: pointer.hpp:58
Common defs needed everywhere and, as far as is possible, platform specific changes.
JSON pointers as per the RFT.
Definition: pointer.hpp:41
std::ostream & operator<<(std::ostream &stream, const json_exception &e)