1 #ifndef LIBJSON_GUARD_STREAM_H
2 #define LIBJSON_GUARD_STREAM_H
3 
4 #include "JSONDebug.h"
5 
6 #ifdef JSON_STREAM
7 
8 #ifdef JSON_LESS_MEMORY
9 	#ifdef __GNUC__
10 		#pragma pack(push, 1)
11 	#elif _MSC_VER
12 		#pragma pack(push, JSONStream_pack, 1)
13 	#endif
14 #endif
15 
16 #ifdef JSON_MEMORY_CALLBACKS
17 #include "JSONMemory.h"
18 #endif
19 
20 #ifndef JSON_LIBRARY
21 class JSONNode; //foreward declaration
22 typedef void (*json_stream_callback_t)(JSONNode &, void *);
23 #endif
24 
25 class JSONStream {
26 public:
27 	LIBJSON_OBJECT(JSONStream);
28     JSONStream(json_stream_callback_t call_p, json_stream_e_callback_t call_e = NULL, void * callbackIdentifier = JSONSTREAM_SELF) json_nothrow;
29     JSONStream(const JSONStream & orig) json_nothrow;
30     JSONStream & operator =(const JSONStream & orig) json_nothrow;
~JSONStream(void)31 	~JSONStream(void) json_nothrow { LIBJSON_DTOR; }
32 #ifdef JSON_LIBRARY
33 	JSONStream & operator << (const json_char * str) json_nothrow;
34 #else
35 	JSONStream & operator << (const json_string & str) json_nothrow;
36 #endif
37 
deleteJSONStream(JSONStream * stream)38     static void deleteJSONStream(JSONStream * stream) json_nothrow {
39 #ifdef JSON_MEMORY_CALLBACKS
40 		stream -> ~JSONStream();
41 		libjson_free<JSONStream>(stream);
42 #else
43 		delete stream;
44 #endif
45     }
46 
newJSONStream(json_stream_callback_t callback,json_stream_e_callback_t call_e,void * callbackIdentifier)47     static JSONStream * newJSONStream(json_stream_callback_t callback, json_stream_e_callback_t call_e, void * callbackIdentifier) json_nothrow {
48 #ifdef JSON_MEMORY_CALLBACKS
49 		return new(json_malloc<JSONStream>(1)) JSONStream(callback, call_e, callbackIdentifier);
50 #else
51 		return new JSONStream(callback, call_e, callbackIdentifier);
52 #endif
53     }
54 
reset()55 	inline void reset() json_nothrow {
56 		state = true;
57 		buffer.clear();
58 	}
59 JSON_PRIVATE
getIdentifier(void)60 	inline void * getIdentifier(void) json_nothrow {
61 		if (callback_identifier == JSONSTREAM_SELF){
62 			return (void*)this;
63 		}
64 		return callback_identifier;
65 	}
66 
67 	#if (JSON_READ_PRIORITY == HIGH) && (!(defined(JSON_LESS_MEMORY)))
68 		template<json_char ch>
69 		static size_t FindNextRelevant(const json_string & value_t, const size_t pos) json_nothrow json_read_priority;
70 	#else
71 		static size_t FindNextRelevant(json_char ch, const json_string & value_t, const size_t pos) json_nothrow json_read_priority;
72 	#endif
73 
74     void parse(void) json_nothrow;
75     json_string buffer;
76     json_stream_callback_t call;
77 	json_stream_e_callback_t err_call;
78 	void * callback_identifier;
79 	bool state BITS(1);
80 };
81 
82 #ifdef JSON_LESS_MEMORY
83 	#ifdef __GNUC__
84 		#pragma pack(pop)
85 	#elif _MSC_VER
86 		#pragma pack(pop, JSONStream_pack)
87 	#endif
88 #endif
89 
90 #endif
91 
92 #endif
93 
94