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

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

There is a newer version: 7.6.0
Show newest version
{{>licenseInfo}}
#ifndef {{prefix}}_OBJECT_H
#define {{prefix}}_OBJECT_H

#include 
#include 
#include 

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

class {{prefix}}Object {
public:
    {{prefix}}Object() {}

    {{prefix}}Object(QString jsonString) {
        fromJson(jsonString);
    }

    virtual ~{{prefix}}Object() {}

    virtual QJsonObject asJsonObject() const {
        return jObj;
    }

    virtual QString asJson() const {
        QJsonDocument doc(jObj);
        return doc.toJson(QJsonDocument::Compact);
    }

    virtual void fromJson(QString jsonString) {
        QJsonDocument doc = QJsonDocument::fromJson(jsonString.toUtf8());
        jObj = doc.object();
    }

    virtual void fromJsonObject(QJsonObject json) {
        jObj = json;
    }

    virtual bool isSet() const {
        return false;
    }

    virtual bool isValid() const {
        return true;
    }

private:
    QJsonObject jObj;
};

inline bool operator==(const {{prefix}}Object& left, const {{prefix}}Object& right){  
    return (left.asJsonObject() == right.asJsonObject());  
}

inline
#if QT_VERSION < 0x060000
uint
#else
size_t
#endif
qHash(const {{prefix}}Object& obj, uint seed = 0) noexcept{
    return qHash(obj.asJsonObject(), seed);
}

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

Q_DECLARE_METATYPE({{#cppNamespaceDeclarations}}{{this}}::{{/cppNamespaceDeclarations}}{{prefix}}Object)

#endif // {{prefix}}_OBJECT_H




© 2015 - 2024 Weber Informatics LLC | Privacy Policy