GluonCore::GDLHandler Class Reference

Functionality for serializing and deserializing GluonObjects. More...

#include <gdlhandler.h>

Inheritance diagram for GluonCore::GDLHandler:
GluonCore::Singleton< GDLHandler > QObject

List of all members.

Public Member Functions

QList< GluonObject * > parseGDL (const QString parseThis, QObject *parent)
QString serializeGDL (QList< const GluonObject * > serializeThis)

Friends

class Singleton< GDLHandler >

Detailed Description

Functionality for serializing and deserializing GluonObjects.

This singleton class provides functionality for serializing and deserializing GluonObject instances to and from the GDL object definition language.

A generalized use scenario for GDLHandler is loading a gdl file from disk and deserializing it into GluonObject instances, do a change to some object in the hierarchy and then save it back into a file. The following function will do that:

    bool fiddleWithObjects(QString filename)
    {
    QFile projectFile(QFileInfo(filename().toLocalFile()).fileName());
    if (!projectFile.open(QIODevice::ReadWrite))
        return false;

    QTextStream projectReader(&projectFile);
    QString fileContents = projectReader.readAll();

    if (fileContents.isEmpty())
        return false;

    QList<GluonObject*> objectList = GluonCore::GDLHandler::instance()->parseGDL(fileContents, this->parent());

    foreach(GluonObject* obj, objectList)
    {
        obj->setName(QString("%1 %2").arg(obj->name()).arg("changed"));
    }

    QString serializedData = GluonCore::GDLHandler::instance()->serializeGDL();
    QTextStream out(&projectFile);
    out << serializedData;
    projectFile.close();

    return true;
    }

The Gluon Definition Language

The Gluon Definition Language, or GDL, is a very simple, hierarchical object definition language, designed for use with GluonObject derived classes. The structure of the language can easiest be described as follows:

    { ClassName(ObjectName)
    PropertyName DataTypeName(Value)
    PropertyName2 DataTypeName2(Value2)
    { ClassName(ObjectName)
        PropertyName DataTypeName(Value)
    }
    }
    

The above sample represents two nested objects of the type ClassName, both named ObjectName. The fully qualified name for the objects respectively are ObjectName and ObjectName.ObjectName and this can be used in properties as well.

PropertyName and PropertyName2 are as the names indicate properties named that way. Their values are Value and Value2 respectively, and the data type contained in the properties are DataTypeName and DataTypeName2 respectively.

An important aspect of GDL is the ability for any property to reference any other object in the hierarchy. An example of this might be:

    { GluonObject(AnotherObject)
    reference GluonObject(AnObject.AChildObject)
    }
    { GluonObject(AnObject)
    { GluonObject(AChildObject)
    }
    }
    

The property reference on the AnotherObject object is then a reference to the object with the fully qualified name AnObject.AChildObject. Also shown here is the fact that an object does not have to be defined before it is able to be referenced.

Finally, this example also shows how GDL can have multiple root nodes in the same file. For these references to work correctly, it is vital that all the objects have the same object parent (that is, the parent passed in the parseGDL function).

Data types

Data types supported by GDL outside of the classes registered in GluonObjectFactory are:

Definition at line 134 of file gdlhandler.h.


Member Function Documentation

QList< GluonObject * > GDLHandler::parseGDL ( const QString  parseThis,
QObject parent 
)

Deserialise a GDL string representation into their GluonObject counterpart

Note:
Please be aware that in the case of an incorrect GDL string, you will not be given a correct list of GluonObjects. That is, the function does not currently degrade gracefully. As such, please ensure the data is acceptable upon return.
Parameters:
parseThis The GDL string that you wish to parse into GluonObject instances
Parameters:
parent The QObject you wish the objects to be parented to
Returns:
A list of generated GluonObject instances

Definition at line 330 of file gdlhandler.cpp.

QString GDLHandler::serializeGDL ( QList< const GluonObject * >  serializeThis  ) 

Serialize a list of GluonObject instances into a GDL representation

Parameters:
serializeThis The list of GluonObject instances you wish to serialize
Returns:
The serialized objects

Definition at line 347 of file gdlhandler.cpp.


Friends And Related Function Documentation

friend class Singleton< GDLHandler > [friend]

Definition at line 160 of file gdlhandler.h.


The documentation for this class was generated from the following files:
Generated on Mon Dec 27 13:13:42 2010 for Gluon by  doxygen 1.6.3