GFXprim
2D bitmap graphics library with emphasis on speed and correctness
|
A JSON writer. More...
#include <utils/gp_json_common.h>
Go to the source code of this file.
Data Structures | |
struct | gp_json_writer |
A JSON writer. More... | |
Functions | |
gp_json_writer * | gp_json_writer_vec_new (void) |
Allocates a JSON writer with a vector as a storage. | |
void | gp_json_writer_vec_free (gp_json_writer *self) |
Frees a JSON writer with a vector as a storage. | |
static char * | gp_json_writer_vec (gp_json_writer *self) |
Returns a pointer to a vector storage. | |
static int | gp_json_writer_err (gp_json_writer *self) |
Returns true if writer error happened. | |
int | gp_json_obj_start (gp_json_writer *self, const char *id) |
Starts an JSON object. | |
int | gp_json_obj_finish (gp_json_writer *self) |
Finishes a JSON object. | |
int | gp_json_arr_start (gp_json_writer *self, const char *id) |
Starts an json array. | |
int | gp_json_arr_finish (gp_json_writer *self) |
Finishes a JSON array. | |
int | gp_json_null_add (gp_json_writer *self, const char *id) |
Adds a null value. | |
int | gp_json_int_add (gp_json_writer *self, const char *id, long val) |
Adds an integer value. | |
int | gp_json_bool_add (gp_json_writer *self, const char *id, int val) |
Adds a bool value. | |
int | gp_json_float_add (gp_json_writer *self, const char *id, double val) |
Adds a float value. | |
int | gp_json_str_add (gp_json_writer *self, const char *id, const char *str) |
Adds a string value. | |
int | gp_json_finish (gp_json_writer *self) |
Finalizes json writer. | |
A JSON writer.
All the function that add values return 0 on success and non-zero on a failure. Once an error has happened all subsequent attempts to add more values return with non-zero exit status immediatelly. This is designed so that we can add several values without checking each return value and only check if error has happened at the end of the sequence.
Failures may occur:
Definition in file gp_json_writer.h.
int gp_json_arr_finish | ( | gp_json_writer * | self | ) |
Finishes a JSON array.
self | A JSON writer. |
int gp_json_arr_start | ( | gp_json_writer * | self, |
const char * | id | ||
) |
Starts an json array.
self | A JSON writer. |
id | An array name. |
int gp_json_bool_add | ( | gp_json_writer * | self, |
const char * | id, | ||
int | val | ||
) |
Adds a bool value.
self | A JSON writer. |
id | An boolean value name. |
int gp_json_finish | ( | gp_json_writer * | self | ) |
Finalizes json writer.
Finalizes the json writer, throws possible errors through the error printing function.
self | A JSON writer. |
int gp_json_float_add | ( | gp_json_writer * | self, |
const char * | id, | ||
double | val | ||
) |
Adds a float value.
self | A JSON writer. |
id | A floating point value name. |
int gp_json_int_add | ( | gp_json_writer * | self, |
const char * | id, | ||
long | val | ||
) |
Adds an integer value.
self | A JSON writer. |
id | An integer value name. |
int gp_json_null_add | ( | gp_json_writer * | self, |
const char * | id | ||
) |
Adds a null value.
self | A JSON writer. |
id | A null value name. |
int gp_json_obj_finish | ( | gp_json_writer * | self | ) |
Finishes a JSON object.
self | A JSON writer. |
int gp_json_obj_start | ( | gp_json_writer * | self, |
const char * | id | ||
) |
Starts an JSON object.
self | A JSON writer. |
id | An object name. |
int gp_json_str_add | ( | gp_json_writer * | self, |
const char * | id, | ||
const char * | str | ||
) |
Adds a string value.
self | A JSON writer. |
id | A string value name. |
|
inlinestatic |
Returns true if writer error happened.
Definition at line 81 of file gp_json_writer.h.
|
inlinestatic |
Returns a pointer to a vector storage.
Definition at line 71 of file gp_json_writer.h.
void gp_json_writer_vec_free | ( | gp_json_writer * | self | ) |
Frees a JSON writer with a vector as a storage.
self | A gp_json_writer with vector as a storage. |
gp_json_writer * gp_json_writer_vec_new | ( | void | ) |
Allocates a JSON writer with a vector as a storage.