BLOG | DOCUMENTATION | TRAC

Home --> Documentations --> PJSIP Reference

pj::PersistentDocument Class Referenceabstract

#include <persistent.hpp>

Inheritance diagram for pj::PersistentDocument:
pj::JsonDocument

Public Member Functions

virtual ~PersistentDocument ()
 
virtual void loadFile (const string &filename) PJSUA2_THROW(Error)=0
 
virtual void loadString (const string &input) PJSUA2_THROW(Error)=0
 
virtual void saveFile (const string &filename) PJSUA2_THROW(Error)=0
 
virtual string saveString () PJSUA2_THROW(Error)=0
 
virtual ContainerNodegetRootContainer () const =0
 
bool hasUnread () const
 
string unreadName () const PJSUA2_THROW(Error)
 
int readInt (const string &name="") const PJSUA2_THROW(Error)
 
float readNumber (const string &name="") const PJSUA2_THROW(Error)
 
bool readBool (const string &name="") const PJSUA2_THROW(Error)
 
string readString (const string &name="") const PJSUA2_THROW(Error)
 
StringVector readStringVector (const string &name="") const PJSUA2_THROW(Error)
 
void readObject (PersistentObject &obj) const PJSUA2_THROW(Error)
 
ContainerNode readContainer (const string &name="") const PJSUA2_THROW(Error)
 
ContainerNode readArray (const string &name="") const PJSUA2_THROW(Error)
 
void writeNumber (const string &name, float num) PJSUA2_THROW(Error)
 
void writeInt (const string &name, int num) PJSUA2_THROW(Error)
 
void writeBool (const string &name, bool value) PJSUA2_THROW(Error)
 
void writeString (const string &name, const string &value) PJSUA2_THROW(Error)
 
void writeStringVector (const string &name, const StringVector &arr) PJSUA2_THROW(Error)
 
void writeObject (const PersistentObject &obj) PJSUA2_THROW(Error)
 
ContainerNode writeNewContainer (const string &name) PJSUA2_THROW(Error)
 
ContainerNode writeNewArray (const string &name) PJSUA2_THROW(Error)
 

Detailed Description

This a the abstract base class for a persistent document. A document is created either by loading from a string or a file, or by constructing it manually when writing data to it. The document then can be saved to either string or to a file. A document contains one root ContainerNode where all data are stored under.

Document is read and written serially, hence the order of reading must be the same as the order of writing. The PersistentDocument class provides API to read and write to the root node, but for more flexible operations application can use the ContainerNode methods instead. Indeed the read and write API in PersistentDocument is just a shorthand which calls the relevant methods in the ContainerNode. As a tip, normally application only uses the readObject() and writeObject() methods declared here to read/write top level objects, and use the macros that are explained in ContainerNode documentation to read/write more detailed data.

Constructor & Destructor Documentation

◆ ~PersistentDocument()

virtual pj::PersistentDocument::~PersistentDocument ( )
inlinevirtual

Virtual destructor

Member Function Documentation

◆ loadFile()

virtual void pj::PersistentDocument::loadFile ( const string &  filename)
pure virtual

Load this document from a file.

Parameters
filenameThe file name.

Implemented in pj::JsonDocument.

◆ loadString()

virtual void pj::PersistentDocument::loadString ( const string &  input)
pure virtual

Load this document from string.

Parameters
inputThe string.

Implemented in pj::JsonDocument.

◆ saveFile()

virtual void pj::PersistentDocument::saveFile ( const string &  filename)
pure virtual

Write this document to a file.

Parameters
filenameThe file name.

Implemented in pj::JsonDocument.

◆ saveString()

virtual string pj::PersistentDocument::saveString ( )
pure virtual

Write this document to string.

Returns
The string document.

Implemented in pj::JsonDocument.

◆ getRootContainer()

virtual ContainerNode& pj::PersistentDocument::getRootContainer ( ) const
pure virtual

Get the root container node for this document

Returns
The root node.

Implemented in pj::JsonDocument.

◆ hasUnread()

bool pj::PersistentDocument::hasUnread ( ) const

Determine if there is unread element. If yes, then app can use one of the readXxx() functions to read it.

Returns
True if there is.

◆ unreadName()

string pj::PersistentDocument::unreadName ( ) const

Get the name of the next unread element. It will throw Error if there is no more element to read.

Returns
The name of the next element .

◆ readInt()

