first commit

This commit is contained in:
bing
2026-04-03 11:32:07 +08:00
commit 003be19522
1142 changed files with 185854 additions and 0 deletions

View File

@@ -0,0 +1,430 @@
/****************************************************************************
**
** https://www.qxorm.com/
** Copyright (C) 2013 XDL Team (ic-east.com)
**
** This file is part of the QxOrm library
**
** This software is provided 'as-is', without any express or implied
** warranty. In no event will the authors be held liable for any
** damages arising from the use of this software
**
** Commercial Usage
** Licensees holding valid commercial QxOrm licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and XDL Team
**
** GNU General Public License Usage
** Alternatively, this file may be used under the terms of the GNU
** General Public License version 3.0 as published by the Free Software
** Foundation and appearing in the file 'license.gpl3.txt' included in the
** packaging of this file. Please review the following information to
** ensure the GNU General Public License version 3.0 requirements will be
** met : http://www.gnu.org/copyleft/gpl.html
**
** If you are unsure which license is appropriate for your use, or
** if you have questions regarding the use of this file, please contact :
** ic-east.com
**
****************************************************************************/
#ifndef _IX_DATA_MEMBER_H_
#define _IX_DATA_MEMBER_H_
#ifdef _MSC_VER
#pragma once
#endif
/*!
* \file IxDataMember.h
* \author XDL Team
* \ingroup QxDataMember
* \brief Common interface for all class properties registered into QxOrm context
*/
#ifdef _MSC_VER
#pragma warning(push)
#pragma warning(disable : 4996)
#endif // _MSC_VER
#include <QtCore/qmutex.h>
#include <QtSql/qsqlquery.h>
#ifndef _QX_NO_JSON
#include <QtCore/qjsonvalue.h>
#endif // _QX_NO_JSON
#include <QxCommon/QxAny.h>
#include <QxCommon/QxBool.h>
#include <QxCommon/QxPropertyBag.h>
#include <QxCollection/QxCollection.h>
#include <QxSerialize/boost/QxSerializeInclude.h>
#include <QxConvert/QxConvert.h>
#ifdef _MSC_VER
#pragma warning(pop)
#endif // _MSC_VER
#define QX_IX_DATA_MEMBER_PURE_VIRTUAL_ARCHIVE(ArchiveInput, ArchiveOutput) \
virtual void toArchive(const void *pOwner, ArchiveOutput &ar) const = 0; \
virtual void fromArchive(void *pOwner, ArchiveInput &ar) = 0;
namespace qx
{
class IxDataMemberX;
class IxSqlRelation;
class IxSqlQueryBuilder;
struct IxDataMemberSqlCallbackParams;
namespace dao
{
namespace detail
{
class IxDao_Helper;
} // namespace detail
} // namespace dao
/*!
* \ingroup QxDataMember
* \brief qx::IxDataMember : common interface for all class properties registered into QxOrm context
*/
class QX_DLL_EXPORT IxDataMember : public qx::QxPropertyBag
{
template <typename DataType, class Owner>
friend class QxDataMember;
public:
typedef std::function<void(IxDataMemberSqlCallbackParams &)> type_fct_sql_callback;
private:
struct IxDataMemberImpl;
std::unique_ptr<IxDataMemberImpl> m_pImpl; //!< Private implementation idiom
static QMutex m_mutex; //!< Mutex => qx::IxDataMember is thread-safe
public:
IxDataMember(const QString &sKey, long lVersion, bool bSerialize, bool bDao, IxDataMember *pImpl);
virtual ~IxDataMember() = 0;
QString getKey() const;
QString getName() const;
int getNameCount() const;
QString getNameParent() const;
const char *getNamePtr() const;
QString getDescription() const;
QString getFormat() const;
long getVersion() const;
bool getSerialize() const;
bool getDao() const;
QVariant getDefaultValue() const;
QVariant getMinValue() const;
QVariant getMaxValue() const;
int getPrecision() const;
int getMinLength() const;
int getMaxLength() const;
bool getRequired() const;
bool getReadOnly() const;
bool getAutoIncrement() const;
bool getNotNull() const;
bool getIsPrimaryKey() const;
bool getIsIndex() const;
bool getIsUnique() const;
IxDataMemberX *getParent() const;
IxSqlRelation *getSqlRelation() const;
bool hasSqlRelation() const;
bool getAccessDataPointer() const;
virtual QString getType() const;
QString getTypeParent() const;
IxDataMember *getPImpl() const;
void setName(const QString &s);
void setNameParent(const QString &s);
void setDescription(const QString &s);
void setFormat(const QString &s);
void setSqlType(const QString &s);
void setSqlAlias(const QString &s);
void setVersion(long l);
void setSerialize(bool b);
void setDao(bool b);
void setDefaultValue(const QVariant &v);
void setPrecision(int i);
void setRequired(bool b);
void setReadOnly(bool b);
void setAutoIncrement(bool b);
void setIsPrimaryKey(bool b);
void setIsIndex(bool b);
void setIsUnique(bool b);
void setParent(IxDataMemberX *p);
void setSqlRelation(IxSqlRelation *p);
void setAccessDataPointer(bool b);
void setMinValue(long lMinValue, const QString &sMessage = QString());
void setMinValue(double dMinValue, const QString &sMessage = QString());
void setMaxValue(long lMaxValue, const QString &sMessage = QString());
void setMaxValue(double dMaxValue, const QString &sMessage = QString());
void setMinLength(int iMinLength, const QString &sMessage = QString());
void setMaxLength(int iMaxLength, const QString &sMessage = QString());
void setNotNull(bool bNotNull, const QString &sMessage = QString());
bool isThereRelationPartOfPrimaryKey(int iIndexNamePK, IxSqlRelation *&pRelation, int &iIndexNameFK) const;
bool isPartOfPrimaryKey(int iIndexNameFK, IxDataMember *&pPrimaryKey, int &iIndexNamePK) const;
void setRelationPartOfPrimaryKey(int iIndexNamePK, IxSqlRelation *pRelation, int iIndexNameFK);
void setPartOfPrimaryKey(int iIndexNameFK, IxDataMember *pPrimaryKey, int iIndexNamePK);
QString getName(int iIndex, const QString &sOtherName = QString()) const;
QString getSqlAlias(const QString &sTable = QString(), bool bClauseWhere = false, int iIndexName = 0, qx::IxSqlQueryBuilder *pSqlQueryBuilder = NULL) const;
QString getSqlType(int iIndexName = -1) const;
QString getSqlTypeAndParams(int iIndexName = -1) const;
QString getSqlPlaceHolder(const QString &sAppend = QString(), int iIndexName = 0, const QString &sSep = QString(", "), const QString &sOtherName = QString(), bool bCheckFKPartOfPK = false) const;
void setSqlPlaceHolder(QSqlQuery &query, void *pOwner, const QString &sAppend = QString(), const QString &sOtherName = QString(), bool bCheckFKPartOfPK = false, qx::QxCollection<QString, QVariantList> *pLstExecBatch = NULL) const;
QString getSqlAliasEqualToPlaceHolder(const QString &sTable = QString(), bool bClauseWhere = false, const QString &sAppend = QString(), const QString &sSep = QString(" AND "), bool bCheckFKPartOfPK = false, qx::IxSqlQueryBuilder *pSqlQueryBuilder = NULL) const;
QString getSqlNameEqualToPlaceHolder(const QString &sAppend = QString(), const QString &sSep = QString(" AND "), bool bCheckFKPartOfPK = false, qx::IxSqlQueryBuilder *pSqlQueryBuilder = NULL) const;
QString getSqlTablePointNameAsAlias(const QString &sTable, const QString &sSep = QString(", "), const QString &sSuffixAlias = QString(), bool bCheckFKPartOfPK = false, const QString &sCustomAlias = QString(), qx::IxSqlQueryBuilder *pSqlQueryBuilder = NULL) const;
QString getSqlName(const QString &sSep = QString(", "), const QString &sOtherName = QString(), bool bCheckFKPartOfPK = false, qx::IxSqlQueryBuilder *pSqlQueryBuilder = NULL) const;
QString getSqlNameAndTypeAndParams(const QString &sSep = QString(", "), const QString &sOtherName = QString(), bool bCheckFKPartOfPK = false) const;
void customGetSqlName(type_fct_sql_callback fct);
void customGetSqlTablePointNameAsAlias(type_fct_sql_callback fct);
void customGetSqlNameEqualToPlaceHolder(type_fct_sql_callback fct);
void customGetSqlAliasEqualToPlaceHolder(type_fct_sql_callback fct);
void customGetSqlAlias(type_fct_sql_callback fct);
static QString getSqlFromTable(const QString &sTable, const QString &sCustomAlias = QString());
static QString getSqlTableName(const QString &sTable);
static QString getSqlColumnName(const QString &sColumn);
static QString getSqlTableNameAlias(const QString &sTable);
static QString getSqlColumnNameAlias(const QString &sColumn);
virtual bool isEqual(const void *pOwner1, const void *pOwner2) const = 0;
virtual QVariant toVariant(const void *pOwner, const QString &sFormat, int iIndexName = -1, qx::cvt::context::ctx_type ctx = qx::cvt::context::e_no_context) const = 0;
virtual qx_bool fromVariant(void *pOwner, const QVariant &v, const QString &sFormat, int iIndexName = -1, qx::cvt::context::ctx_type ctx = qx::cvt::context::e_no_context) = 0;
QVariant toVariant(const void *pOwner, int iIndexName = -1, qx::cvt::context::ctx_type ctx = qx::cvt::context::e_no_context) const;
qx_bool fromVariant(void *pOwner, const QVariant &v, int iIndexName = -1, qx::cvt::context::ctx_type ctx = qx::cvt::context::e_no_context);
#ifndef _QX_NO_JSON
virtual QJsonValue toJson(const void *pOwner, const QString &sFormat) const = 0;
virtual qx_bool fromJson(void *pOwner, const QJsonValue &j, const QString &sFormat) = 0;
QJsonValue toJson(const void *pOwner) const;
qx_bool fromJson(void *pOwner, const QJsonValue &j);
#endif // _QX_NO_JSON
protected:
virtual qx::any getDataPtr(const void *pOwner) const = 0;
virtual qx::any getDataPtr(void *pOwner) = 0;
virtual void *getDataVoidPtr(const void *pOwner) const = 0;
virtual void *getDataVoidPtr(void *pOwner) = 0;
public:
qx::any getValueAnyPtr(const void *pOwner) const { return this->getDataPtr(pOwner); }
qx::any getValueAnyPtr(void *pOwner) { return this->getDataPtr(pOwner); }
void *getValueVoidPtr(const void *pOwner) const { return this->getDataVoidPtr(pOwner); }
void *getValueVoidPtr(void *pOwner) { return this->getDataVoidPtr(pOwner); }
template <typename T>
T *getValuePtr(void *pOwner, bool *bOk = NULL)
{
if (bOk)
{
(*bOk) = false;
}
if (!getAccessDataPointer())
{
qDebug("[QxOrm] qx::IxDataMember::getValuePtr<T>() : '%s'", "cannot access data-member pointer");
return NULL;
}
qx::any a = this->getDataPtr(pOwner);
try
{
T *t = qx::any_cast<T *>(a);
if (bOk)
{
(*bOk) = (t != NULL);
};
return t;
}
catch (const qx::bad_any_cast &err)
{
Q_UNUSED(err);
qDebug("[QxOrm] qx::IxDataMember::getValuePtr<T>() : '%s'", "bad any cast exception");
return NULL;
}
catch (...)
{
qDebug("[QxOrm] qx::IxDataMember::getValuePtr<T>() : '%s'", "unknown cast exception");
return NULL;
}
}
template <typename T>
T getValue(void *pOwner, bool *bOk = NULL)
{
if (!getAccessDataPointer())
{
return qxCannotAccessDataPointer<T, 0>::getValue(this, pOwner, bOk);
}
T *t = this->getValuePtr<T>(pOwner, bOk);
return (t ? (*t) : T());
}
template <typename T>
bool setValue(void *pOwner, const T &val)
{
if (!getAccessDataPointer())
{
return qxCannotAccessDataPointer<T, 0>::setValue(this, pOwner, val);
}
T *t = this->getValuePtr<T>(pOwner);
if (t)
{
(*t) = val;
}
return (t != NULL);
}
private:
template <typename T, int dummy>
struct qxCannotAccessDataPointer
{
static T getValue(IxDataMember *pData, void *pOwner, bool *bOk)
{
Q_UNUSED(pData);
Q_UNUSED(pOwner);
qDebug("[QxOrm] qx::IxDataMember::qxCannotAccessDataPointer<T>::getValue() : '%s'", "type T not supported");
if (bOk)
{
(*bOk) = false;
};
return T();
}
static bool setValue(IxDataMember *pData, void *pOwner, const T &val)
{
Q_UNUSED(pData);
Q_UNUSED(pOwner);
Q_UNUSED(val);
qDebug("[QxOrm] qx::IxDataMember::qxCannotAccessDataPointer<T>::setValue() : '%s'", "type T not supported");
return false;
}
};
template <int dummy>
struct qxCannotAccessDataPointer<QVariant, dummy>
{
static QVariant getValue(IxDataMember *pData, void *pOwner, bool *bOk)
{
if (bOk)
{
(*bOk) = (pData != NULL);
};
return (pData ? pData->toVariant(pOwner, "") : QVariant());
}
static bool setValue(IxDataMember *pData, void *pOwner, const QVariant &val)
{
return (pData ? pData->fromVariant(pOwner, val, "").getValue() : false);
}
};
template <int dummy>
struct qxCannotAccessDataPointer<QString, dummy>
{
static QString getValue(IxDataMember *pData, void *pOwner, bool *bOk)
{
if (bOk)
{
(*bOk) = (pData != NULL);
};
return (pData ? pData->toVariant(pOwner, "").toString() : QString());
}
static bool setValue(IxDataMember *pData, void *pOwner, const QString &val)
{
QVariant tmp(val);
return (pData ? pData->fromVariant(pOwner, tmp, "").getValue() : false);
}
};
public:
#ifdef _QX_ENABLE_BOOST_SERIALIZATION
#if _QX_SERIALIZE_POLYMORPHIC
QX_IX_DATA_MEMBER_PURE_VIRTUAL_ARCHIVE(boost::archive::polymorphic_iarchive, boost::archive::polymorphic_oarchive)
#endif // _QX_SERIALIZE_POLYMORPHIC
#if _QX_SERIALIZE_BINARY
QX_IX_DATA_MEMBER_PURE_VIRTUAL_ARCHIVE(boost::archive::binary_iarchive, boost::archive::binary_oarchive)
#endif // _QX_SERIALIZE_BINARY
#if _QX_SERIALIZE_TEXT
QX_IX_DATA_MEMBER_PURE_VIRTUAL_ARCHIVE(boost::archive::text_iarchive, boost::archive::text_oarchive)
#endif // _QX_SERIALIZE_TEXT
#if _QX_SERIALIZE_XML
QX_IX_DATA_MEMBER_PURE_VIRTUAL_ARCHIVE(boost::archive::xml_iarchive, boost::archive::xml_oarchive)
#endif // _QX_SERIALIZE_XML
#if _QX_SERIALIZE_PORTABLE_BINARY
QX_IX_DATA_MEMBER_PURE_VIRTUAL_ARCHIVE(eos::portable_iarchive, eos::portable_oarchive)
#endif // _QX_SERIALIZE_PORTABLE_BINARY
#if _QX_SERIALIZE_WIDE_BINARY
QX_IX_DATA_MEMBER_PURE_VIRTUAL_ARCHIVE(boost::archive::binary_wiarchive, boost::archive::binary_woarchive)
#endif // _QX_SERIALIZE_WIDE_BINARY
#if _QX_SERIALIZE_WIDE_TEXT
QX_IX_DATA_MEMBER_PURE_VIRTUAL_ARCHIVE(boost::archive::text_wiarchive, boost::archive::text_woarchive)
#endif // _QX_SERIALIZE_WIDE_TEXT
#if _QX_SERIALIZE_WIDE_XML
QX_IX_DATA_MEMBER_PURE_VIRTUAL_ARCHIVE(boost::archive::xml_wiarchive, boost::archive::xml_woarchive)
#endif // _QX_SERIALIZE_WIDE_XML
#endif // _QX_ENABLE_BOOST_SERIALIZATION
private:
#ifdef _QX_ENABLE_BOOST_SERIALIZATION
template <class Archive>
void serialize(Archive &ar, const unsigned int version);
#endif // _QX_ENABLE_BOOST_SERIALIZATION
};
typedef std::shared_ptr<IxDataMember> IxDataMember_ptr;
/*!
* \ingroup QxDataMember
* \brief qx::IxDataMemberSqlCallbackParams : list of parameters used by custom callback functions to override SQL queries generated by QxOrm library
*/
struct IxDataMemberSqlCallbackParams
{
const IxDataMember *pDataMember; //!< The data member instance which calls custom callback function
QString &sSQL; //!< Default value is the SQL generated by QxOrm library for this data member, can be changed by the custom callback function
QString sTable; //!< SQL table name (not always provided)
QString sSep; //!< SQL separator (not always provided)
QString sCustomAlias; //!< SQL custom alias (not always provided)
QString sSuffixAlias; //!< SQL suffix alias (not always provided)
QString sAppend; //!< String to append to SQL query (not always provided)
QString sOtherName; //!< SQL other name for this data member (not always provided)
bool bClauseWhere; //!< Define if we are building SQL in the clause WHERE or not (not always provided)
bool bCheckFKPartOfPK; //!< Check if foreign key is part of primary key (not always provided)
int iIndexName; //!< Index name for composite primary key (not always provided)
qx::dao::detail::IxDao_Helper *pDaoHelper; //!< DAO helper instance
qx::IxSqlQueryBuilder *pSqlQueryBuilder; //!< SQL query builder instance
IxDataMemberSqlCallbackParams(const IxDataMember *p, QString &sql);
~IxDataMemberSqlCallbackParams();
};
} // namespace qx
QX_DLL_EXPORT_INLINE_FCT bool operator<(const qx::IxDataMember &i1, const qx::IxDataMember &i2);
QX_DLL_EXPORT_INLINE_FCT bool operator>(const qx::IxDataMember &i1, const qx::IxDataMember &i2);
#endif // _IX_DATA_MEMBER_H_

View File

@@ -0,0 +1,107 @@
/****************************************************************************
**
** https://www.qxorm.com/
** Copyright (C) 2013 XDL Team (ic-east.com)
**
** This file is part of the QxOrm library
**
** This software is provided 'as-is', without any express or implied
** warranty. In no event will the authors be held liable for any
** damages arising from the use of this software
**
** Commercial Usage
** Licensees holding valid commercial QxOrm licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and XDL Team
**
** GNU General Public License Usage
** Alternatively, this file may be used under the terms of the GNU
** General Public License version 3.0 as published by the Free Software
** Foundation and appearing in the file 'license.gpl3.txt' included in the
** packaging of this file. Please review the following information to
** ensure the GNU General Public License version 3.0 requirements will be
** met : http://www.gnu.org/copyleft/gpl.html
**
** If you are unsure which license is appropriate for your use, or
** if you have questions regarding the use of this file, please contact :
** ic-east.com
**
****************************************************************************/
#ifndef _IX_DATA_MEMBER_X_H_
#define _IX_DATA_MEMBER_X_H_
#ifdef _MSC_VER
#pragma once
#endif
/*!
* \file IxDataMemberX.h
* \author XDL Team
* \ingroup QxDataMember
* \brief Common interface for a list of IxDataMember class properties registered into QxOrm context (for example, list of data member of a class)
*/
#include <QxDataMember/IxDataMember.h>
#include <QxDao/QxDaoStrategy.h>
#include <QxCollection/QxCollection.h>
namespace qx
{
class IxClass;
/*!
* \ingroup QxDataMember
* \brief qx::IxDataMemberX : common interface for a list of IxDataMember class properties registered into QxOrm context (for example, list of data member of a class)
*/
class QX_DLL_EXPORT IxDataMemberX
{
private:
struct IxDataMemberXImpl;
std::unique_ptr<IxDataMemberXImpl> m_pImpl; //!< Private implementation idiom
protected:
IxDataMemberX();
virtual ~IxDataMemberX();
public:
IxClass *getClass() const;
void setClass(IxClass *p);
QString getName() const;
const char *getNamePtr() const;
QString getDescription() const;
long getVersion() const;
qx::dao::strategy::inheritance getDaoStrategy() const;
long count() const;
long size() const;
bool exist(const QString &sKey) const;
IxDataMember *get(long l) const;
IxDataMember *get(const QString &s) const;
IxDataMember *getId() const;
virtual long count_WithDaoStrategy() const = 0;
virtual bool exist_WithDaoStrategy(const QString &sKey) const = 0;
virtual IxDataMember *get_WithDaoStrategy(long lIndex) const = 0;
virtual IxDataMember *get_WithDaoStrategy(const QString &sKey) const = 0;
virtual IxDataMember *getId_WithDaoStrategy() const = 0;
protected:
void setId(IxDataMember *p);
QxCollection<QString, IxDataMember *> &getListDataMemberRef();
const QxCollection<QString, IxDataMember *> &getListDataMemberRef() const;
QxCollection<QString, IxDataMember *> &getListPImplRef();
const QxCollection<QString, IxDataMember *> &getListPImplRef() const;
};
typedef std::shared_ptr<IxDataMemberX> IxDataMemberX_ptr;
} // namespace qx
#endif // _IX_DATA_MEMBER_X_H_

