Serializes or deserializes C++ objects.
More...
|
template<class T > |
bool | read (T &object, JKString &filename) |
| Reads a C++ object (and all objects pointed by its serialized members) from a JSON file. More...
|
|
template<class T > |
bool | read (T &object, std::istream &in, JKString &name="", size_t linenbr=1) |
| Reads a C++ object (and all objects pointed by its serialized members) from an input stream. More...
|
|
template<class T > |
bool | write (const T &object, JKString &filename, bool cyclic_graph) |
| Reads a C++ object (and all objects pointed by its serialized members) to a JSON file. More...
|
|
template<class T > |
bool | write (const T &object, std::ostream &out, bool cyclic_graph, JKString &name="", size_t linenbr=1) |
| Reads a C++ object (and all objects pointed by its serialized members) on an output stream. More...
|
|
template<class T > |
void | readMember (T &variable, JKString &str) |
| Reads a class member.
|
|
template<class T > |
void | writeMember (const T &variable) |
| Writes a class member.
|
|
|
| JSonSerial (JSonClasses const &classes, JSonError::Handler handler={}) |
| Constructor. More...
|
|
|
void | setSyntax (unsigned int mode) |
| Parsing options. More...
|
|
|
void | setIndent (char tabchar, unsigned int tabcount) |
| Indentation. More...
|
|
Serializes or deserializes C++ objects.
JSON syntax.
- Strict: strict JSON syntax
- Relaxed: all options are allowed
- Comments: allows C++ style comments
- NoQuotes: allows unquoted strings
- NoCommas: name/value pairs can be sparated by a newline
- Newlines: strings can contain newlines and any ::isspace() character
Constructor.
- classes : the user-defined classes and members that should be serialized.
- handler : allows writing errors in a specific way instead of printing them on std::cerr
- See Also
- JSonClasses, JSonError.
template<class T >
bool jsonserial::JSonSerial::read |
( |
T & |
object, |
|
|
JKString & |
filename |
|
) |
| |
|
inline |
Reads a C++ object (and all objects pointed by its serialized members) from a JSON file.
- object : the object that is serialized (can be a plain object, a raw or smart pointer, or a container)
- filename : the path name of the corresponding JSON file
- returns false and prints a message in case of an error (see constructor)
- Note
- This function supports JSON files containing cyclic graphs and shared objects, see write().
template<class T >
bool jsonserial::JSonSerial::read |
( |
T & |
object, |
|
|
std::istream & |
in, |
|
|
JKString & |
name = "" , |
|
|
size_t |
linenbr = 1 |
|
) |
| |
|
inline |
Reads a C++ object (and all objects pointed by its serialized members) from an input stream.
Works as read(T& object, JKString& filename) except that in is the input stream. In addition name and firstline are used when displaying errors: name is a file name or whatever, linenbr the number of the current line on this stream or file.
template<class T >
bool jsonserial::JSonSerial::write |
( |
const T & |
object, |
|
|
JKString & |
filename, |
|
|
bool |
cyclic_graph |
|
) |
| |
|
inline |
Reads a C++ object (and all objects pointed by its serialized members) to a JSON file.
- object : the object that is serialized (can be a plain object, a raw or smart pointer, or a container)
- filename : the path name of the corresponding JSON file
- cyclic_graph specifies whether cyclic graphs are allowed. This option also avoids duplicating shared objects (objects pointed by multiple pointers). An @id field is then added to all user-defined objects in the JSON file.
- returns false and prints a message in case of an error (see constructor)
- Warning
- : this function will enter an infinite loop if cyclic_graph is false but the objects' graph is cyclic!
template<class T >
bool jsonserial::JSonSerial::write |
( |
const T & |
object, |
|
|
std::ostream & |
out, |
|
|
bool |
cyclic_graph, |
|
|
JKString & |
name = "" , |
|
|
size_t |
linenbr = 1 |
|
) |
| |
|
inline |
Reads a C++ object (and all objects pointed by its serialized members) on an output stream.
Works as write(const T& object, JKString& filename) except that out is the output stream. In addition name and firstline are used when displaying errors: name is a file name or whatever, linenbr the number of the current line on this stream or file.
void jsonserial::JSonSerial::setSyntax |
( |
unsigned int |
mode) | |
|
|
inline |
Parsing options.
mode can be an ORred mask of the JSyntax enum constants. C++-like comments are allowed by default (contrary to standard JSON syntax)
void jsonserial::JSonSerial::setIndent |
( |
char |
tabchar, |
|
|
unsigned int |
tabcount |
|
) |
| |
|
inline |
Indentation.
tabchar: tabulation character, tabcount: how many times it is repeated.
The documentation for this class was generated from the following file: