BLOG | DOCUMENTATION | GITHUB

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)=0 throw (Error)
 
virtual void loadString (const string &input)=0 throw (Error)
 
virtual void saveFile (const string &filename)=0 throw (Error)
 
virtual string saveString ()=0 throw (Error)
 
virtual ContainerNodegetRootContainer () const =0
 
bool hasUnread () const
 
string unreadName () const throw (Error)
 
int readInt (const string &name="") const throw (Error)
 
float readNumber (const string &name="") const throw (Error)
 
bool readBool (const string &name="") const throw (Error)
 
string readString (const string &name="") const throw (Error)
 
StringVector readStringVector (const string &name="") const throw (Error)
 
void readObject (PersistentObject &obj) const throw (Error)
 
ContainerNode readContainer (const string &name="") const throw (Error)
 
ContainerNode readArray (const string &name="") const throw (Error)
 
void writeNumber (const string &name, float num) throw (Error)
 
void writeInt (const string &name, int num) throw (Error)
 
void writeBool (const string &name, bool value) throw (Error)
 
void writeString (const string &name, const string &value) throw (Error)
 
void writeStringVector (const string &name, const StringVector &arr) throw (Error)
 
void writeObject (const PersistentObject &obj) throw (Error)
 
ContainerNode writeNewContainer (const string &name) throw (Error)
 
ContainerNode writeNewArray (const string &name) 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)
throw (Error
)
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)
throw (Error
)
pure virtual

Load this document from string.

Parameters
inputThe string.

Implemented in pj::JsonDocument.

◆ saveFile()

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

Write this document to a file.

Parameters
filenameThe file name.

Implemented in pj::JsonDocument.

◆ saveString()

virtual string pj::PersistentDocument::saveString ( )
throw (Error
)
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
throw (Error
)

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
throw (Error
)

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
throw (Error
)

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
throw (Error
)

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
throw (Error
)

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
throw (Error
)

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
throw (Error
)

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
throw (Error
)

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
throw (Error
)

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 
)
throw (Error
)

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 
)
throw (Error
)

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 
)
throw (Error
)

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 
)
throw (Error
)

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 
)
throw (Error
)

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)
throw (Error
)

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)
throw (Error
)

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)
throw (Error
)

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.