IxValidatorX.h 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. /****************************************************************************
  2. **
  3. ** https://www.qxorm.com/
  4. ** Copyright (C) 2013 Lionel Marty (contact@qxorm.com)
  5. **
  6. ** This file is part of the QxOrm library
  7. **
  8. ** This software is provided 'as-is', without any express or implied
  9. ** warranty. In no event will the authors be held liable for any
  10. ** damages arising from the use of this software
  11. **
  12. ** Commercial Usage
  13. ** Licensees holding valid commercial QxOrm licenses may use this file in
  14. ** accordance with the commercial license agreement provided with the
  15. ** Software or, alternatively, in accordance with the terms contained in
  16. ** a written agreement between you and Lionel Marty
  17. **
  18. ** GNU General Public License Usage
  19. ** Alternatively, this file may be used under the terms of the GNU
  20. ** General Public License version 3.0 as published by the Free Software
  21. ** Foundation and appearing in the file 'license.gpl3.txt' included in the
  22. ** packaging of this file. Please review the following information to
  23. ** ensure the GNU General Public License version 3.0 requirements will be
  24. ** met : http://www.gnu.org/copyleft/gpl.html
  25. **
  26. ** If you are unsure which license is appropriate for your use, or
  27. ** if you have questions regarding the use of this file, please contact :
  28. ** contact@qxorm.com
  29. **
  30. ****************************************************************************/
  31. #ifndef _IX_VALIDATOR_X_H_
  32. #define _IX_VALIDATOR_X_H_
  33. #ifdef _MSC_VER
  34. #pragma once
  35. #endif
  36. /*!
  37. * \file IxValidatorX.h
  38. * \author Lionel Marty
  39. * \ingroup QxValidator
  40. * \brief Common interface for a list of validators
  41. */
  42. #include <QxCollection/QxCollection.h>
  43. #include <QxValidator/IxValidator.h>
  44. namespace qx {
  45. class IxClass;
  46. class IxDataMember;
  47. class QxInvalidValueX;
  48. /*!
  49. * \ingroup QxValidator
  50. * \brief qx::IxValidatorX : common interface for a list of validators
  51. *
  52. * 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> :
  53. * <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>
  54. */
  55. class QX_DLL_EXPORT IxValidatorX
  56. {
  57. friend class IxClass;
  58. protected:
  59. typedef QList<IxValidator_ptr> type_lst_validator;
  60. typedef std::shared_ptr<type_lst_validator> type_lst_validator_ptr;
  61. typedef QxCollection<QString, type_lst_validator_ptr> type_lst_validator_ptr_by_group;
  62. type_lst_validator_ptr_by_group m_lstValidatorByGroup; //!< List of validator by group
  63. IxClass * m_pClass; //!< Class registered into QxOrm context
  64. public:
  65. IxValidatorX();
  66. virtual ~IxValidatorX() = 0;
  67. QxInvalidValueX validate(void * pOwner, const QString & sGroup = QString()) const;
  68. IxValidator * add_NotNull(const QString & sPropertyKey, const QString & sMessage = QString(), const QString & sGroup = QString());
  69. IxValidator * add_NotEmpty(const QString & sPropertyKey, const QString & sMessage = QString(), const QString & sGroup = QString());
  70. IxValidator * add_MinValue(const QString & sPropertyKey, long lMinValue, const QString & sMessage = QString(), const QString & sGroup = QString());
  71. IxValidator * add_MaxValue(const QString & sPropertyKey, long lMaxValue, const QString & sMessage = QString(), const QString & sGroup = QString());
  72. IxValidator * add_Range(const QString & sPropertyKey, long lMinValue, long lMaxValue, const QString & sMessage = QString(), const QString & sGroup = QString());
  73. IxValidator * add_MinDecimal(const QString & sPropertyKey, double dMinValue, const QString & sMessage = QString(), const QString & sGroup = QString());
  74. IxValidator * add_MaxDecimal(const QString & sPropertyKey, double dMaxValue, const QString & sMessage = QString(), const QString & sGroup = QString());
  75. IxValidator * add_RangeDecimal(const QString & sPropertyKey, double dMinValue, double dMaxValue, const QString & sMessage = QString(), const QString & sGroup = QString());
  76. IxValidator * add_MinLength(const QString & sPropertyKey, long lMinLength, const QString & sMessage = QString(), const QString & sGroup = QString());
  77. IxValidator * add_MaxLength(const QString & sPropertyKey, long lMaxLength, const QString & sMessage = QString(), const QString & sGroup = QString());
  78. IxValidator * add_Size(const QString & sPropertyKey, long lMinLength, long lMaxLength, const QString & sMessage = QString(), const QString & sGroup = QString());
  79. IxValidator * add_DatePast(const QString & sPropertyKey, const QString & sMessage = QString(), const QString & sGroup = QString());
  80. IxValidator * add_DateFuture(const QString & sPropertyKey, const QString & sMessage = QString(), const QString & sGroup = QString());
  81. IxValidator * add_RegExp(const QString & sPropertyKey, const QString & sPattern, const QString & sMessage = QString(), const QString & sGroup = QString());
  82. IxValidator * add_EMail(const QString & sPropertyKey, const QString & sMessage = QString(), const QString & sGroup = QString());
  83. QStringList getAllGroup() const;
  84. QList<IxValidator_ptr> getAllValidatorByGroup(const QString & group) const;
  85. protected:
  86. void setClass(IxClass * p);
  87. void insertIntoGroup(IxValidator_ptr pValidator, const QString & sGroup);
  88. IxValidator_ptr createValidator(IxValidator::validator_type type, const QString & sPropertyKey, const QString & sMessage, const QString & sGroup);
  89. IxDataMember * getDataMember(const QString & sPropertyKey) const;
  90. };
  91. typedef std::shared_ptr<IxValidatorX> IxValidatorX_ptr;
  92. } // namespace qx
  93. #endif // _IX_VALIDATOR_X_H_