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,130 @@
/****************************************************************************
**
** 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_VALIDATOR_H_
#define _IX_VALIDATOR_H_
#ifdef _MSC_VER
#pragma once
#endif
/*!
* \file IxValidator.h
* \author XDL Team
* \ingroup QxValidator
* \brief Common interface for validator engine
*/
#include <QxCommon/QxPropertyBag.h>
namespace qx
{
class IxDataMember;
class QxInvalidValueX;
/*!
* \ingroup QxValidator
* \brief qx::IxValidator : common interface for validator engine
*
* For more informations about <b>QxValidator module</b>, <a href="https://www.qxorm.com/qxorm_en/faq.html#faq_250" target="_blank">goto the FAQ of QxOrm website</a> :
* <a href="https://www.qxorm.com/qxorm_en/faq.html#faq_250" target="_blank">https://www.qxorm.com/qxorm_en/faq.html#faq_250</a>
*/
class QX_DLL_EXPORT IxValidator : public QxPropertyBag
{
public:
enum validator_type
{
not_null,
not_empty,
min_value,
max_value,
min_length,
max_length,
date_past,
date_future,
min_decimal,
max_decimal,
regular_expression,
e_mail,
recursive_validator,
custom_validator
};
protected:
validator_type m_type; //!< Validator type
QString m_message; //!< Validator message when invalid value is detected
QString m_group; //!< Validator group
QVariantList m_Constraints; //!< List of constraints to verify
IxDataMember *m_pDataMember; //!< Registered property associated to validator
public:
IxValidator(validator_type type);
virtual ~IxValidator();
validator_type getType() const;
QString getMessage() const;
QString getGroup() const;
QVariant getConstraint() const;
QVariantList getConstraints() const;
IxDataMember *getDataMember() const;
void setMessage(const QString &s);
void setGroup(const QString &s);
void setConstraint(const QVariant &v);
void setConstraints(const QVariantList &lst);
void setDataMember(IxDataMember *p);
virtual void validate(void *pOwner, QxInvalidValueX &lstInvalidValues) const;
protected:
void initDefaultMessage();
void validateNotNull(const QVariant &v, QxInvalidValueX &lstInvalidValues) const;
void validateNotEmpty(const QVariant &v, QxInvalidValueX &lstInvalidValues) const;
void validateMinValue(const QVariant &v, QxInvalidValueX &lstInvalidValues) const;
void validateMaxValue(const QVariant &v, QxInvalidValueX &lstInvalidValues) const;
void validateMinDecimal(const QVariant &v, QxInvalidValueX &lstInvalidValues) const;
void validateMaxDecimal(const QVariant &v, QxInvalidValueX &lstInvalidValues) const;
void validateMinLength(const QVariant &v, QxInvalidValueX &lstInvalidValues) const;
void validateMaxLength(const QVariant &v, QxInvalidValueX &lstInvalidValues) const;
void validateDatePast(const QVariant &v, QxInvalidValueX &lstInvalidValues) const;
void validateDateFuture(const QVariant &v, QxInvalidValueX &lstInvalidValues) const;
void validateRegularExpression(const QVariant &v, QxInvalidValueX &lstInvalidValues) const;
void validateEMail(const QVariant &v, QxInvalidValueX &lstInvalidValues) const;
};
typedef std::shared_ptr<IxValidator> IxValidator_ptr;
} // namespace qx
#endif // _IX_VALIDATOR_H_

View File

@@ -0,0 +1,113 @@
/****************************************************************************
**
** 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_VALIDATOR_X_H_
#define _IX_VALIDATOR_X_H_
#ifdef _MSC_VER
#pragma once
#endif
/*!
* \file IxValidatorX.h
* \author XDL Team
* \ingroup QxValidator
* \brief Common interface for a list of validators
*/
#include <QxCollection/QxCollection.h>
#include <QxValidator/IxValidator.h>
namespace qx
{
class IxClass;
class IxDataMember;
class QxInvalidValueX;
/*!
* \ingroup QxValidator
* \brief qx::IxValidatorX : common interface for a list of validators
*
* For more informations about <b>QxValidator module</b>, <a href="https://www.qxorm.com/qxorm_en/faq.html#faq_250" target="_blank">goto the FAQ of QxOrm website</a> :
* <a href="https://www.qxorm.com/qxorm_en/faq.html#faq_250" target="_blank">https://www.qxorm.com/qxorm_en/faq.html#faq_250</a>
*/
class QX_DLL_EXPORT IxValidatorX
{
friend class IxClass;
protected:
typedef QList<IxValidator_ptr> type_lst_validator;
typedef std::shared_ptr<type_lst_validator> type_lst_validator_ptr;
typedef QxCollection<QString, type_lst_validator_ptr> type_lst_validator_ptr_by_group;
type_lst_validator_ptr_by_group m_lstValidatorByGroup; //!< List of validator by group
IxClass *m_pClass; //!< Class registered into QxOrm context
public:
IxValidatorX();
virtual ~IxValidatorX() = 0;
QxInvalidValueX validate(void *pOwner, const QString &sGroup = QString()) const;
IxValidator *add_NotNull(const QString &sPropertyKey, const QString &sMessage = QString(), const QString &sGroup = QString());
IxValidator *add_NotEmpty(const QString &sPropertyKey, const QString &sMessage = QString(), const QString &sGroup = QString());
IxValidator *add_MinValue(const QString &sPropertyKey, long lMinValue, const QString &sMessage = QString(), const QString &sGroup = QString());
IxValidator *add_MaxValue(const QString &sPropertyKey, long lMaxValue, const QString &sMessage = QString(), const QString &sGroup = QString());
IxValidator *add_Range(const QString &sPropertyKey, long lMinValue, long lMaxValue, const QString &sMessage = QString(), const QString &sGroup = QString());
IxValidator *add_MinDecimal(const QString &sPropertyKey, double dMinValue, const QString &sMessage = QString(), const QString &sGroup = QString());
IxValidator *add_MaxDecimal(const QString &sPropertyKey, double dMaxValue, const QString &sMessage = QString(), const QString &sGroup = QString());
IxValidator *add_RangeDecimal(const QString &sPropertyKey, double dMinValue, double dMaxValue, const QString &sMessage = QString(), const QString &sGroup = QString());
IxValidator *add_MinLength(const QString &sPropertyKey, long lMinLength, const QString &sMessage = QString(), const QString &sGroup = QString());
IxValidator *add_MaxLength(const QString &sPropertyKey, long lMaxLength, const QString &sMessage = QString(), const QString &sGroup = QString());
IxValidator *add_Size(const QString &sPropertyKey, long lMinLength, long lMaxLength, const QString &sMessage = QString(), const QString &sGroup = QString());
IxValidator *add_DatePast(const QString &sPropertyKey, const QString &sMessage = QString(), const QString &sGroup = QString());
IxValidator *add_DateFuture(const QString &sPropertyKey, const QString &sMessage = QString(), const QString &sGroup = QString());
IxValidator *add_RegExp(const QString &sPropertyKey, const QString &sPattern, const QString &sMessage = QString(), const QString &sGroup = QString());
IxValidator *add_EMail(const QString &sPropertyKey, const QString &sMessage = QString(), const QString &sGroup = QString());
QStringList getAllGroup() const;
QList<IxValidator_ptr> getAllValidatorByGroup(const QString &group) const;
protected:
void setClass(IxClass *p);
void insertIntoGroup(IxValidator_ptr pValidator, const QString &sGroup);
IxValidator_ptr createValidator(IxValidator::validator_type type, const QString &sPropertyKey, const QString &sMessage, const QString &sGroup);
IxDataMember *getDataMember(const QString &sPropertyKey) const;
};
typedef std::shared_ptr<IxValidatorX> IxValidatorX_ptr;
} // namespace qx
#endif // _IX_VALIDATOR_X_H_

View File

