KFoundation  v2.1
A Better Foundation Library for C++
 All Classes Functions Variables Typedefs Enumerations Enumerator Groups Pages
Public Member Functions | List of all members
kfoundation::ObjectSerializer Class Referenceabstract

Provides APIs to serialize an object. More...

#include <kfoundation/ObjectSerializer.h>

Inheritance diagram for kfoundation::ObjectSerializer:
Inheritance graph
[legend]

Public Member Functions

 ObjectSerializer (Ref< OutputStream > stream, kf_int8_t indentUnit=4)
 Constructor, sets output stream, type, and indent units. More...
 
Ref< ObjectSerializermember (RefConst< UString > name)
 Used to output an object owned by the current one. More...
 
Ref< ObjectSerializerobject (RefConst< UString > className)
 Used to output an object. More...
 
Ref< ObjectSerializerattribute (RefConst< UString > name, const wchar_t value)
 Serializes a char attribute.
 
Ref< ObjectSerializerattribute (RefConst< UString > name, const kf_int32_t value)
 Serializes an int attribute.
 
Ref< ObjectSerializerattribute (RefConst< UString > name, const kf_int64_t value)
 Serializes an unsigned int attribute.
 
Ref< ObjectSerializerattribute (RefConst< UString > name, const double value)
 Serializes a double attribuet.
 
Ref< ObjectSerializerattribute (RefConst< UString > name, const bool value)
 Serializes a bool attribute.
 
Ref< ObjectSerializerattribute (RefConst< UString > name)
 Serializes an attribute with no value.
 
Ref< ObjectSerializernull ()
 Used to print a field that is NULL. More...
 
Ref< ObjectSerializerendObject ()
 Marks the end of an object started by the latest call of object() method. More...
 
Ref< ObjectSerializercollection ()
 Used to print a collection. More...
 
Ref< ObjectSerializerendCollection ()
 Marks end of a collection started by the latest unclosed call to collection(). More...
 
- Public Member Functions inherited from kfoundation::KFObject
bool equals (RefConst< KFObject > other) const
 Checks if this object is the same as the one reffered by the given refrence.
 

Detailed Description

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();

Constructor & Destructor Documentation

kfoundation::ObjectSerializer::ObjectSerializer ( Ref< OutputStream stream,
kf_int8_t  indentUnit = 4 
)

Constructor, sets output stream, type, and indent units.

Parameters
streamThe stream to print the output to.
outputTypeThe output format.
indentUnitNumber of spaces for each indention level.

Member Function Documentation

Ref< ObjectSerializer > kfoundation::ObjectSerializer::collection ( )

Used to print a collection.

Allowed only after member().

Returns
Pointer to self.
Ref< ObjectSerializer > kfoundation::ObjectSerializer::endCollection ( )

Marks end of a collection started by the latest unclosed call to collection().

Returns
Pointer to self.
Ref< ObjectSerializer > kfoundation::ObjectSerializer::endObject ( )

Marks the end of an object started by the latest call of object() method.

Returns
Pointer to self.
Ref< ObjectSerializer > kfoundation::ObjectSerializer::member ( RefConst< UString >  name)

Used to output an object owned by the current one.

Only allowed after object() and attribute().

Parameters
nameThe corresponding member variable name (property name).
Returns
Pointer to self.
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().

Parameters
classNameClass name of the designated object.
Returns
Pointer to self.

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