#ifndef NW_UTILS_H #define NW_UTILS_H #include #include #include #include class NwUtils { public: NwUtils(); template static void describe(T& d, const nw::String key, QDate& value) { if (d.isInWriteMode()) { std::string str = value.toString(Qt::ISODate).toStdString(); d.describe(key, str); } else { std::string str; d.describe(key, str); value = QDate::fromString(QString(str.data()), Qt::ISODate); } } template static void describe(T& d, const nw::String key, QTime& value) { if (d.isInWriteMode()) { std::string str = value.toString(Qt::ISODate).toStdString(); d.describe(key, str); } else { std::string str; d.describe(key, str); value = QTime::fromString(QString(str.data()), Qt::ISODate); } } template static void describe(T& d, const nw::String key, QDateTime& value) { if (d.isInWriteMode()) { std::string str = value.toString(Qt::ISODate).toStdString(); d.describe(key, str); } else { std::string str; d.describe(key, str); value = QDateTime::fromString(QString(str.data()), Qt::ISODate); } } template static void describe(T& d, const nw::String key, QString& value) { d.describeName(key); describeValue(d, value); } template static void describeValue(T& d, QString& value) { if (d.isInWriteMode()) { std::string str = value.toStdString(); d.describeValue(str); } else { std::string str; d.describeValue(str); value = QString(str.data()); } } template static void describeConst(T& d, const nw::String key, const QString& value) { d.describeName(key); describeValueConst(d, value); } template static void describeValueConst(T& d, const QString& value) { std::string str = value.toStdString(); d.describeValueConst(str); } template static void describe(T& d, const nw::String key, QStringList& value, char separator) { if (d.isInWriteMode()) { std::stringstream ss; for (int i=0; i < value.length(); ++i) { if (i != 0) { ss << separator; } ss << value.at(i).toStdString(); } std::string str = ss.str(); d.describe(key, str); } else { std::string str; d.describe(key, str); value = QString(str.data()).split(separator); } } template static void describeValueArray(T& d, const nw::String arrayName, QStringList& value) { if (d.isInReadMode()) { value.clear(); } d.describeValueArray(arrayName, value.length()); for (int i=0; d.enterNextElement(i); ++i) { nw::String str; if (d.isInWriteMode()) { str = value[i].toStdString(); } d.describeValue(str); if (d.isInReadMode()) { value.append(str.data()); } } } template static void describeValueArray(T& d, const nw::String arrayName, QList& value) { if (d.isInReadMode()) { value.clear(); } d.describeValueArray(arrayName, value.length()); for (int i=0; d.enterNextElement(i); ++i) { T2 val; if (d.isInWriteMode()) { val = value[i]; } d.describeValue(val); if (d.isInReadMode()) { value.append(val); } } } template inline static void describe(T& d, const nw::String key, T2& value) { d.describe(key, value); } template inline static void describeConst(T& d, const nw::String key, const T2& value) { d.describeConst(key, value); } }; #endif // NW_UTILS_H