View File

@@ -0,0 +1,202 @@
/****************************************************************************
**
** https://www.qxorm.com/
** Copyright (C) 2013 XDL Team (ic-east.com)
**
** This file is part of the QxOrm library
**
** This software is provided 'as-is', without any express or implied
** warranty. In no event will the authors be held liable for any
** damages arising from the use of this software
**
** Commercial Usage
** Licensees holding valid commercial QxOrm licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and XDL Team
**
** GNU General Public License Usage
** Alternatively, this file may be used under the terms of the GNU
** General Public License version 3.0 as published by the Free Software
** Foundation and appearing in the file 'license.gpl3.txt' included in the
** packaging of this file. Please review the following information to
** ensure the GNU General Public License version 3.0 requirements will be
** met : http://www.gnu.org/copyleft/gpl.html
**
** If you are unsure which license is appropriate for your use, or
** if you have questions regarding the use of this file, please contact :
** ic-east.com
**
****************************************************************************/
#ifndef _QX_DATA_MEMBER_H_
#define _QX_DATA_MEMBER_H_
#ifdef _MSC_VER
#pragma once
#endif
/*!
* \file QxDataMember.h
* \author XDL Team
* \ingroup QxDataMember
* \brief Concrete class property registered into QxOrm context
*/
#ifdef _QX_ENABLE_BOOST_SERIALIZATION
#include <boost/serialization/serialization.hpp>
#include <boost/serialization/nvp.hpp>
#endif // _QX_ENABLE_BOOST_SERIALIZATION
#include <QxDataMember/IxDataMember.h>
#include <QxTraits/is_equal.h>
#include <QxTraits/get_class_name.h>
#define QX_DATA_MEMBER_IMPL_VIRTUAL_ARCHIVE(ArchiveInput, ArchiveOutput) \
virtual void toArchive(const void *pOwner, ArchiveOutput &ar) const { QxDataMember::toArchive(ar, getNamePtr(), getData(pOwner)); } \
virtual void fromArchive(void *pOwner, ArchiveInput &ar) { QxDataMember::fromArchive(ar, getNamePtr(), getData(pOwner)); }
namespace qx
{
/*!
* \ingroup QxDataMember
* \brief qx::QxDataMember<DataType, Owner> : concrete property of type DataType registered into QxOrm context for the class Owner
*/
template <typename DataType, class Owner>
class QxDataMember : public IxDataMember
{
protected:
typedef DataType Owner::*type_data_member_ptr;
type_data_member_ptr m_pData; //!< Data member under format "& Owner::DataMember"
IxDataMember *m_pImpl_; //!< If not NULL then this data member is owned by a private implementation idiom instance
public:
QxDataMember(type_data_member_ptr pData, const QString &sKey, long lVersion, bool bSerialize, bool bDao, IxDataMember *pImpl = NULL) : IxDataMember(sKey, lVersion, bSerialize, bDao, pImpl), m_pData(pData), m_pImpl_(pImpl) { this->setAccessDataPointer(true); }
virtual ~QxDataMember() { ; }
inline DataType *getData(void *pOwner) const
{
void *pOwner_ = (m_pImpl_ ? m_pImpl_->getDataVoidPtr(pOwner) : pOwner);
return (pOwner_ ? (&((static_cast<Owner *>(pOwner_))->*m_pData)) : NULL);
}
inline const DataType *getData(const void *pOwner) const
{
const void *pOwner_ = (m_pImpl_ ? m_pImpl_->getDataVoidPtr(pOwner) : pOwner);
return (pOwner_ ? (&((static_cast<const Owner *>(pOwner_))->*m_pData)) : NULL);
}
virtual QVariant toVariant(const void *pOwner, const QString &sFormat, int iIndexName = -1, qx::cvt::context::ctx_type ctx = qx::cvt::context::e_no_context) const { return qx::cvt::to_variant((*getData(pOwner)), sFormat, iIndexName, ctx); }
virtual qx_bool fromVariant(void *pOwner, const QVariant &v, const QString &sFormat, int iIndexName = -1, qx::cvt::context::ctx_type ctx = qx::cvt::context::e_no_context) { return qx::cvt::from_variant(v, (*getData(pOwner)), sFormat, iIndexName, ctx); }
virtual QString getType() const
{
QMutexLocker locker(&IxDataMember::m_mutex);
return QString(qx::trait::get_class_name<DataType>::get());
}
#ifndef _QX_NO_JSON
virtual QJsonValue toJson(const void *pOwner, const QString &sFormat) const { return qx::cvt::to_json((*getData(pOwner)), sFormat); }
virtual qx_bool fromJson(void *pOwner, const QJsonValue &j, const QString &sFormat) { return qx::cvt::from_json(j, (*getData(pOwner)), sFormat); }
#endif // _QX_NO_JSON
virtual bool isEqual(const void *pOwner1, const void *pOwner2) const
{
if ((pOwner1 == NULL) || (pOwner2 == NULL))
{
return false;
}
if (pOwner1 == pOwner2)
{
return true;
}
return qxCompareDataMember<qx::trait::has_operator_equal_equal<DataType>::value, 0>::isEqual((*this), pOwner1, pOwner2);
}
protected:
virtual qx::any getDataPtr(const void *pOwner) const { return qx::any(getData(pOwner)); }
virtual qx::any getDataPtr(void *pOwner) { return qx::any(getData(pOwner)); }
virtual void *getDataVoidPtr(const void *pOwner) const { return static_cast<void *>(const_cast<DataType *>(getData(pOwner))); }
virtual void *getDataVoidPtr(void *pOwner) { return static_cast<void *>(getData(pOwner)); }
public:
#ifdef _QX_ENABLE_BOOST_SERIALIZATION
#if _QX_SERIALIZE_POLYMORPHIC
QX_DATA_MEMBER_IMPL_VIRTUAL_ARCHIVE(boost::archive::polymorphic_iarchive, boost::archive::polymorphic_oarchive)
#endif // _QX_SERIALIZE_POLYMORPHIC
#if _QX_SERIALIZE_BINARY
QX_DATA_MEMBER_IMPL_VIRTUAL_ARCHIVE(boost::archive::binary_iarchive, boost::archive::binary_oarchive)
#endif // _QX_SERIALIZE_BINARY
#if _QX_SERIALIZE_TEXT
QX_DATA_MEMBER_IMPL_VIRTUAL_ARCHIVE(boost::archive::text_iarchive, boost::archive::text_oarchive)
#endif // _QX_SERIALIZE_TEXT
#if _QX_SERIALIZE_XML
QX_DATA_MEMBER_IMPL_VIRTUAL_ARCHIVE(boost::archive::xml_iarchive, boost::archive::xml_oarchive)
#endif // _QX_SERIALIZE_XML
#if _QX_SERIALIZE_PORTABLE_BINARY
QX_DATA_MEMBER_IMPL_VIRTUAL_ARCHIVE(eos::portable_iarchive, eos::portable_oarchive)
#endif // _QX_SERIALIZE_PORTABLE_BINARY
#if _QX_SERIALIZE_WIDE_BINARY
QX_DATA_MEMBER_IMPL_VIRTUAL_ARCHIVE(boost::archive::binary_wiarchive, boost::archive::binary_woarchive)
#endif // _QX_SERIALIZE_WIDE_BINARY
#if _QX_SERIALIZE_WIDE_TEXT
QX_DATA_MEMBER_IMPL_VIRTUAL_ARCHIVE(boost::archive::text_wiarchive, boost::archive::text_woarchive)
#endif // _QX_SERIALIZE_WIDE_TEXT
#if _QX_SERIALIZE_WIDE_XML
QX_DATA_MEMBER_IMPL_VIRTUAL_ARCHIVE(boost::archive::xml_wiarchive, boost::archive::xml_woarchive)
#endif // _QX_SERIALIZE_WIDE_XML
#endif // _QX_ENABLE_BOOST_SERIALIZATION
private:
#ifdef _QX_ENABLE_BOOST_SERIALIZATION
template <class Archive>
static inline void toArchive(Archive &ar, const char *sName, const DataType *pData)
{
ar << boost::serialization::make_nvp(sName, (*pData));
}
template <class Archive>
static inline void fromArchive(Archive &ar, const char *sName, DataType *pData)
{
ar >> boost::serialization::make_nvp(sName, (*pData));
}
#endif // _QX_ENABLE_BOOST_SERIALIZATION
private:
template <bool bCanCompare /* = false */, int dummy>
struct qxCompareDataMember
{
static inline bool isEqual(const QxDataMember<DataType, Owner> &dataMember, const void *pOwner1, const void *pOwner2)
{
return (dataMember.toVariant(pOwner1, "") == dataMember.toVariant(pOwner2, ""));
}
};
template <int dummy>
struct qxCompareDataMember<true, dummy>
{
static inline bool isEqual(const QxDataMember<DataType, Owner> &dataMember, const void *pOwner1, const void *pOwner2)
{
return ((*dataMember.getData(pOwner1)) == (*dataMember.getData(pOwner2)));
}
};
};
} // namespace qx
#include "../../inl/QxDataMember/QxDataMember.inl"
#endif // _QX_DATA_MEMBER_H_

