StelJsonParser.hpp   StelJsonParser.hpp 
skipping to change at line 26 skipping to change at line 26
* Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA. * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA.
*/ */
#ifndef _STELJSONPARSER_HPP_ #ifndef _STELJSONPARSER_HPP_
#define _STELJSONPARSER_HPP_ #define _STELJSONPARSER_HPP_
#include <QIODevice> #include <QIODevice>
#include <QVariant> #include <QVariant>
#include <QByteArray> #include <QByteArray>
//! Qt-style iterator over a JSON array. An actual list is not kept in memo
ry,
//! so only forward iteration is supported and all methods, including the c
onstructor,
//! involve read() calls on the QIODevice. Because of this, do not modify t
he
//! QIODevice between calls to JsonListIterator methods. Also, the toFront(
)
//! method has a special function and reset() is provided for convenience.
Only
//! peekNext() is guaranteed not to modify the QIODevice.
class JsonListIterator
{
public:
//! Sets up JsonListIterator to read an array. Swallows all whitespa
ce
//! up to a beginning '[' character. If '[' is not the first non-whi
tespace
//! character encountered, reset() is called and an exception is thr
own.
JsonListIterator(QIODevice* input);
~JsonListIterator();
//! Reads and parses the next object from input. Advances QIODevice
to
//! just after the object.
//! @return the next object from the array
QVariant next();
//! Returns true if the next non-whitespace character is not a ']' c
haracter.
bool hasNext() const {return ahasNext;}
private:
bool ahasNext;
class StelJsonParserInstance* parser;
};
//! @class StelJsonParser //! @class StelJsonParser
//! Qt-based simple JSON reader inspired by the one from <a href='http://zo olib.sourceforge.net/'>Zoolib</a>. //! Qt-based simple JSON reader inspired by the one from <a href='http://zo olib.sourceforge.net/'>Zoolib</a>.
//! JSON is JavaScript Object Notation. See http://www.json.org/ //! JSON is JavaScript Object Notation. See http://www.json.org/
/*! <p>The mapping with Qt types is done as following: /*! <p>The mapping with Qt types is done as following:
@verbatim @verbatim
JSON Qt JSON Qt
---- ------- ---- -------
null QVariant::Invalid null QVariant::Invalid
object QVariantMap (QVariant::Map) object QVariantMap (QVariant::Map)
array QVariantList (QVariant::List) array QVariantList (QVariant::List)
boolean QVariant::Bool boolean QVariant::Bool
string QVariant::String string QVariant::String
number QVariant::Int or QVariant::Double number QVariant::Int or QVariant::Double
@endverbatim */ @endverbatim */
class StelJsonParser class StelJsonParser
{ {
public: public:
//! Create a JsonListIterator from the given input device.
static JsonListIterator initListIterator(QIODevice* in) {return Json
ListIterator(in);}
//! Parse the given input stream. //! Parse the given input stream.
static QVariant parse(QIODevice* input); static QVariant parse(QIODevice* input);
static QVariant parse(const QByteArray& input); static QVariant parse(const QByteArray& input);
//! Serialize the passed QVariant as JSON into the output QIODevice. //! Serialize the passed QVariant as JSON into the output QIODevice.
static void write(const QVariant& jsonObject, QIODevice* output, int indentLevel=0); static void write(const QVariant& jsonObject, QIODevice* output, int indentLevel=0);
//! Serialize the passed QVariant as JSON in a QByteArray. //! Serialize the passed QVariant as JSON in a QByteArray.
static QByteArray write(const QVariant& jsonObject, int indentLevel= 0); static QByteArray write(const QVariant& jsonObject, int indentLevel= 0);
static void registerSerializerForType(int t, void (*func)(const QVar // static void registerSerializerForType(int t, void (*func)(const Q
iant&, QIODevice*, int)) {otherSerializer.insert(t, func);} Variant&, QIODevice*, int)) {otherSerializer.insert(t, func);}
private:
static QHash<int, void (*)(const QVariant&, QIODevice*, int)> otherS
erializer;
}; };
#endif // _STELJSONPARSER_HPP_ #endif // _STELJSONPARSER_HPP_
 End of changes. 3 change blocks. 
48 lines changed or deleted 2 lines changed or added

This html diff was produced by rfcdiff 1.41. The latest version is available from http://tools.ietf.org/tools/rfcdiff/