Operator Console
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Public Member Functions | Static Public Member Functions | Public Attributes | List of all members
JSONStream Class Reference

#include <JSONStream.h>

Public Member Functions

 JSONStream (json_stream_callback_t call_p, json_stream_e_callback_t call_e=NULL, void *callbackIdentifier=JSONSTREAM_SELF) json_nothrow
 
 JSONStream (const JSONStream &orig) json_nothrow
 
JSONStreamoperator= (const JSONStream &orig) json_nothrow
 
JSONStreamoperator<< (const json_string &str) json_nothrow
 
void reset () json_nothrow
 
JSON_PRIVATE void * getIdentifier (void) json_nothrow
 
void parse (void) json_nothrow
 
bool state BITS (1)
 
 JSONStream (json_stream_callback_t call_p, json_stream_e_callback_t call_e=NULL, void *callbackIdentifier=JSONSTREAM_SELF) json_nothrow
 
 JSONStream (const JSONStream &orig) json_nothrow
 
JSONStreamoperator= (const JSONStream &orig) json_nothrow
 
JSONStreamoperator<< (const json_string &str) json_nothrow
 
void reset () json_nothrow
 
JSON_PRIVATE void * getIdentifier (void) json_nothrow
 
void parse (void) json_nothrow
 
bool state BITS (1)
 

Static Public Member Functions

static void deleteJSONStream (JSONStream *stream) json_nothrow
 
static JSONStreamnewJSONStream (json_stream_callback_t callback, json_stream_e_callback_t call_e, void *callbackIdentifier) json_nothrow
 
template<json_char ch>
static size_t FindNextRelevant (const json_string &value_t, const size_t pos) json_nothrow json_read_priority
 
static void deleteJSONStream (JSONStream *stream) json_nothrow
 
static JSONStreamnewJSONStream (json_stream_callback_t callback, json_stream_e_callback_t call_e, void *callbackIdentifier) json_nothrow
 
template<json_char ch>
static size_t FindNextRelevant (const json_string &value_t, const size_t pos) json_nothrow json_read_priority
 

Public Attributes

json_string buffer
 
json_stream_callback_t call
 
json_stream_e_callback_t err_call
 
void * callback_identifier
 

Constructor & Destructor Documentation

JSONStream::JSONStream ( json_stream_callback_t  call_p,
json_stream_e_callback_t  call_e = NULL,
void *  callbackIdentifier = JSONSTREAM_SELF 
)

Referenced by newJSONStream().

9 : state(true), call(call_p), err_call(call_e), buffer(), callback_identifier(callbackIdentifier) {}
void * callback_identifier
Definition: JSONStream.h:76
json_stream_e_callback_t err_call
Definition: JSONStream.h:75
json_stream_callback_t call
Definition: JSONStream.h:74
json_string buffer
Definition: JSONStream.h:73

Here is the caller graph for this function:

JSONStream::JSONStream ( const JSONStream orig)
11 : state(orig.state), call(orig.call), err_call(orig.err_call), buffer(orig.buffer), callback_identifier(orig.callback_identifier){}
void * callback_identifier
Definition: JSONStream.h:76
json_stream_e_callback_t err_call
Definition: JSONStream.h:75
json_stream_callback_t call
Definition: JSONStream.h:74
json_string buffer
Definition: JSONStream.h:73
JSONStream::JSONStream ( json_stream_callback_t  call_p,
json_stream_e_callback_t  call_e = NULL,
void *  callbackIdentifier = JSONSTREAM_SELF 
)
JSONStream::JSONStream ( const JSONStream orig)

Member Function Documentation

bool state JSONStream::BITS ( )
bool state JSONStream::BITS ( )
static void JSONStream::deleteJSONStream ( JSONStream stream)
inlinestatic
36  {
37 #ifdef JSON_MEMORY_CALLBACKS
38  stream -> ~JSONStream();
39  libjson_free<JSONStream>(stream);
40 #else
41  delete stream;
42 #endif
43  }
Definition: JSONStream.h:25
static void JSONStream::deleteJSONStream ( JSONStream stream)
inlinestatic
36  {
37 #ifdef JSON_MEMORY_CALLBACKS
38  stream -> ~JSONStream();
39  libjson_free<JSONStream>(stream);
40 #else
41  delete stream;
42 #endif
43  }
Definition: JSONStream.h:25
template<json_char ch>
static size_t JSONStream::FindNextRelevant ( const json_string &  value_t,
const size_t  pos 
)
static
template<json_char ch>
size_t JSONStream::FindNextRelevant ( const json_string &  value_t,
const size_t  pos 
)
static

References BRACKET_STREAM, json_char, json_nothrow, JSON_TEXT, json_unlikely, and QUOTECASE_STREAM.

