KFoundation
v2.1
A Better Foundation Library for C++
|
Provides APIs to serialize an object. More...
#include <kfoundation/ObjectSerializer.h>
Public Member Functions | |
ObjectSerializer (Ref< OutputStream > stream, kf_int8_t indentUnit=4) | |
Constructor, sets output stream, type, and indent units. More... | |
Ref< ObjectSerializer > | member (RefConst< UString > name) |
Used to output an object owned by the current one. More... | |
Ref< ObjectSerializer > | object (RefConst< UString > className) |
Used to output an object. More... | |
Ref< ObjectSerializer > | attribute (RefConst< UString > name, const wchar_t value) |
Serializes a char attribute. | |
Ref< ObjectSerializer > | attribute (RefConst< UString > name, const kf_int32_t value) |
Serializes an int attribute. | |
Ref< ObjectSerializer > | attribute (RefConst< UString > name, const kf_int64_t value) |
Serializes an unsigned int attribute. | |
Ref< ObjectSerializer > | attribute (RefConst< UString > name, const double value) |
Serializes a double attribuet. | |
Ref< ObjectSerializer > | attribute (RefConst< UString > name, const bool value) |
Serializes a bool attribute. | |
Ref< ObjectSerializer > | attribute (RefConst< UString > name) |
Serializes an attribute with no value. | |
Ref< ObjectSerializer > | null () |
Used to print a field that is NULL . More... | |
Ref< ObjectSerializer > | endObject () |
Marks the end of an object started by the latest call of object() method. More... | |
Ref< ObjectSerializer > | collection () |
Used to print a collection. More... | |
Ref< ObjectSerializer > | endCollection () |
Marks end of a collection started by the latest unclosed call to collection(). More... | |
![]() | |
bool | equals (RefConst< KFObject > other) const |
Checks if this object is the same as the one reffered by the given refrence. | |
Provides APIs to serialize an object.
This is usually used in conjuction with SerializingStreamer.
Supported output formats are KFOR (KFoundation Format), XML, and JSON. To use, the methods shoud be called in particular order. If the order is not observed, an expcetion will be thrown.
An expception is when using object(const SerializingStreamer&) or object(const Ref<T>) it is not needed to call endObject() because it is already called in the serializer() method of the given argument.
All of these methods can be used chained sytax. Example:
void serialize(Ref<ObjectSerializer> os) const { os->object("MyClass") ->attribute("counter", _counter) ->attribute("name", _name) ->member("innerObject")->object(innerObject) ->endObject();
kfoundation::ObjectSerializer::ObjectSerializer | ( | Ref< OutputStream > | stream, |
kf_int8_t | indentUnit = 4 |
||
) |
Constructor, sets output stream, type, and indent units.
stream | The stream to print the output to. |
outputType | The output format. |
indentUnit | Number of spaces for each indention level. |
Ref< ObjectSerializer > kfoundation::ObjectSerializer::collection | ( | ) |
Ref< ObjectSerializer > kfoundation::ObjectSerializer::endCollection | ( | ) |
Marks end of a collection started by the latest unclosed call to collection().
Ref< ObjectSerializer > kfoundation::ObjectSerializer::endObject | ( | ) |
Marks the end of an object started by the latest call of object() method.
Ref< ObjectSerializer > kfoundation::ObjectSerializer::member | ( | RefConst< UString > | name) |
Used to output an object owned by the current one.
Only allowed after object() and attribute().
name | The corresponding member variable name (property name). |
Ref< ObjectSerializer > kfoundation::ObjectSerializer::null | ( | ) |
Used to print a field that is NULL
.
Only allowed after member().
Ref< ObjectSerializer > kfoundation::ObjectSerializer::object | ( | RefConst< UString > | className) |
Used to output an object.
Allowed in the begining or after member().
className | Class name of the designated object. |