@@ -0,0 +1,160 @@
/****************************************************************************
**
** 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_VALIDATOR_INVALID_VALUE_H_
#define _QX_VALIDATOR_INVALID_VALUE_H_
#ifdef _MSC_VER
#pragma once
#endif
/*!
* \file QxInvalidValue.h
* \author XDL Team
* \ingroup QxValidator
* \brief Invalid value when a property fails to pass a constraint
*/
#ifdef _QX_ENABLE_BOOST_SERIALIZATION
#include <boost/serialization/serialization.hpp>
#include <boost/serialization/nvp.hpp>
#endif // _QX_ENABLE_BOOST_SERIALIZATION
#ifndef _QX_NO_JSON
#include <QtCore/qjsonvalue.h>
#endif // _QX_NO_JSON
#include <QxSerialize/boost/QxSerialize_shared_ptr.h>
#include <QxSerialize/Qt/QxSerialize_QString.h>
#include <QxSerialize/Qt/QxSerialize_QVariant.h>
#include <QxSerialize/Qt/QxSerialize_QHash.h>
#include <QxConvert/QxConvert.h>
#include <QxTraits/get_class_name.h>
#include <QxCommon/QxPropertyBag.h>
namespace qx
{
class IxValidator;
class QxInvalidValue;
} // namespace qx
QX_DLL_EXPORT QDataStream &operator<<(QDataStream &stream, const qx::QxInvalidValue &t) QX_USED;
QX_DLL_EXPORT QDataStream &operator>>(QDataStream &stream, qx::QxInvalidValue &t) QX_USED;
#ifndef _QX_NO_JSON
namespace qx
{
namespace cvt
{
namespace detail
{
template <>
struct QxConvert_ToJson<qx::QxInvalidValue>;
template <>
struct QxConvert_FromJson<qx::QxInvalidValue>;
QX_DLL_EXPORT QJsonValue QxConvert_ToJson_Helper(const qx::QxInvalidValue &t, const QString &format) QX_USED;
QX_DLL_EXPORT qx_bool QxConvert_FromJson_Helper(const QJsonValue &j, qx::QxInvalidValue &t, const QString &format) QX_USED;
} // namespace detail
} // namespace cvt
} // namespace qx
#endif // _QX_NO_JSON
namespace qx
{
/*!
* \ingroup QxValidator
* \brief qx::QxInvalidValue : invalid value when a property fails to pass a constraint
*
* For more informations about <b>QxValidator module</b>, <a href="https://www.qxorm.com/qxorm_en/faq.html#faq_250" target="_blank">goto the FAQ of QxOrm website</a> :
* <a href="https://www.qxorm.com/qxorm_en/faq.html#faq_250" target="_blank">https://www.qxorm.com/qxorm_en/faq.html#faq_250</a>
*/
class QX_DLL_EXPORT QxInvalidValue : public QxPropertyBag
{
#ifdef _QX_ENABLE_BOOST_SERIALIZATION
friend class boost::serialization::access;
#endif // _QX_ENABLE_BOOST_SERIALIZATION
friend QX_DLL_EXPORT QDataStream & ::operator<<(QDataStream &stream, const qx::QxInvalidValue &t);
friend QX_DLL_EXPORT QDataStream & ::operator>>(QDataStream &stream, qx::QxInvalidValue &t);
#ifndef _QX_NO_JSON
friend struct qx::cvt::detail::QxConvert_ToJson<qx::QxInvalidValue>;
friend struct qx::cvt::detail::QxConvert_FromJson<qx::QxInvalidValue>;
friend QX_DLL_EXPORT QJsonValue qx::cvt::detail::QxConvert_ToJson_Helper(const qx::QxInvalidValue &t, const QString &format);
friend QX_DLL_EXPORT qx_bool qx::cvt::detail::QxConvert_FromJson_Helper(const QJsonValue &j, qx::QxInvalidValue &t, const QString &format);
#endif // _QX_NO_JSON
protected:
QString m_sMessage; //!< Message associated to the invalid value
QString m_sPropertyName; //!< Property name failing to pass the constraint
QString m_sPath; //!< Path of property failing to pass the constraint
const IxValidator *m_pValidator; //!< IxValidator class associated to the invalid value
public:
QxInvalidValue();
virtual ~QxInvalidValue();
QString getMessage() const { return m_sMessage; }
QString getPropertyName() const { return m_sPropertyName; }
QString getPath() const { return m_sPath; }
QString getFullName() const;
const IxValidator *getValidator() const;
void setMessage(const QString &s) { m_sMessage = s; }
void setPropertyName(const QString &s) { m_sPropertyName = s; }
void setPath(const QString &s) { m_sPath = s; }
void setValidator(const IxValidator *p);
private:
#ifdef _QX_ENABLE_BOOST_SERIALIZATION
template <class Archive>
void serialize(Archive &ar, const unsigned int file_version)
{
Q_UNUSED(file_version);
ar &boost::serialization::make_nvp("message", m_sMessage);
ar &boost::serialization::make_nvp("property_name", m_sPropertyName);
ar &boost::serialization::make_nvp("path", m_sPath);
ar &boost::serialization::make_nvp("list_property_bag", this->m_lstPropertyBag);
}
#endif // _QX_ENABLE_BOOST_SERIALIZATION
};
} // namespace qx
QX_REGISTER_CLASS_NAME(qx::QxInvalidValue)
#endif // _QX_VALIDATOR_INVALID_VALUE_H_

View File

