File: jansson.h

package info (click to toggle)
freespace2 24.2.0%2Brepack-1
  • links: PTS, VCS
  • area: non-free
  • in suites: forky, sid
  • size: 43,716 kB
  • sloc: cpp: 595,001; ansic: 21,741; python: 1,174; sh: 457; makefile: 248; xml: 181
file content (100 lines) | stat: -rw-r--r-- 2,061 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
#pragma once

#include "cfile/cfile.h"
#include <jansson.h>
#include <stdexcept>

int json_dump_cfile(const json_t *json, CFILE* file, size_t flags);

json_t *json_load_cfile(CFILE* cfile, size_t flags, json_error_t *error);

SCP_string json_dump_string(const json_t* json, size_t flags);

SCP_string json_dump_string_new(json_t* json, size_t flagse);

// This allows using std::unique_ptr with json_t values
namespace std {
template <>
class default_delete<json_t> {
  public:
	void operator()(json_t* ptr) const
	{
		if (ptr) {
			json_decref(ptr);
		}
	}
};
}; // namespace std

class json_exception : public std::runtime_error {
  public:
	explicit json_exception(const json_error_t& error);
};

namespace json {
namespace detail {

class object_iterator {
  public:
	using value_type = std::tuple<const char*, json_t*>;
	using reference = value_type&;
	using pointer = value_type*;

	object_iterator(json_t* obj, void* iter);

	object_iterator& operator++();
	value_type operator*() const;

	friend bool operator==(const object_iterator& lhs, const object_iterator& rhs);
	friend bool operator!=(const object_iterator& lhs, const object_iterator& rhs);

  private:
	json_t* m_obj = nullptr;
	void* m_iter = nullptr;
};

class array_iterator {
  public:
	using value_type = json_t*;
	using reference = value_type&;
	using pointer = value_type*;

	array_iterator(json_t* obj, size_t index);

	array_iterator& operator++();
	value_type operator*() const;

	friend bool operator==(const array_iterator& lhs, const array_iterator& rhs);
	friend bool operator!=(const array_iterator& lhs, const array_iterator& rhs);
  private:
	json_t* m_array = nullptr;
	size_t m_index = 0;
};

} // namespace detail

class object_range {
  public:
	object_range(json_t* obj);

	detail::object_iterator begin();

	detail::object_iterator end();

  private:
	json_t* m_obj = nullptr;
};

class array_range {
  public:
	array_range(json_t* array);

	detail::array_iterator begin();

	detail::array_iterator end();

  private:
	json_t* m_array = nullptr;
};

} // namespace json