70  {
71 #else
72  #define STREAM_FIND_NEXT_RELEVANT(ch, vt, po) FindNextRelevant(ch, vt, po)
73  size_t JSONStream::FindNextRelevant(json_char ch, const json_string & value_t, const size_t pos) json_nothrow {
74 #endif
75  const json_char * start = value_t.c_str();
76  for (const json_char * p = start + pos; *p; ++p){
77  if (json_unlikely(*p == ch)) return p - start;
78  switch (*p){
80  BRACKET_STREAM(JSON_TEXT('{'), JSON_TEXT('}'))
81  QUOTECASE_STREAM()
82  }
83  };
84  return json_string::npos;
85 }
#define JSON_TEXT(s)
Definition: Strings_Defs.h:30
static size_t FindNextRelevant(const json_string &value_t, const size_t pos) json_nothrow json_read_priority
Definition: JSONStream.cpp:70
#define json_unlikely(x)
Definition: Unknown_C.h:17
#define json_char
Definition: Strings_Defs.h:21
#define json_nothrow
Definition: Unknown_C.h:8
#define BRACKET_STREAM(left, right)
Definition: JSONStream.cpp:48
JSON_PRIVATE void* JSONStream::getIdentifier ( void  )
inline

References callback_identifier, and JSONSTREAM_SELF.

58  {
60  return (void*)this;
61  }
62  return callback_identifier;
63  }
#define JSONSTREAM_SELF
Definition: JSONDefs.h:124
void * callback_identifier
Definition: JSONStream.h:76
JSON_PRIVATE void* JSONStream::getIdentifier ( void  )
inline

References callback_identifier, and JSONSTREAM_SELF.

Referenced by parse().

58  {
60  return (void*)this;
61  }
62  return callback_identifier;
63  }
#define JSONSTREAM_SELF
Definition: JSONDefs.h:124
void * callback_identifier
Definition: JSONStream.h:76

Here is the caller graph for this function:

static JSONStream* JSONStream::newJSONStream ( json_stream_callback_t  callback,
json_stream_e_callback_t  call_e,
void *  callbackIdentifier 
)
inlinestatic

References JSONStream().

45  {
46 #ifdef JSON_MEMORY_CALLBACKS
47  return new(json_malloc<JSONStream>(1)) JSONStream(callback, call_e, callbackIdentifier);
48 #else
49  return new JSONStream(callback, call_e, callbackIdentifier);
50 #endif
51  }
JSONStream(json_stream_callback_t call_p, json_stream_e_callback_t call_e=NULL, void *callbackIdentifier=JSONSTREAM_SELF) json_nothrow
Definition: JSONStream.cpp:9

Here is the call graph for this function:

static JSONStream* JSONStream::newJSONStream ( json_stream_callback_t  callback,
json_stream_e_callback_t  call_e,
void *  callbackIdentifier 
)
inlinestatic

References JSONStream().

45  {
46 #ifdef JSON_MEMORY_CALLBACKS
47  return new(json_malloc<JSONStream>(1)) JSONStream(callback, call_e, callbackIdentifier);
48 #else
49  return new JSONStream(callback, call_e, callbackIdentifier);
50 #endif
51  }
JSONStream(json_stream_callback_t call_p, json_stream_e_callback_t call_e=NULL, void *callbackIdentifier=JSONSTREAM_SELF) json_nothrow
Definition: JSONStream.cpp:9

Here is the call graph for this function:

JSONStream& JSONStream::operator<< ( const json_string &  str)
JSONStream & JSONStream::operator<< ( const json_string &  str)

References libjson::parse().

25  {
26 #endif
27  if (state){
28  buffer += str;
29  parse();
30  }
31  return *this;
32 }
void parse(void) json_nothrow
Definition: JSONStream.cpp:87
json_string buffer
Definition: JSONStream.h:73

Here is the call graph for this function:

JSONStream & JSONStream::operator= ( const JSONStream orig)
13  {
14  err_call = orig.err_call;
15  call = orig.call;
16  state = orig.state;
17  buffer = orig.buffer;
19  return *this;
20 }
void * callback_identifier
Definition: JSONStream.h:76
json_stream_e_callback_t err_call
Definition: JSONStream.h:75
json_stream_callback_t call
Definition: JSONStream.h:74
json_string buffer
Definition: JSONStream.h:73
JSONStream& JSONStream::operator= ( const JSONStream orig)
void JSONStream::parse ( void  )

References buffer, call, END_MEM_SCOPE, err_call, getIdentifier(), JSONValidator::isValidPartialRoot(), json_char, JSON_FAIL, json_likely, JSON_SECURITY_MAX_STREAM_OBJECTS, JSON_TEXT, libjson::parse(), json_auto< T >::ptr, JSONWorker::RemoveWhiteSpace, json_auto< T >::set(), START_MEM_SCOPE, and STREAM_FIND_NEXT_RELEVANT.