@@ -0,0 +1,159 @@
/****************************************************************************
**
** 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_VALIDATOR_INVALID_VALUE_X_H_
#define _QX_VALIDATOR_INVALID_VALUE_X_H_
#ifdef _MSC_VER
#pragma once
#endif
/*!
* \file QxInvalidValueX.h
* \author XDL Team
* \ingroup QxValidator
* \brief List of invalid values
*/
#ifdef _QX_ENABLE_BOOST_SERIALIZATION
#include <boost/serialization/serialization.hpp>
#include <boost/serialization/nvp.hpp>
#endif // _QX_ENABLE_BOOST_SERIALIZATION
#ifndef _QX_NO_JSON
#include <QtCore/qjsonvalue.h>
#endif // _QX_NO_JSON
#include <QxSerialize/Qt/QxSerialize_QString.h>
#include <QxSerialize/Qt/QxSerialize_QList.h>
#include <QxValidator/QxInvalidValue.h>
#include <QxConvert/QxConvert.h>
#include <QxTraits/get_class_name.h>
namespace qx
{
class QxInvalidValueX;
} // namespace qx
QX_DLL_EXPORT QDataStream &operator<<(QDataStream &stream, const qx::QxInvalidValueX &t) QX_USED;
QX_DLL_EXPORT QDataStream &operator>>(QDataStream &stream, qx::QxInvalidValueX &t) QX_USED;
#ifndef _QX_NO_JSON
namespace qx
{
namespace cvt
{
namespace detail
{
template <>
struct QxConvert_ToJson<qx::QxInvalidValueX>;
template <>
struct QxConvert_FromJson<qx::QxInvalidValueX>;
QX_DLL_EXPORT QJsonValue QxConvert_ToJson_Helper(const qx::QxInvalidValueX &t, const QString &format) QX_USED;
QX_DLL_EXPORT qx_bool QxConvert_FromJson_Helper(const QJsonValue &j, qx::QxInvalidValueX &t, const QString &format) QX_USED;
} // namespace detail
} // namespace cvt
} // namespace qx
#endif // _QX_NO_JSON
namespace qx
{
/*!
* \ingroup QxValidator
* \brief qx::QxInvalidValueX : list of invalid values
*
* For more informations about <b>QxValidator module</b>, <a href="https://www.qxorm.com/qxorm_en/faq.html#faq_250" target="_blank">goto the FAQ of QxOrm website</a> :
* <a href="https://www.qxorm.com/qxorm_en/faq.html#faq_250" target="_blank">https://www.qxorm.com/qxorm_en/faq.html#faq_250</a>
*/
class QX_DLL_EXPORT QxInvalidValueX
{
#ifdef _QX_ENABLE_BOOST_SERIALIZATION
friend class boost::serialization::access;
#endif // _QX_ENABLE_BOOST_SERIALIZATION
friend QX_DLL_EXPORT QDataStream & ::operator<<(QDataStream &stream, const qx::QxInvalidValueX &t);
friend QX_DLL_EXPORT QDataStream & ::operator>>(QDataStream &stream, qx::QxInvalidValueX &t);
#ifndef _QX_NO_JSON
friend struct qx::cvt::detail::QxConvert_ToJson<qx::QxInvalidValueX>;
friend struct qx::cvt::detail::QxConvert_FromJson<qx::QxInvalidValueX>;
friend QX_DLL_EXPORT QJsonValue qx::cvt::detail::QxConvert_ToJson_Helper(const qx::QxInvalidValueX &t, const QString &format);
friend QX_DLL_EXPORT qx_bool qx::cvt::detail::QxConvert_FromJson_Helper(const QJsonValue &j, qx::QxInvalidValueX &t, const QString &format);
#endif // _QX_NO_JSON
protected:
QList<QxInvalidValue> m_lstInvalidValues; //!< List of invalid values
QString m_sCurrentPath; //!< Current path of validation process
public:
QxInvalidValueX();
virtual ~QxInvalidValueX();
QString getCurrentPath() const;
void setCurrentPath(const QString &s);
long count() const;
QxInvalidValue at(long l) const;
void insert(const IxValidator *pValidator);
void insert(const QString &sMessage);
void insert(const QxInvalidValue &invalidValue);
void insert(const QxInvalidValueX &other);
QString text() const;
void dump() const;
inline operator bool() const
{
return (m_lstInvalidValues.count() == 0);
}
private:
#ifdef _QX_ENABLE_BOOST_SERIALIZATION
template <class Archive>
void serialize(Archive &ar, const unsigned int file_version)
{
Q_UNUSED(file_version);
ar &boost::serialization::make_nvp("list_invalid_values", m_lstInvalidValues);
ar &boost::serialization::make_nvp("current_path", m_sCurrentPath);
}
#endif // _QX_ENABLE_BOOST_SERIALIZATION
};
} // namespace qx
QX_REGISTER_CLASS_NAME(qx::QxInvalidValueX)
#endif // _QX_VALIDATOR_INVALID_VALUE_X_H_

