| Line |
Branch |
Exec |
Source |
| 1 |
|
|
/** |
| 2 |
|
|
* This file is part of the CernVM File System. |
| 3 |
|
|
*/ |
| 4 |
|
|
|
| 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 |
|
|
|
| 17 |
|
|
class JsonDocument : SingleCopy { |
| 18 |
|
|
public: |
| 19 |
|
|
static JsonDocument *Create(const std::string &text); |
| 20 |
|
|
~JsonDocument(); |
| 21 |
|
|
|
| 22 |
|
|
std::string PrintCanonical(); |
| 23 |
|
|
std::string PrintPretty(); |
| 24 |
|
|
|
| 25 |
|
1505 |
inline const JSON *root() const { return root_; } |
| 26 |
|
240 |
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 { |
| 36 |
|
24 |
PrintOptions() : with_whitespace(false), num_indent(0) { } |
| 37 |
|
|
bool with_whitespace; |
| 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_; |
| 48 |
|
|
JSON *root_; |
| 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_ |
| 56 |
|
|
|