87  {
88  #ifdef JSON_SECURITY_MAX_STREAM_OBJECTS
89  size_t objects = 0;
90  #endif
91  for(;;){
92  size_t pos = buffer.find_first_of(JSON_TEXT("{["));
93  if (json_likely(pos != json_string::npos)){
94  size_t end = (buffer[pos] == JSON_TEXT('[')) ? STREAM_FIND_NEXT_RELEVANT(JSON_TEXT(']'), buffer, pos + 1) : STREAM_FIND_NEXT_RELEVANT(JSON_TEXT('}'), buffer, pos + 1);
95  if (end != json_string::npos){
96  #ifdef JSON_SECURITY_MAX_STREAM_OBJECTS
97  if (++objects > JSON_SECURITY_MAX_STREAM_OBJECTS){
98  JSON_FAIL(JSON_TEXT("Maximum number of json objects for a stream at once has been reached"));
100  state = false;
101  return;
102  }
103  #endif
105  JSONNode temp(JSONWorker::parse(buffer.substr(pos, end - pos + 1)));
106  #ifndef JSON_LIBRARY
107  call(temp, getIdentifier());
108  #else
109  call(&temp, getIdentifier());
110  #endif
112  json_string::iterator beginning = buffer.begin();
113  buffer.erase(beginning, beginning + end);
114  continue; //parse(); //parse the next object too
115  }
116  #ifdef JSON_SAFE
117  else {
118  //verify that what's in there is at least valid so far
119  #ifndef JSON_VALIDATE
120  #error In order to use safe mode and streams, JSON_VALIDATE needs to be defined
121  #endif
122 
124  #if defined JSON_DEBUG || defined JSON_SAFE
125  json_char c;
126  s.set(JSONWorker::RemoveWhiteSpace(json_string(buffer.c_str() + pos), c, false));
127  #else
128  s.set(JSONWorker::RemoveWhiteSpace(json_string(buffer.c_str() + pos), false));
129  #endif
130 
131 
134  state = false;
135  }
136  }
137  #endif
138  }
139  break;
140  }
141 }
#define JSON_TEXT(s)
Definition: Strings_Defs.h:30
#define JSON_SECURITY_MAX_STREAM_OBJECTS
Definition: JSONOptions.h:353
static JSONNode static parse(const json_string &json) json_throws(std JSONNode static parse_unformatted(const json_string &json) json_throws(std JSONNode static _parse_unformatted(const json_char *json) json_throws(std json_char RemoveWhiteSpace)(const json_string &value_t, bool escapeQuotes) json_nothrow json_read_priority
Definition: JSONWorker.h:24
#define END_MEM_SCOPE
Definition: JSONDefs.h:89
static bool isValidPartialRoot(const json_char *json) json_nothrow json_read_priority
Definition: JSONValidator.cpp:390
Definition: JSONMemory.h:129
void set(T *p) json_nothrow
Definition: JSONMemory.h:137
#define START_MEM_SCOPE
Definition: JSONDefs.h:88
Definition: JSONNode.h:132
#define json_char
Definition: Strings_Defs.h:21
T * ptr
Definition: JSONMemory.h:140
json_stream_e_callback_t err_call
Definition: JSONStream.h:75
#define STREAM_FIND_NEXT_RELEVANT(ch, vt, po)
Definition: JSONStream.cpp:68
json_stream_callback_t call
Definition: JSONStream.h:74
json_string buffer
Definition: JSONStream.h:73
#define json_likely(x)
Definition: Unknown_C.h:16
static JSONNode parse(const json_string &json) json_throws(std
Definition: libjson.h:242
JSON_PRIVATE void * getIdentifier(void) json_nothrow
Definition: JSONStream.h:58
#define JSON_FAIL(msg)
Definition: JSONDebug.h:54

Here is the call graph for this function:

void JSONStream::parse ( void  )
void JSONStream::reset ( )
inline

References buffer.

53  {
54  state = true;
55  buffer.clear();
56  }
json_string buffer
Definition: JSONStream.h:73
void JSONStream::reset ( )
inline

References buffer.

53  {
54  state = true;
55  buffer.clear();
56  }
json_string buffer
Definition: JSONStream.h:73

Member Data Documentation

json_string JSONStream::buffer

Referenced by parse(), and reset().

json_stream_callback_t JSONStream::call

Referenced by parse().

void * JSONStream::callback_identifier

Referenced by getIdentifier().

json_stream_e_callback_t JSONStream::err_call

Referenced by parse().


The documentation for this class was generated from the following files: