CernVM-FS  2.10.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
json_document.h
Go to the documentation of this file.
1 
5 #ifndef CVMFS_JSON_DOCUMENT_H_
6 #define CVMFS_JSON_DOCUMENT_H_
7 
8 #include <string>
9 #include <utility>
10 #include <vector>
11 
12 #include "json.h"
13 #include "util/single_copy.h"
14 
15 typedef struct json_value JSON;
16 
18  public:
19  static JsonDocument *Create(const std::string &text);
20  ~JsonDocument();
21 
22  std::string PrintCanonical();
23  std::string PrintPretty();
24 
25  inline const JSON *root() const { return root_; }
26  inline bool IsValid() const { return root_ != NULL; }
27 
28  static std::string EscapeString(const std::string &input);
29  static JSON *SearchInObject(const JSON *json_object, const std::string &name,
30  const json_type type);
31 
32  private:
33  static const unsigned kDefaultBlockSize = 2048; // 2kB
34 
35  struct PrintOptions {
38  unsigned num_indent;
39  };
40 
41  JsonDocument();
42  bool Parse(const std::string &text);
43  std::string PrintValue(JSON *value, PrintOptions print_options);
44  std::string PrintArray(JSON *first_child, PrintOptions print_options);
45  std::string PrintObject(JSON *first_child, PrintOptions print_options);
46 
47  block_allocator allocator_;
49  char *raw_text_;
50 };
51 
52 template <typename T>
53 bool GetFromJSON(const JSON *object, const std::string &name, T *value);
54 
55 #endif // CVMFS_JSON_DOCUMENT_H_
block_allocator allocator_
Definition: json_document.h:47
std::string PrintValue(JSON *value, PrintOptions print_options)
std::string PrintObject(JSON *first_child, PrintOptions print_options)
static JSON * SearchInObject(const JSON *json_object, const std::string &name, const json_type type)
bool GetFromJSON(const JSON *object, const std::string &name, T *value)
std::string PrintArray(JSON *first_child, PrintOptions print_options)
bool Parse(const std::string &text)
static const unsigned kDefaultBlockSize
Definition: json_document.h:33
std::string PrintCanonical()
std::string PrintPretty()
bool IsValid() const
Definition: json_document.h:26
static JsonDocument * Create(const std::string &text)
static std::string EscapeString(const std::string &input)
char * raw_text_
Definition: json_document.h:49
struct json_value JSON
Definition: helper_allow.cc:11
const JSON * root() const
Definition: json_document.h:25