-
Notifications
You must be signed in to change notification settings - Fork 0
/
JSON_handler.h
55 lines (47 loc) · 1.71 KB
/
JSON_handler.h
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
/*
* Copyright (C) 2011-2017 Redis Labs Ltd.
*
* This file is part of memtier_benchmark.
*
* memtier_benchmark is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, version 2.
*
* memtier_benchmark is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with memtier_benchmark. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef _JSON_HANDLER_H
#define _JSON_HANDLER_H
#include <stdlib.h>
#include <stdio.h>
#include <stdarg.h>
#include <list>
// enum for holding type of nesting
typedef enum{
NESTED_GENERAL, // {}
NESTED_ARRAY // []
}eJSON_NESTED_TYPE;
/** represents an JSON handler, At this phase, only writes to JSON. */
class json_handler {
protected:
FILE * m_json_file;
// This list is used later for closing the nesting
std::list<eJSON_NESTED_TYPE> m_nest_closer_types;
void beutify(bool only_tabs = false);
public:
json_handler(const char * jsonfilename);
~json_handler();
// Write a single object to JSON
void write_obj(const char * objectname, const char * format, ...);
// Starts nesting, the type is used for deciding which charecter to be used for opening and closing
// the nesting ('{}','[]')
void open_nesting(const char * objectname,eJSON_NESTED_TYPE type = NESTED_GENERAL);
// returns the nested level left after closing
int close_nesting();
};
#endif /* _JSON_HANDLER_H */