int pj::PersistentDocument::readInt ( const string &  name = "") const

Read an integer value from the document and return the value. This will throw Error if the current element is not a number. The read position will be advanced to the next element.

Parameters
nameIf specified, then the function will check if the name of the next element matches the specified name and throw Error if it doesn't match.
Returns
The value.

◆ readNumber()

float pj::PersistentDocument::readNumber ( const string &  name = "") const

Read a float value from the document and return the value. This will throw Error if the current element is not a number. The read position will be advanced to the next element.

Parameters
nameIf specified, then the function will check if the name of the next element matches the specified name and throw Error if it doesn't match.
Returns
The value.

◆ readBool()

bool pj::PersistentDocument::readBool ( const string &  name = "") const

Read a boolean value from the container and return the value. This will throw Error if the current element is not a boolean. The read position will be advanced to the next element.

Parameters
nameIf specified, then the function will check if the name of the next element matches the specified name and throw Error if it doesn't match.
Returns
The value.

◆ readString()

string pj::PersistentDocument::readString ( const string &  name = "") const

Read a string value from the container and return the value. This will throw Error if the current element is not a string. The read position will be advanced to the next element.

Parameters
nameIf specified, then the function will check if the name of the next element matches the specified name and throw Error if it doesn't match.
Returns
The value.

◆ readStringVector()

StringVector pj::PersistentDocument::readStringVector ( const string &  name = "") const

Read a string array from the container. This will throw Error if the current element is not a string array. The read position will be advanced to the next element.

Parameters
nameIf specified, then the function will check if the name of the next element matches the specified name and throw Error if it doesn't match.
Returns
The value.

◆ readObject()

void pj::PersistentDocument::readObject ( PersistentObject obj) const

Read the specified object from the container. This is equal to calling PersistentObject.readObject(ContainerNode);

Parameters
objThe object to read.

◆ readContainer()

ContainerNode pj::PersistentDocument::readContainer ( const string &  name = "") const

Read a container from the container. This will throw Error if the current element is not an object. The read position will be advanced to the next element.

Parameters
nameIf specified, then the function will check if the name of the next element matches the specified name and throw Error if it doesn't match.
Returns
Container object.

◆ readArray()

ContainerNode pj::PersistentDocument::readArray ( const string &  name = "") const

Read array container from the container. This will throw Error if the current element is not an array. The read position will be advanced to the next element.

Parameters
nameIf specified, then the function will check if the name of the next element matches the specified name and throw Error if it doesn't match.
Returns
Container object.

◆ writeNumber()

void pj::PersistentDocument::writeNumber ( const string &  name,
float  num 
)

Write a number value to the container.

Parameters
nameThe name for the value in the container.
numThe value to be written.

◆ writeInt()

void pj::PersistentDocument::writeInt ( const string &  name,
int  num 
)

Write a number value to the container.

Parameters
nameThe name for the value in the container.
numThe value to be written.

◆ writeBool()

void pj::PersistentDocument::writeBool ( const string &  name,
bool  value 
)

Write a boolean value to the container.

Parameters
nameThe name for the value in the container.
valueThe value to be written.

◆ writeString()

void pj::PersistentDocument::writeString ( const string &  name,
const string &  value 
)

Write a string value to the container.

Parameters
nameThe name for the value in the container.
valueThe value to be written.

◆ writeStringVector()

void pj::PersistentDocument::writeStringVector ( const string &  name,
const StringVector arr 
)

Write string vector to the container.

Parameters
nameThe name for the value in the container.
arrThe vector to be written.

◆ writeObject()

void pj::PersistentDocument::writeObject ( const PersistentObject obj)

Write an object to the container. This is equal to calling PersistentObject.writeObject(ContainerNode);

Parameters
objThe object to be written

◆ writeNewContainer()

ContainerNode pj::PersistentDocument::writeNewContainer ( const string &  name)

Create and write an empty Object node that can be used as parent for subsequent write operations.

Parameters
nameThe name for the new container in the container.
Returns
A sub-container.

◆ writeNewArray()

ContainerNode pj::PersistentDocument::writeNewArray ( const string &  name)

Create and write an empty array node that can be used as parent for subsequent write operations.

Parameters
nameThe name for the array.
Returns
A sub-container.

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

 


PJSIP Open Source, high performance, small footprint, and very very portable SIP stack
Copyright (C) 2006-2008 Teluu Inc.