View File

@@ -0,0 +1,186 @@
/****************************************************************************
**
** 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_VALIDATOR_H_
#define _QX_VALIDATOR_H_
#ifdef _MSC_VER
#pragma once
#endif
/*!
* \file QxValidator.h
* \author XDL Team
* \ingroup QxValidator
* \brief Concrete class for a custom or recursive validator
*/
#include <QxValidator/IxValidator.h>
#include <QxValidator/QxInvalidValueX.h>
#include <QxDataMember/IxDataMember.h>
namespace qx
{
template <class T>
QxInvalidValueX validate(T &t, const QString &group);
/*!
* \ingroup QxValidator
* \brief qx::QxValidator<Owner> : concrete class for a custom validator
*
* For more informations about <b>QxValidator module</b>, <a href="https://www.qxorm.com/qxorm_en/faq.html#faq_250" target="_blank">goto the FAQ of QxOrm website</a> :
* <a href="https://www.qxorm.com/qxorm_en/faq.html#faq_250" target="_blank">https://www.qxorm.com/qxorm_en/faq.html#faq_250</a>
*/
template <class Owner>
class QxValidator : public IxValidator
{
public:
typedef std::function<void(Owner *, QxInvalidValueX &)> type_fct_custom_validator_member;
typedef std::function<void(const QVariant &, QxInvalidValueX &)> type_fct_custom_validator_variant;
typedef std::function<void(const QVariant &, const IxValidator *, QxInvalidValueX &)> type_fct_custom_validator_variant_validator;
protected:
type_fct_custom_validator_member m_fctCustomValidator_Member; //!< Custom validator function : class method
type_fct_custom_validator_variant m_fctCustomValidator_Variant; //!< Custom validator function : global function with value converted to QVariant type
type_fct_custom_validator_variant_validator m_fctCustomValidator_VariantValidator; //!< Custom validator function : global function with value converted to QVariant type and a IxValidator pointer containing all parameters
public:
QxValidator() : IxValidator(IxValidator::custom_validator) { ; }
virtual ~QxValidator() { ; }
void setFunction(type_fct_custom_validator_member fct) { m_fctCustomValidator_Member = fct; }
void setFunction(type_fct_custom_validator_variant fct) { m_fctCustomValidator_Variant = fct; }
void setFunction(type_fct_custom_validator_variant_validator fct) { m_fctCustomValidator_VariantValidator = fct; }
virtual void validate(void *pOwner, QxInvalidValueX &lstInvalidValues) const
{
if (m_fctCustomValidator_Member)
{
m_fctCustomValidator_Member(static_cast<Owner *>(pOwner), lstInvalidValues);
}
else if (m_fctCustomValidator_Variant && m_pDataMember)
{
m_fctCustomValidator_Variant(m_pDataMember->toVariant(pOwner), lstInvalidValues);
}
else if (m_fctCustomValidator_VariantValidator && m_pDataMember)
{
m_fctCustomValidator_VariantValidator(m_pDataMember->toVariant(pOwner), this, lstInvalidValues);
}
}
};
/*!
* \ingroup QxValidator
* \brief qx::QxValidator_WithDataType<DataType, Owner> : concrete class for a custom validator with data type
*
* For more informations about <b>QxValidator module</b>, <a href="https://www.qxorm.com/qxorm_en/faq.html#faq_250" target="_blank">goto the FAQ of QxOrm website</a> :
* <a href="https://www.qxorm.com/qxorm_en/faq.html#faq_250" target="_blank">https://www.qxorm.com/qxorm_en/faq.html#faq_250</a>
*/
template <typename DataType, class Owner>
class QxValidator_WithDataType : public IxValidator
{
public:
typedef std::function<void(const DataType &, QxInvalidValueX &)> type_fct_custom_validator_data_type;
typedef std::function<void(const DataType &, const IxValidator *, QxInvalidValueX &)> type_fct_custom_validator_data_type_validator;
protected:
type_fct_custom_validator_data_type m_fctCustomValidator_DataType; //!< Custom validator function : global function with value
type_fct_custom_validator_data_type_validator m_fctCustomValidator_DataTypeValidator; //!< Custom validator function : global function with value and a IxValidator pointer containing all parameters
public:
QxValidator_WithDataType() : IxValidator(IxValidator::custom_validator) { ; }
virtual ~QxValidator_WithDataType() { ; }
void setFunction(type_fct_custom_validator_data_type fct) { m_fctCustomValidator_DataType = fct; }
void setFunction(type_fct_custom_validator_data_type_validator fct) { m_fctCustomValidator_DataTypeValidator = fct; }
virtual void validate(void *pOwner, QxInvalidValueX &lstInvalidValues) const
{
if (!m_pDataMember)
{
return;
}
IxDataMember *pDataMember = const_cast<IxDataMember *>(m_pDataMember);
DataType *val = pDataMember->getValuePtr<DataType>(pOwner);
if (m_fctCustomValidator_DataType && val)
{
m_fctCustomValidator_DataType((*val), lstInvalidValues);
}
else if (m_fctCustomValidator_DataTypeValidator && val)
{
m_fctCustomValidator_DataTypeValidator((*val), this, lstInvalidValues);
}
}
};
/*!
* \ingroup QxValidator
* \brief qx::QxValidator_Recursive<DataType, Owner> : concrete class for a recursive validator
*
* For more informations about <b>QxValidator module</b>, <a href="https://www.qxorm.com/qxorm_en/faq.html#faq_250" target="_blank">goto the FAQ of QxOrm website</a> :
* <a href="https://www.qxorm.com/qxorm_en/faq.html#faq_250" target="_blank">https://www.qxorm.com/qxorm_en/faq.html#faq_250</a>
*/
template <typename DataType, class Owner>
class QxValidator_Recursive : public IxValidator
{
public:
QxValidator_Recursive() : IxValidator(IxValidator::recursive_validator) { ; }
virtual ~QxValidator_Recursive() { ; }
virtual void validate(void *pOwner, QxInvalidValueX &lstInvalidValues) const
{
if (!m_pDataMember)
{
qAssert(false);
return;
}
IxDataMember *pDataMember = const_cast<IxDataMember *>(m_pDataMember);
DataType *val = pDataMember->getValuePtr<DataType>(pOwner);
if (!val)
{
qAssert(false);
return;
}
QxInvalidValueX invalidValues;
invalidValues.setCurrentPath(m_pDataMember->getName());
invalidValues.insert(qx::validate((*val), m_group));
lstInvalidValues.insert(invalidValues);
}
};
} // namespace qx
#endif // _QX_VALIDATOR_H_

