All Downloads are FREE. Search and download functionalities are using the official Maven repository.

cpp-qt5-client.object.mustache Maven / Gradle / Ivy

There is a newer version: 7.8.0
Show newest version
{{>licenseInfo}}
#ifndef _{{prefix}}_OBJECT_H_
#define _{{prefix}}_OBJECT_H_

#include 
#include 

{{#cppNamespaceDeclarations}}
namespace {{this}} {
{{/cppNamespaceDeclarations}}

class {{prefix}}Object {
  public:
    virtual QJsonObject asJsonObject() {
        if(jObj != nullptr){
            return *jObj;
        }
        return QJsonObject();
    }

    {{prefix}}Object() {
        jObj = nullptr;
    }

    virtual ~{{prefix}}Object() {
        if(jObj != nullptr){
            delete jObj;
        }
    }

    virtual {{prefix}}Object* fromJson(QString jsonString) {
        QJsonDocument doc = QJsonDocument::fromJson(jsonString.toUtf8());
        auto ret = new {{prefix}}Object();
        ret->fromJsonObject(doc.object());
        return ret;
    }

    virtual void fromJsonObject(QJsonObject json) {
        if(jObj != nullptr)
        {
            delete jObj;
        }
        jObj = new QJsonObject(json);
    }

    virtual QString asJson() {
        if(jObj != nullptr)
        {
            QJsonDocument doc(*jObj);
            return doc.toJson(QJsonDocument::Compact);
        }
        return QString();
    }

    virtual bool isSet() {
        return false;
    }
private :
   QJsonObject *jObj;
};

{{#cppNamespaceDeclarations}}
}
{{/cppNamespaceDeclarations}}

#endif /* _{{prefix}}_OBJECT_H_ */




© 2015 - 2024 Weber Informatics LLC | Privacy Policy