View File

@@ -0,0 +1,229 @@
/****************************************************************************
**
** https://www.qxorm.com/
** Copyright (C) 2013 XDL Team (ic-east.com)
**
** This file is part of the QxOrm library
**
** This software is provided 'as-is', without any express or implied
** warranty. In no event will the authors be held liable for any
** damages arising from the use of this software
**
** Commercial Usage
** Licensees holding valid commercial QxOrm licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and XDL Team
**
** GNU General Public License Usage
** Alternatively, this file may be used under the terms of the GNU
** General Public License version 3.0 as published by the Free Software
** Foundation and appearing in the file 'license.gpl3.txt' included in the
** packaging of this file. Please review the following information to
** ensure the GNU General Public License version 3.0 requirements will be
** met : http://www.gnu.org/copyleft/gpl.html
**
** If you are unsure which license is appropriate for your use, or
** if you have questions regarding the use of this file, please contact :
** ic-east.com
**
****************************************************************************/
#ifndef _QX_DATA_MEMBER_X_H_
#define _QX_DATA_MEMBER_X_H_
#ifdef _MSC_VER
#pragma once
#endif
/*!
* \file QxDataMemberX.h
* \author XDL Team
* \ingroup QxDataMember
* \brief Concrete list of class properties registered into QxOrm context
*/
#include <QxDataMember/IxDataMemberX.h>
#include <QxDataMember/QxDataMember.h>
#include <QxDataMember/QxDataMember_QObject.h>
#include <QxDataMember/QxDataMember_PImpl.h>
#include <QxDao/QxSqlRelation.h>
#include <QxSingleton/QxSingleton.h>
#include <QxFactory/QxFactory.h>
#include <QxTraits/get_base_class.h>
#include <QxTraits/get_primary_key.h>
#include <QxTraits/get_sql_type.h>
#include <QxTraits/qt_meta_object.h>
namespace qx
{
/*!
* \ingroup QxDataMember
* \brief qx::QxDataMemberX<T> : concrete list of properties registered into QxOrm context for the class T
*/
template <class T>
class QxDataMemberX : public IxDataMemberX, public QxSingleton<QxDataMemberX<T>>
{
friend class QxSingleton<QxDataMemberX<T>>;
public:
typedef typename qx::trait::get_primary_key<T>::type type_primary_key;
typedef typename qx::trait::get_base_class<T>::type type_base_class;
protected:
QxDataMemberX() : IxDataMemberX(), QxSingleton<QxDataMemberX<T>>(QString("qx::QxDataMemberX_") + qx::trait::get_class_name<T>::get_xml_tag()) { ; }
virtual ~QxDataMemberX() { ; }
public:
virtual long count_WithDaoStrategy() const { return count_WithDaoStrategy_Helper(); }
virtual bool exist_WithDaoStrategy(const QString &sKey) const { return exist_WithDaoStrategy_Helper(sKey); }
virtual IxDataMember *get_WithDaoStrategy(long lIndex) const { return get_WithDaoStrategy_Helper(lIndex); }
virtual IxDataMember *get_WithDaoStrategy(const QString &sKey) const { return get_WithDaoStrategy_Helper(sKey); }
virtual IxDataMember *getId_WithDaoStrategy() const { return getId_WithDaoStrategy_Helper(); }
IxDataMember *id(type_primary_key T::*pDataMemberId, const QString &sKey, long lVersion = 0);
IxDataMember *id(const QString &sKey, long lVersion);
IxDataMember *add(const QString &sKey, long lVersion);
template <typename V, typename U>
IxDataMember *add(V U::*pData, const QString &sKey, long lVersion = 0, bool bSerialize = true, bool bDao = true);
template <typename V, typename U>
IxSqlRelation *relationOneToOne(V U::*pData, const QString &sKey, long lVersion = 0);
template <typename V, typename U>
IxSqlRelation *relationManyToOne(V U::*pData, const QString &sKey, long lVersion = 0);
template <typename V, typename U>
IxSqlRelation *relationOneToMany(V U::*pData, const QString &sKey, const QString &sForeignKey, long lVersion = 0);
template <typename V, typename U>
IxSqlRelation *relationManyToMany(V U::*pData, const QString &sKey, const QString &sExtraTable, const QString &sForeignKeyOwner, const QString &sForeignKeyDataType, long lVersion = 0);
template <typename V, typename U>
IxDataMember *pimpl(V U::*pData, const QString &sKey);
template <typename U>
IxDataMember *id(type_primary_key U::*pDataMemberId, const QString &sKey, long lVersion, IxDataMember *pImpl);
template <typename V, typename U>
IxDataMember *add(V U::*pData, const QString &sKey, long lVersion, bool bSerialize, bool bDao, IxDataMember *pImpl);
template <typename V, typename U>
IxSqlRelation *relationOneToOne(V U::*pData, const QString &sKey, long lVersion, IxDataMember *pImpl);
template <typename V, typename U>
IxSqlRelation *relationManyToOne(V U::*pData, const QString &sKey, long lVersion, IxDataMember *pImpl);
template <typename V, typename U>
IxSqlRelation *relationOneToMany(V U::*pData, const QString &sKey, const QString &sForeignKey, long lVersion, IxDataMember *pImpl);
template <typename V, typename U>
IxSqlRelation *relationManyToMany(V U::*pData, const QString &sKey, const QString &sExtraTable, const QString &sForeignKeyOwner, const QString &sForeignKeyDataType, long lVersion, IxDataMember *pImpl);
#ifdef _QX_ENABLE_BOOST_SERIALIZATION
template <class Archive>
inline void toArchive(const T *pOwner, Archive &ar, const unsigned int file_version) const;
template <class Archive>
inline void fromArchive(T *pOwner, Archive &ar, const unsigned int file_version);
#endif // _QX_ENABLE_BOOST_SERIALIZATION
private:
IxDataMember *initId(IxDataMember *pId, long lVersion);
IxDataMember *initData(IxDataMember *pData, long lVersion);
IxDataMember *initPImpl(IxDataMember *pImpl);
inline IxDataMemberX *getBaseClass_Helper() const { return QxDataMemberX<type_base_class>::getSingleton(); }
long count_WithDaoStrategy_Helper() const
{
if (getDaoStrategy() == qx::dao::strategy::single_table_inheritance)
{
return ((getBaseClass_Helper()->getDaoStrategy() != getDaoStrategy()) ? count() : getBaseClass_Helper()->count_WithDaoStrategy());
}
else if (getDaoStrategy() == qx::dao::strategy::class_table_inheritance)
{
return (count() + ((!getId() && getId_WithDaoStrategy()) ? 1 : 0));
}
else if (getDaoStrategy() == qx::dao::strategy::concrete_table_inheritance)
{
return (count() + getBaseClass_Helper()->count_WithDaoStrategy());
}
qAssert(false);
return 0;
}
bool exist_WithDaoStrategy_Helper(const QString &sKey) const
{
if (getDaoStrategy() == qx::dao::strategy::single_table_inheritance)
{
return ((getBaseClass_Helper()->getDaoStrategy() != getDaoStrategy()) ? exist(sKey) : getBaseClass_Helper()->exist_WithDaoStrategy(sKey));
}
else if (getDaoStrategy() == qx::dao::strategy::class_table_inheritance)
{
return (exist(sKey) || (getId_WithDaoStrategy() ? (getId_WithDaoStrategy()->getKey() == sKey) : false));
}
else if (getDaoStrategy() == qx::dao::strategy::concrete_table_inheritance)
{
return (exist(sKey) || getBaseClass_Helper()->exist_WithDaoStrategy(sKey));
}
qAssert(false);
return false;
}
IxDataMember *get_WithDaoStrategy_Helper(long lIndex) const
{
if (getDaoStrategy() == qx::dao::strategy::single_table_inheritance)
{
return ((getBaseClass_Helper()->getDaoStrategy() != getDaoStrategy()) ? get(lIndex) : getBaseClass_Helper()->get_WithDaoStrategy(lIndex));
}
else if (getDaoStrategy() == qx::dao::strategy::class_table_inheritance)
{
return ((!getId() && (lIndex == count())) ? getId_WithDaoStrategy() : get(lIndex));
}
else if (getDaoStrategy() == qx::dao::strategy::concrete_table_inheritance)
{
return (((lIndex >= 0) && (lIndex < count())) ? get(lIndex) : getBaseClass_Helper()->get_WithDaoStrategy(lIndex - count()));
}
qAssert(false);
return NULL;
}
IxDataMember *get_WithDaoStrategy_Helper(const QString &sKey) const
{
if (getDaoStrategy() == qx::dao::strategy::single_table_inheritance)
{
return ((getBaseClass_Helper()->getDaoStrategy() != getDaoStrategy()) ? get(sKey) : getBaseClass_Helper()->get_WithDaoStrategy(sKey));
}
else if (getDaoStrategy() == qx::dao::strategy::class_table_inheritance)
{
return ((getId_WithDaoStrategy() && (getId_WithDaoStrategy()->getKey() == sKey)) ? getId_WithDaoStrategy() : get(sKey));
}
else if (getDaoStrategy() == qx::dao::strategy::concrete_table_inheritance)
{
return (exist(sKey) ? get(sKey) : getBaseClass_Helper()->get_WithDaoStrategy(sKey));
}
qAssert(false);
return NULL;
}
IxDataMember *getId_WithDaoStrategy_Helper() const
{
if (getDaoStrategy() == qx::dao::strategy::single_table_inheritance)
{
return ((getBaseClass_Helper()->getDaoStrategy() != getDaoStrategy()) ? getId() : getBaseClass_Helper()->getId_WithDaoStrategy());
}
else if (getDaoStrategy() == qx::dao::strategy::class_table_inheritance)
{
return (getId() ? getId() : getBaseClass_Helper()->getId_WithDaoStrategy());
}
else if (getDaoStrategy() == qx::dao::strategy::concrete_table_inheritance)
{
return (getId() ? getId() : getBaseClass_Helper()->getId_WithDaoStrategy());
}
qAssert(false);
return NULL;
}
};
} // namespace qx
#include "../../inl/QxDataMember/QxDataMemberX.inl"
#endif // _QX_DATA_MEMBER_X_H_

View File

@@ -0,0 +1,376 @@
/****************************************************************************
**
** https://www.qxorm.com/
** Copyright (C) 2013 XDL Team (ic-east.com)
**
** This file is part of the QxOrm library
**
** This software is provided 'as-is', without any express or implied
** warranty. In no event will the authors be held liable for any
** damages arising from the use of this software
**
** Commercial Usage
** Licensees holding valid commercial QxOrm licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and XDL Team
**
** GNU General Public License Usage
** Alternatively, this file may be used under the terms of the GNU
** General Public License version 3.0 as published by the Free Software
** Foundation and appearing in the file 'license.gpl3.txt' included in the
** packaging of this file. Please review the following information to
** ensure the GNU General Public License version 3.0 requirements will be
** met : http://www.gnu.org/copyleft/gpl.html
**
** If you are unsure which license is appropriate for your use, or
** if you have questions regarding the use of this file, please contact :
** ic-east.com
**
****************************************************************************/
#ifndef _QX_DATA_MEMBER_PIMPL_H_
#define _QX_DATA_MEMBER_PIMPL_H_
#ifdef _MSC_VER
#pragma once
#endif
/*!
* \file QxDataMember_PImpl.h
* \author XDL Team
* \ingroup QxDataMember
* \brief Concrete class property registered into QxOrm context (using private implementation idiom)
*/
#include <QxDataMember/IxDataMember.h>
#define QX_DATA_MEMBER_PIMPL_VIRTUAL_ARCHIVE_HPP(ArchiveInput, ArchiveOutput) \
virtual void toArchive(const void *pOwner, ArchiveOutput &ar) const Q_DECL_OVERRIDE \
{ \
Q_UNUSED(pOwner); \
Q_UNUSED(ar); \
} \
virtual void fromArchive(void *pOwner, ArchiveInput &ar) Q_DECL_OVERRIDE \
{ \
Q_UNUSED(pOwner); \
Q_UNUSED(ar); \
}
namespace qx
{
/*!
* \ingroup QxDataMember
* \brief qx::QxDataMember_PImpl<DataType, Owner> : concrete property of type DataType registered into QxOrm context for the class Owner (using private implementation idiom)
*/
template <typename DataType, class Owner>
class QxDataMember_PImpl : public IxDataMember
{
protected:
typedef DataType Owner::*type_data_member_ptr;
type_data_member_ptr m_pData; //!< Data member under format "& Owner::DataMember"
public:
QxDataMember_PImpl(type_data_member_ptr pData, const QString &sKey) : IxDataMember(sKey, 0, false, false, NULL), m_pData(pData)
{
static_assert(std::is_pointer<DataType>::value, "std::is_pointer<DataType>::value");
this->setAccessDataPointer(true);
}
virtual ~QxDataMember_PImpl() { ; }
virtual bool isEqual(const void *pOwner1, const void *pOwner2) const Q_DECL_OVERRIDE
{
Q_UNUSED(pOwner1);
Q_UNUSED(pOwner2);
return false;
}
virtual QVariant toVariant(const void *pOwner, const QString &sFormat, int iIndexName = -1, qx::cvt::context::ctx_type ctx = qx::cvt::context::e_no_context) const Q_DECL_OVERRIDE
{
Q_UNUSED(pOwner);
Q_UNUSED(sFormat);
Q_UNUSED(iIndexName);
Q_UNUSED(ctx);
return QVariant();
}
virtual qx_bool fromVariant(void *pOwner, const QVariant &v, const QString &sFormat, int iIndexName = -1, qx::cvt::context::ctx_type ctx = qx::cvt::context::e_no_context) Q_DECL_OVERRIDE
{
Q_UNUSED(pOwner);
Q_UNUSED(v);
Q_UNUSED(sFormat);
Q_UNUSED(iIndexName);
Q_UNUSED(ctx);
return qx_bool(true);
}
virtual QString getType() const Q_DECL_OVERRIDE { return QString(); }
#ifndef _QX_NO_JSON
virtual QJsonValue toJson(const void *pOwner, const QString &sFormat) const Q_DECL_OVERRIDE
{
Q_UNUSED(pOwner);
Q_UNUSED(sFormat);
return QJsonValue();
}
virtual qx_bool fromJson(void *pOwner, const QJsonValue &j, const QString &sFormat) Q_DECL_OVERRIDE
{
Q_UNUSED(pOwner);
Q_UNUSED(j);
Q_UNUSED(sFormat);
return qx_bool(true);
}
#endif // _QX_NO_JSON
protected:
inline DataType *getData(void *pOwner) const { return (&((static_cast<Owner *>(pOwner))->*m_pData)); }
inline const DataType *getData(const void *pOwner) const { return (&((static_cast<const Owner *>(pOwner))->*m_pData)); }
virtual qx::any getDataPtr(const void *pOwner) const Q_DECL_FINAL { return (pOwner ? qx::any(*getData(pOwner)) : qx::any()); }
virtual qx::any getDataPtr(void *pOwner) Q_DECL_FINAL { return (pOwner ? qx::any(*getData(pOwner)) : qx::any()); }
virtual void *getDataVoidPtr(const void *pOwner) const Q_DECL_FINAL { return (pOwner ? static_cast<void *>(const_cast<DataType>(*getData(pOwner))) : NULL); }
virtual void *getDataVoidPtr(void *pOwner) Q_DECL_FINAL { return (pOwner ? static_cast<void *>(*getData(pOwner)) : NULL); }
public:
#ifdef _QX_ENABLE_BOOST_SERIALIZATION
#if _QX_SERIALIZE_POLYMORPHIC
QX_DATA_MEMBER_PIMPL_VIRTUAL_ARCHIVE_HPP(boost::archive::polymorphic_iarchive, boost::archive::polymorphic_oarchive)
#endif // _QX_SERIALIZE_POLYMORPHIC
#if _QX_SERIALIZE_BINARY
QX_DATA_MEMBER_PIMPL_VIRTUAL_ARCHIVE_HPP(boost::archive::binary_iarchive, boost::archive::binary_oarchive)
#endif // _QX_SERIALIZE_BINARY
#if _QX_SERIALIZE_TEXT
QX_DATA_MEMBER_PIMPL_VIRTUAL_ARCHIVE_HPP(boost::archive::text_iarchive, boost::archive::text_oarchive)
#endif // _QX_SERIALIZE_TEXT
#if _QX_SERIALIZE_XML
QX_DATA_MEMBER_PIMPL_VIRTUAL_ARCHIVE_HPP(boost::archive::xml_iarchive, boost::archive::xml_oarchive)
#endif // _QX_SERIALIZE_XML
#if _QX_SERIALIZE_PORTABLE_BINARY
QX_DATA_MEMBER_PIMPL_VIRTUAL_ARCHIVE_HPP(eos::portable_iarchive, eos::portable_oarchive)
#endif // _QX_SERIALIZE_PORTABLE_BINARY
#if _QX_SERIALIZE_WIDE_BINARY
QX_DATA_MEMBER_PIMPL_VIRTUAL_ARCHIVE_HPP(boost::archive::binary_wiarchive, boost::archive::binary_woarchive)
#endif // _QX_SERIALIZE_WIDE_BINARY
#if _QX_SERIALIZE_WIDE_TEXT
QX_DATA_MEMBER_PIMPL_VIRTUAL_ARCHIVE_HPP(boost::archive::text_wiarchive, boost::archive::text_woarchive)
#endif // _QX_SERIALIZE_WIDE_TEXT
#if _QX_SERIALIZE_WIDE_XML
QX_DATA_MEMBER_PIMPL_VIRTUAL_ARCHIVE_HPP(boost::archive::xml_wiarchive, boost::archive::xml_woarchive)
#endif // _QX_SERIALIZE_WIDE_XML
#endif // _QX_ENABLE_BOOST_SERIALIZATION
};
template <typename DataType, class Owner>
class QxDataMember_PImpl<std::unique_ptr<DataType>, Owner> : public IxDataMember
{
protected:
typedef std::unique_ptr<DataType> Owner::*type_data_member_ptr;
type_data_member_ptr m_pData; //!< Data member under format "& Owner::DataMember"
public:
QxDataMember_PImpl(type_data_member_ptr pData, const QString &sKey) : IxDataMember(sKey, 0, false, false, NULL), m_pData(pData) { this->setAccessDataPointer(true); }
virtual ~QxDataMember_PImpl() { ; }
virtual bool isEqual(const void *pOwner1, const void *pOwner2) const Q_DECL_OVERRIDE
{
Q_UNUSED(pOwner1);
Q_UNUSED(pOwner2);
return false;
}
virtual QVariant toVariant(const void *pOwner, const QString &sFormat, int iIndexName = -1, qx::cvt::context::ctx_type ctx = qx::cvt::context::e_no_context) const Q_DECL_OVERRIDE
{
Q_UNUSED(pOwner);
Q_UNUSED(sFormat);
Q_UNUSED(iIndexName);
Q_UNUSED(ctx);
return QVariant();
}
virtual qx_bool fromVariant(void *pOwner, const QVariant &v, const QString &sFormat, int iIndexName = -1, qx::cvt::context::ctx_type ctx = qx::cvt::context::e_no_context) Q_DECL_OVERRIDE
{
Q_UNUSED(pOwner);
Q_UNUSED(v);
Q_UNUSED(sFormat);
Q_UNUSED(iIndexName);
Q_UNUSED(ctx);
return qx_bool(true);
}
virtual QString getType() const Q_DECL_OVERRIDE { return QString(); }
#ifndef _QX_NO_JSON
virtual QJsonValue toJson(const void *pOwner, const QString &sFormat) const Q_DECL_OVERRIDE
{
Q_UNUSED(pOwner);
Q_UNUSED(sFormat);
return QJsonValue();
}
virtual qx_bool fromJson(void *pOwner, const QJsonValue &j, const QString &sFormat) Q_DECL_OVERRIDE
{
Q_UNUSED(pOwner);
Q_UNUSED(j);
Q_UNUSED(sFormat);
return qx_bool(true);
}
#endif // _QX_NO_JSON
protected:
inline std::unique_ptr<DataType> *getData(void *pOwner) const { return (&((static_cast<Owner *>(pOwner))->*m_pData)); }
inline const std::unique_ptr<DataType> *getData(const void *pOwner) const { return (&((static_cast<const Owner *>(pOwner))->*m_pData)); }
virtual qx::any getDataPtr(const void *pOwner) const Q_DECL_FINAL { return (pOwner ? qx::any(getData(pOwner)->get()) : qx::any()); }
virtual qx::any getDataPtr(void *pOwner) Q_DECL_FINAL { return (pOwner ? qx::any(getData(pOwner)->get()) : qx::any()); }
virtual void *getDataVoidPtr(const void *pOwner) const Q_DECL_FINAL { return (pOwner ? static_cast<void *>(const_cast<DataType *>(getData(pOwner)->get())) : NULL); }
virtual void *getDataVoidPtr(void *pOwner) Q_DECL_FINAL { return (pOwner ? static_cast<void *>(getData(pOwner)->get()) : NULL); }
public:
#ifdef _QX_ENABLE_BOOST_SERIALIZATION
#if _QX_SERIALIZE_POLYMORPHIC
QX_DATA_MEMBER_PIMPL_VIRTUAL_ARCHIVE_HPP(boost::archive::polymorphic_iarchive, boost::archive::polymorphic_oarchive)
#endif // _QX_SERIALIZE_POLYMORPHIC
#if _QX_SERIALIZE_BINARY
QX_DATA_MEMBER_PIMPL_VIRTUAL_ARCHIVE_HPP(boost::archive::binary_iarchive, boost::archive::binary_oarchive)
#endif // _QX_SERIALIZE_BINARY
#if _QX_SERIALIZE_TEXT
QX_DATA_MEMBER_PIMPL_VIRTUAL_ARCHIVE_HPP(boost::archive::text_iarchive, boost::archive::text_oarchive)
#endif // _QX_SERIALIZE_TEXT
#if _QX_SERIALIZE_XML
QX_DATA_MEMBER_PIMPL_VIRTUAL_ARCHIVE_HPP(boost::archive::xml_iarchive, boost::archive::xml_oarchive)
#endif // _QX_SERIALIZE_XML
#if _QX_SERIALIZE_PORTABLE_BINARY
QX_DATA_MEMBER_PIMPL_VIRTUAL_ARCHIVE_HPP(eos::portable_iarchive, eos::portable_oarchive)
#endif // _QX_SERIALIZE_PORTABLE_BINARY
#if _QX_SERIALIZE_WIDE_BINARY
QX_DATA_MEMBER_PIMPL_VIRTUAL_ARCHIVE_HPP(boost::archive::binary_wiarchive, boost::archive::binary_woarchive)
#endif // _QX_SERIALIZE_WIDE_BINARY
#if _QX_SERIALIZE_WIDE_TEXT
QX_DATA_MEMBER_PIMPL_VIRTUAL_ARCHIVE_HPP(boost::archive::text_wiarchive, boost::archive::text_woarchive)
#endif // _QX_SERIALIZE_WIDE_TEXT
#if _QX_SERIALIZE_WIDE_XML
QX_DATA_MEMBER_PIMPL_VIRTUAL_ARCHIVE_HPP(boost::archive::xml_wiarchive, boost::archive::xml_woarchive)
#endif // _QX_SERIALIZE_WIDE_XML
#endif // _QX_ENABLE_BOOST_SERIALIZATION
};
template <typename DataType, class Owner>
class QxDataMember_PImpl<std::shared_ptr<DataType>, Owner> : public IxDataMember
{
protected:
typedef std::shared_ptr<DataType> Owner::*type_data_member_ptr;
type_data_member_ptr m_pData; //!< Data member under format "& Owner::DataMember"
public:
QxDataMember_PImpl(type_data_member_ptr pData, const QString &sKey) : IxDataMember(sKey, 0, false, false, NULL), m_pData(pData) { this->setAccessDataPointer(true); }
virtual ~QxDataMember_PImpl() { ; }
virtual bool isEqual(const void *pOwner1, const void *pOwner2) const Q_DECL_OVERRIDE
{
Q_UNUSED(pOwner1);
Q_UNUSED(pOwner2);
return false;
}
virtual QVariant toVariant(const void *pOwner, const QString &sFormat, int iIndexName = -1, qx::cvt::context::ctx_type ctx = qx::cvt::context::e_no_context) const Q_DECL_OVERRIDE
{
Q_UNUSED(pOwner);
Q_UNUSED(sFormat);
Q_UNUSED(iIndexName);
Q_UNUSED(ctx);
return QVariant();
}
virtual qx_bool fromVariant(void *pOwner, const QVariant &v, const QString &sFormat, int iIndexName = -1, qx::cvt::context::ctx_type ctx = qx::cvt::context::e_no_context) Q_DECL_OVERRIDE
{
Q_UNUSED(pOwner);
Q_UNUSED(v);
Q_UNUSED(sFormat);
Q_UNUSED(iIndexName);
Q_UNUSED(ctx);
return qx_bool(true);
}
virtual QString getType() const Q_DECL_OVERRIDE { return QString(); }
#ifndef _QX_NO_JSON
virtual QJsonValue toJson(const void *pOwner, const QString &sFormat) const Q_DECL_OVERRIDE
{
Q_UNUSED(pOwner);
Q_UNUSED(sFormat);
return QJsonValue();
}
virtual qx_bool fromJson(void *pOwner, const QJsonValue &j, const QString &sFormat) Q_DECL_OVERRIDE
{
Q_UNUSED(pOwner);
Q_UNUSED(j);
Q_UNUSED(sFormat);
return qx_bool(true);
}
#endif // _QX_NO_JSON
protected:
inline std::shared_ptr<DataType> *getData(void *pOwner) const { return (&((static_cast<Owner *>(pOwner))->*m_pData)); }
inline const std::shared_ptr<DataType> *getData(const void *pOwner) const { return (&((static_cast<const Owner *>(pOwner))->*m_pData)); }
virtual qx::any getDataPtr(const void *pOwner) const Q_DECL_FINAL { return (pOwner ? qx::any(getData(pOwner)->get()) : qx::any()); }
virtual qx::any getDataPtr(void *pOwner) Q_DECL_FINAL { return (pOwner ? qx::any(getData(pOwner)->get()) : qx::any()); }
virtual void *getDataVoidPtr(const void *pOwner) const Q_DECL_FINAL { return (pOwner ? static_cast<void *>(const_cast<DataType *>(getData(pOwner)->get())) : NULL); }
virtual void *getDataVoidPtr(void *pOwner) Q_DECL_FINAL { return (pOwner ? static_cast<void *>(getData(pOwner)->get()) : NULL); }
public:
#ifdef _QX_ENABLE_BOOST_SERIALIZATION
#if _QX_SERIALIZE_POLYMORPHIC
QX_DATA_MEMBER_PIMPL_VIRTUAL_ARCHIVE_HPP(boost::archive::polymorphic_iarchive, boost::archive::polymorphic_oarchive)
#endif // _QX_SERIALIZE_POLYMORPHIC
#if _QX_SERIALIZE_BINARY
QX_DATA_MEMBER_PIMPL_VIRTUAL_ARCHIVE_HPP(boost::archive::binary_iarchive, boost::archive::binary_oarchive)
#endif // _QX_SERIALIZE_BINARY
#if _QX_SERIALIZE_TEXT
QX_DATA_MEMBER_PIMPL_VIRTUAL_ARCHIVE_HPP(boost::archive::text_iarchive, boost::archive::text_oarchive)
#endif // _QX_SERIALIZE_TEXT
#if _QX_SERIALIZE_XML
QX_DATA_MEMBER_PIMPL_VIRTUAL_ARCHIVE_HPP(boost::archive::xml_iarchive, boost::archive::xml_oarchive)
#endif // _QX_SERIALIZE_XML
#if _QX_SERIALIZE_PORTABLE_BINARY
QX_DATA_MEMBER_PIMPL_VIRTUAL_ARCHIVE_HPP(eos::portable_iarchive, eos::portable_oarchive)
#endif // _QX_SERIALIZE_PORTABLE_BINARY
#if _QX_SERIALIZE_WIDE_BINARY
QX_DATA_MEMBER_PIMPL_VIRTUAL_ARCHIVE_HPP(boost::archive::binary_wiarchive, boost::archive::binary_woarchive)
#endif // _QX_SERIALIZE_WIDE_BINARY
#if _QX_SERIALIZE_WIDE_TEXT
QX_DATA_MEMBER_PIMPL_VIRTUAL_ARCHIVE_HPP(boost::archive::text_wiarchive, boost::archive::text_woarchive)
#endif // _QX_SERIALIZE_WIDE_TEXT
#if _QX_SERIALIZE_WIDE_XML
QX_DATA_MEMBER_PIMPL_VIRTUAL_ARCHIVE_HPP(boost::archive::xml_wiarchive, boost::archive::xml_woarchive)
#endif // _QX_SERIALIZE_WIDE_XML
#endif // _QX_ENABLE_BOOST_SERIALIZATION
};
} // namespace qx
#endif // _QX_DATA_MEMBER_PIMPL_H_

View File

@@ -0,0 +1,132 @@
/****************************************************************************
**
** https://www.qxorm.com/
** Copyright (C) 2013 XDL Team (ic-east.com)
**
** This file is part of the QxOrm library
**
** This software is provided 'as-is', without any express or implied
** warranty. In no event will the authors be held liable for any
** damages arising from the use of this software
**
** Commercial Usage
** Licensees holding valid commercial QxOrm licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and XDL Team
**
** GNU General Public License Usage
** Alternatively, this file may be used under the terms of the GNU
** General Public License version 3.0 as published by the Free Software
** Foundation and appearing in the file 'license.gpl3.txt' included in the
** packaging of this file. Please review the following information to
** ensure the GNU General Public License version 3.0 requirements will be
** met : http://www.gnu.org/copyleft/gpl.html
**
** If you are unsure which license is appropriate for your use, or
** if you have questions regarding the use of this file, please contact :
** ic-east.com
**
****************************************************************************/
#ifndef _QX_DATA_MEMBER_QOBJECT_H_
#define _QX_DATA_MEMBER_QOBJECT_H_
#ifdef _MSC_VER
#pragma once
#endif
/*!
* \file QxDataMember_QObject.h
* \author XDL Team
* \ingroup QxDataMember
* \brief Connect Qt introspection engine (based on QObject class, with QMetaObject type) to QxOrm library introspection engine
*/
#include <QtCore/qmetaobject.h>
#include <QtCore/qmetatype.h>
#include <QxDataMember/IxDataMember.h>
#include <QxSerialize/Qt/QxSerialize_QString.h>
#include <QxSerialize/Qt/QxSerialize_QVariant.h>
#define QX_DATA_MEMBER_QOBJECT_IMPL_VIRTUAL_ARCHIVE_HPP(ArchiveInput, ArchiveOutput) \
virtual void toArchive(const void *pOwner, ArchiveOutput &ar) const; \
virtual void fromArchive(void *pOwner, ArchiveInput &ar);
namespace qx
{
/*!
* \ingroup QxDataMember
* \brief qx::QxDataMember_QObject : connect Qt introspection engine (based on QObject class, with QMetaObject type) to QxOrm library introspection engine
*/
class QX_DLL_EXPORT QxDataMember_QObject : public IxDataMember
{
protected:
const QMetaObject *m_metaObject; //!< Meta-object from introspection engine of Qt library (& MyQObject::staticMetaObject)
QMetaProperty m_metaProperty; //!< Meta-property from introspection engine of Qt library
public:
QxDataMember_QObject(const QMetaObject *pMetaObject, const QString &sKey);
virtual ~QxDataMember_QObject() { ; }
virtual bool isEqual(const void *pOwner1, const void *pOwner2) const;
virtual QVariant toVariant(const void *pOwner, const QString &sFormat, int iIndexName = -1, qx::cvt::context::ctx_type ctx = qx::cvt::context::e_no_context) const;
virtual qx_bool fromVariant(void *pOwner, const QVariant &v, const QString &sFormat, int iIndexName = -1, qx::cvt::context::ctx_type ctx = qx::cvt::context::e_no_context);
virtual QString getType() const;
#ifndef _QX_NO_JSON
virtual QJsonValue toJson(const void *pOwner, const QString &sFormat) const;
virtual qx_bool fromJson(void *pOwner, const QJsonValue &j, const QString &sFormat);
#endif // _QX_NO_JSON
public:
#ifdef _QX_ENABLE_BOOST_SERIALIZATION
#if _QX_SERIALIZE_POLYMORPHIC
QX_DATA_MEMBER_QOBJECT_IMPL_VIRTUAL_ARCHIVE_HPP(boost::archive::polymorphic_iarchive, boost::archive::polymorphic_oarchive)
#endif // _QX_SERIALIZE_POLYMORPHIC
#if _QX_SERIALIZE_BINARY
QX_DATA_MEMBER_QOBJECT_IMPL_VIRTUAL_ARCHIVE_HPP(boost::archive::binary_iarchive, boost::archive::binary_oarchive)
#endif // _QX_SERIALIZE_BINARY
#if _QX_SERIALIZE_TEXT
QX_DATA_MEMBER_QOBJECT_IMPL_VIRTUAL_ARCHIVE_HPP(boost::archive::text_iarchive, boost::archive::text_oarchive)
#endif // _QX_SERIALIZE_TEXT
#if _QX_SERIALIZE_XML
QX_DATA_MEMBER_QOBJECT_IMPL_VIRTUAL_ARCHIVE_HPP(boost::archive::xml_iarchive, boost::archive::xml_oarchive)
#endif // _QX_SERIALIZE_XML
#if _QX_SERIALIZE_PORTABLE_BINARY
QX_DATA_MEMBER_QOBJECT_IMPL_VIRTUAL_ARCHIVE_HPP(eos::portable_iarchive, eos::portable_oarchive)
#endif // _QX_SERIALIZE_PORTABLE_BINARY
#if _QX_SERIALIZE_WIDE_BINARY
QX_DATA_MEMBER_QOBJECT_IMPL_VIRTUAL_ARCHIVE_HPP(boost::archive::binary_wiarchive, boost::archive::binary_woarchive)
#endif // _QX_SERIALIZE_WIDE_BINARY
#if _QX_SERIALIZE_WIDE_TEXT
QX_DATA_MEMBER_QOBJECT_IMPL_VIRTUAL_ARCHIVE_HPP(boost::archive::text_wiarchive, boost::archive::text_woarchive)
#endif // _QX_SERIALIZE_WIDE_TEXT
#if _QX_SERIALIZE_WIDE_XML
QX_DATA_MEMBER_QOBJECT_IMPL_VIRTUAL_ARCHIVE_HPP(boost::archive::xml_wiarchive, boost::archive::xml_woarchive)
#endif // _QX_SERIALIZE_WIDE_XML
#endif // _QX_ENABLE_BOOST_SERIALIZATION
protected:
virtual qx::any getDataPtr(const void *pOwner) const;
virtual qx::any getDataPtr(void *pOwner);
virtual void *getDataVoidPtr(const void *pOwner) const;
virtual void *getDataVoidPtr(void *pOwner);
};
} // namespace qx
#endif // _QX_DATA_MEMBER_QOBJECT_H_