View File

@@ -0,0 +1,84 @@
/****************************************************************************
**
** 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_VALIDATOR_ERROR_H_
#define _QX_VALIDATOR_ERROR_H_
#ifdef _MSC_VER
#pragma once
#endif
/*!
* \file QxValidatorError.h
* \author XDL Team
* \ingroup QxValidator
* \brief Define a validator error exception (for example, inserting or updating an element into database) and retrieve list of invalid values
*/
#include <iostream>
#include <exception>
#include <QxValidator/QxInvalidValueX.h>
namespace qx
{
/*!
* \ingroup QxValidator
* \brief qx::validator_error : define a validator error exception (for example, inserting or updating an element into database) and retrieve list of invalid values
*
* For more informations about <b>QxValidator module</b>, <a href="https://www.qxorm.com/qxorm_en/faq.html#faq_250" target="_blank">goto the FAQ of QxOrm website</a> :
* <a href="https://www.qxorm.com/qxorm_en/faq.html#faq_250" target="_blank">https://www.qxorm.com/qxorm_en/faq.html#faq_250</a>
*/
class validator_error : public std::exception
{
private:
QxInvalidValueX m_lstInvalidValues;
public:
validator_error(const QxInvalidValueX &err) : std::exception(), m_lstInvalidValues(err) { ; }
virtual ~validator_error() throw() { ; }
virtual const char *what() const throw()
{
return qPrintable(m_lstInvalidValues.text());
}
QxInvalidValueX get() const
{
return m_lstInvalidValues;
}
};
} // namespace qx
#endif // _QX_VALIDATOR_ERROR_H_

View File

