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

cpp-qt-qhttpengine-server.helpers-header.mustache Maven / Gradle / Ivy

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

#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 

#include "{{prefix}}Enum.h"
#include "{{prefix}}HttpFileElement.h"
#include "{{prefix}}Object.h"

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

bool setDateTimeFormat(const QString&);

template 
QString toStringValue(const QList &val);

template 
bool fromStringValue(const QList &inStr, QList &val);

template 
bool fromStringValue(const QMap &inStr, QMap &val);

template 
QJsonValue toJsonValue(const QList &val);

template 
QJsonValue toJsonValue(const QMap &val);

template 
bool fromJsonValue(QList &val, const QJsonValue &jval);

template 
bool fromJsonValue(QMap &val, const QJsonValue &jval);

QString toStringValue(const QString &value);
QString toStringValue(const QDateTime &value);
QString toStringValue(const QByteArray &value);
QString toStringValue(const QDate &value);
QString toStringValue(const qint32 &value);
QString toStringValue(const qint64 &value);
QString toStringValue(const bool &value);
QString toStringValue(const float &value);
QString toStringValue(const double &value);
QString toStringValue(const {{prefix}}Object &value);
QString toStringValue(const {{prefix}}Enum &value);
QString toStringValue(const {{prefix}}HttpFileElement &value);

template 
QString toStringValue(const QList &val) {
    QString strArray;
    for (const auto &item : val) {
        strArray.append(toStringValue(item) + ",");
    }
    if (val.count() > 0) {
        strArray.chop(1);
    }
    return strArray;
}

QJsonValue toJsonValue(const QString &value);
QJsonValue toJsonValue(const QDateTime &value);
QJsonValue toJsonValue(const QByteArray &value);
QJsonValue toJsonValue(const QDate &value);
QJsonValue toJsonValue(const qint32 &value);
QJsonValue toJsonValue(const qint64 &value);
QJsonValue toJsonValue(const bool &value);
QJsonValue toJsonValue(const float &value);
QJsonValue toJsonValue(const double &value);
QJsonValue toJsonValue(const {{prefix}}Object &value);
QJsonValue toJsonValue(const {{prefix}}Enum &value);
QJsonValue toJsonValue(const {{prefix}}HttpFileElement &value);

template 
QJsonValue toJsonValue(const QList &val) {
    QJsonArray jArray;
    for (const auto &item : val) {
        jArray.append(toJsonValue(item));
    }
    return jArray;
}

template 
QJsonValue toJsonValue(const QMap &val) {
    QJsonObject jObject;
    for (const auto &itemkey : val.keys()) {
        jObject.insert(itemkey, toJsonValue(val.value(itemkey)));
    }
    return jObject;
}

bool fromStringValue(const QString &inStr, QString &value);
bool fromStringValue(const QString &inStr, QDateTime &value);
bool fromStringValue(const QString &inStr, QByteArray &value);
bool fromStringValue(const QString &inStr, QDate &value);
bool fromStringValue(const QString &inStr, qint32 &value);
bool fromStringValue(const QString &inStr, qint64 &value);
bool fromStringValue(const QString &inStr, bool &value);
bool fromStringValue(const QString &inStr, float &value);
bool fromStringValue(const QString &inStr, double &value);
bool fromStringValue(const QString &inStr, {{prefix}}Object &value);
bool fromStringValue(const QString &inStr, {{prefix}}Enum &value);
bool fromStringValue(const QString &inStr, {{prefix}}HttpFileElement &value);

template 
bool fromStringValue(const QList &inStr, QList &val) {
    bool ok = (inStr.count() > 0);
    for (const auto &item : inStr) {
        T itemVal;
        ok &= fromStringValue(item, itemVal);
        val.push_back(itemVal);
    }
    return ok;
}

template 
bool fromStringValue(const QMap &inStr, QMap &val) {
    bool ok = (inStr.count() > 0);
    for (const auto &itemkey : inStr.keys()) {
        T itemVal;
        ok &= fromStringValue(inStr.value(itemkey), itemVal);
        val.insert(itemkey, itemVal);
    }
    return ok;
}

bool fromJsonValue(QString &value, const QJsonValue &jval);
bool fromJsonValue(QDateTime &value, const QJsonValue &jval);
bool fromJsonValue(QByteArray &value, const QJsonValue &jval);
bool fromJsonValue(QDate &value, const QJsonValue &jval);
bool fromJsonValue(qint32 &value, const QJsonValue &jval);
bool fromJsonValue(qint64 &value, const QJsonValue &jval);
bool fromJsonValue(bool &value, const QJsonValue &jval);
bool fromJsonValue(float &value, const QJsonValue &jval);
bool fromJsonValue(double &value, const QJsonValue &jval);
bool fromJsonValue({{prefix}}Object &value, const QJsonValue &jval);
bool fromJsonValue({{prefix}}Enum &value, const QJsonValue &jval);
bool fromJsonValue({{prefix}}HttpFileElement &value, const QJsonValue &jval);

template 
bool fromJsonValue(QList &val, const QJsonValue &jval) {
    bool ok = true;
    if (jval.isArray()) {
        for (const auto jitem : jval.toArray()) {
            T item;
            ok &= fromJsonValue(item, jitem);
            val.push_back(item);
        }
    } else {
        ok = false;
    }
    return ok;
}

template 
bool fromJsonValue(QMap &val, const QJsonValue &jval) {
    bool ok = true;
    if (jval.isObject()) {
        auto varmap = jval.toObject().toVariantMap();
        if (varmap.count() > 0) {
            for (const auto &itemkey : varmap.keys()) {
                T itemVal;
                ok &= fromJsonValue(itemVal, QJsonValue::fromVariant(varmap.value(itemkey)));
                val.insert(itemkey, itemVal);
            }
        }
    } else {
        ok = false;
    }
    return ok;
}

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

#endif // {{prefix}}_HELPERS_H




© 2015 - 2024 Weber Informatics LLC | Privacy Policy