@@ -0,0 +1,232 @@
/****************************************************************************
**
** 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_VALIDATOR_FUNCTION_H_
#define _QX_VALIDATOR_FUNCTION_H_
#ifdef _MSC_VER
#pragma once
#endif
/*!
* \file QxValidatorFct.h
* \author XDL Team
* \ingroup QxValidator
* \brief Implementation of qx::validate<T>() function (validator engine)
*/
#include <QxValidator/IxValidatorX.h>
#include <QxValidator/QxInvalidValueX.h>
#include <QxRegister/QxClass.h>
#include <QxTraits/is_container.h>
#include <QxTraits/is_smart_ptr.h>
#include <QxTraits/is_qx_registered.h>
namespace qx
{
template <class T>
QxInvalidValueX validate(T &t, const QString &group);
} // namespace qx
namespace qx
{
namespace validator
{
namespace detail
{
template <class T>
struct QxValidator_Helper_Generic
{
static inline qx::QxInvalidValueX validate(T &t, const QString &group)
{
static_assert(qx::trait::is_qx_registered<T>::value, "qx::trait::is_qx_registered<T>::value");
qx::QxInvalidValueX invalidValues;
qx::IxClass *pClass = qx::QxClass<T>::getSingleton();
if (!pClass)
{
qAssert(false);
return invalidValues;
}
qx::IxValidatorX *pAllValidator = pClass->getAllValidator();
if (!pAllValidator)
{
return invalidValues;
}
invalidValues.setCurrentPath(pClass->getName());
invalidValues.insert(pAllValidator->validate((&t), group));
return invalidValues;
}
};
template <class T>
struct QxValidator_Helper_Container
{
static inline qx::QxInvalidValueX validate(T &t, const QString &group)
{
qx::QxInvalidValueX invalidValues;
long lIndex = 0;
for (typename T::iterator it = t.begin(); it != t.end(); ++it)
{
invalidValues.setCurrentPath("[" + QString::number(lIndex) + "]");
invalidValues.insert(validateItem((*it), group));
lIndex++;
}
return invalidValues;
}
private:
template <typename U>
static inline qx::QxInvalidValueX validateItem(U &item, const QString &group)
{
return validateItem_Helper < U, std::is_pointer<U>::value || qx::trait::is_smart_ptr<U>::value > ::validate(item, group);
}
template <typename U, bool bIsPointer /* = true */>
struct validateItem_Helper
{
static inline qx::QxInvalidValueX validate(U &item, const QString &group)
{
return (item ? qx::validator::detail::QxValidator_Helper_Container<T>::validateItem((*item), group) : qx::QxInvalidValueX());
}
};
template <typename U1, typename U2>
struct validateItem_Helper<std::pair<U1, U2>, false>
{
static inline qx::QxInvalidValueX validate(std::pair<U1, U2> &item, const QString &group)
{
return qx::validator::detail::QxValidator_Helper_Container<T>::validateItem(item.second, group);
}
};
template <typename U1, typename U2>
struct validateItem_Helper<const std::pair<U1, U2>, false>
{
static inline qx::QxInvalidValueX validate(const std::pair<U1, U2> &item, const QString &group)
{
return qx::validator::detail::QxValidator_Helper_Container<T>::validateItem(item.second, group);
}
};
#if (QT_VERSION < QT_VERSION_CHECK(6, 0, 0))
template <typename U1, typename U2>
struct validateItem_Helper<QPair<U1, U2>, false>
{
static inline qx::QxInvalidValueX validate(QPair<U1, U2> &item, const QString &group)
{
return qx::validator::detail::QxValidator_Helper_Container<T>::validateItem(item.second, group);
}
};
template <typename U1, typename U2>
struct validateItem_Helper<const QPair<U1, U2>, false>
{
static inline qx::QxInvalidValueX validate(const QPair<U1, U2> &item, const QString &group)
{
return qx::validator::detail::QxValidator_Helper_Container<T>::validateItem(item.second, group);
}
};
#endif // (QT_VERSION < QT_VERSION_CHECK(6, 0, 0))
template <typename U>
struct validateItem_Helper<U, false>
{
static qx::QxInvalidValueX validate(U &item, const QString &group) { return qx::validate(item, group); }
};
};
template <class T>
struct QxValidator_Helper_Ptr
{
static inline qx::QxInvalidValueX validate(T &t, const QString &group)
{
return (t ? qx::validate((*t), group) : qx::QxInvalidValueX());
}
};
template <class T>
struct QxValidator_Helper
{
static inline qx::QxInvalidValueX validate(T &t, const QString &group)
{
typedef typename std::conditional<std::is_pointer<T>::value, qx::validator::detail::QxValidator_Helper_Ptr<T>, qx::validator::detail::QxValidator_Helper_Generic<T>>::type type_validator_1;
typedef typename std::conditional<qx::trait::is_smart_ptr<T>::value, qx::validator::detail::QxValidator_Helper_Ptr<T>, type_validator_1>::type type_validator_2;
typedef typename std::conditional<qx::trait::is_container<T>::value, qx::validator::detail::QxValidator_Helper_Container<T>, type_validator_2>::type type_validator_3;
return type_validator_3::validate(t, group);
}
};
} // namespace detail
} // namespace validator
} // namespace qx
namespace qx
{
template <class T>
QxInvalidValueX validate(T &t, const QString &group)
{
return qx::validator::detail::QxValidator_Helper<T>::validate(t, group);
}
template <class T>
QxInvalidValueX validate(T &t)
{
return qx::validator::detail::QxValidator_Helper<T>::validate(t, "");
}
template <class T>
QxInvalidValueX validate(T &t, const QStringList &groups)
{
QxInvalidValueX invalidValues;
if (groups.count() <= 0)
{
return qx::validate(t);
}
for (long l = 0; l < groups.count(); l++)
{
invalidValues.insert(qx::validate(t, groups.at(l)));
}
return invalidValues;
}
} // namespace qx
#endif // _QX_VALIDATOR_FUNCTION_H_

View File

@@ -0,0 +1,116 @@
/****************************************************************************
**
** 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_VALIDATOR_X_H_
#define _QX_VALIDATOR_X_H_
#ifdef _MSC_VER
#pragma once
#endif
/*!
* \file QxValidatorX.h
* \author XDL Team
* \ingroup QxValidator
* \brief Concrete class for a list of validators associated to a type registered into QxOrm context
*/
#include <QxValidator/IxValidatorX.h>
#include <QxValidator/QxValidator.h>
#include <QxRegister/QxClassX.h>
namespace qx
{
/*!
* \ingroup QxValidator
* \brief qx::QxValidatorX<T> : concrete class for a list of validators associated to a type registered into QxOrm context
*
* For more informations about <b>QxValidator module</b>, <a href="https://www.qxorm.com/qxorm_en/faq.html#faq_250" target="_blank">goto the FAQ of QxOrm website</a> :
* <a href="https://www.qxorm.com/qxorm_en/faq.html#faq_250" target="_blank">https://www.qxorm.com/qxorm_en/faq.html#faq_250</a>
*/
template <class T>
class QxValidatorX : public IxValidatorX
{
public:
QxValidatorX() : IxValidatorX() { ; }
virtual ~QxValidatorX() { ; }
template <class DataType>
IxValidator *add_RecursiveValidator(const QString &sPropertyKey, const QString &sGroup = QString())
{
IxValidator_ptr pValidator = std::make_shared<QxValidator_Recursive<DataType, T>>();
pValidator->setGroup(sGroup);
pValidator->setDataMember(getDataMember(sPropertyKey));
insertIntoGroup(pValidator, sGroup);
return pValidator.get();
}
IxValidator *add_CustomValidator(typename QxValidator<T>::type_fct_custom_validator_member fct, const QString &sGroup = QString())
{
return add_CustomValidator_Helper(new QxValidator<T>(), fct, "", sGroup);
}
IxValidator *add_CustomValidator_QVariant(typename QxValidator<T>::type_fct_custom_validator_variant_validator fct, const QString &sPropertyKey, const QString &sGroup = QString())
{
return add_CustomValidator_Helper(new QxValidator<T>(), fct, sPropertyKey, sGroup);
}
template <class DataType>
IxValidator *add_CustomValidator_DataType(typename QxValidator_WithDataType<DataType, T>::type_fct_custom_validator_data_type_validator fct, const QString &sPropertyKey, const QString &sGroup = QString())
{
return add_CustomValidator_Helper(new QxValidator_WithDataType<DataType, T>(), fct, sPropertyKey, sGroup);
}
private:
template <class Validator, class FunctionType>
IxValidator *add_CustomValidator_Helper(Validator *validator, FunctionType fct, const QString &sPropertyKey, const QString &sGroup)
{
if (!validator)
{
qAssert(false);
return NULL;
}
IxValidator_ptr pValidator;
pValidator.reset(validator);
validator->setGroup(sGroup);
validator->setFunction(fct);
validator->setDataMember(getDataMember(sPropertyKey));
insertIntoGroup(pValidator, sGroup);
return pValidator.get();
}
};
} // namespace qx
#endif // _QX_VALIDATOR_X_H_