QxInvalidValueX.h 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  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 _QX_VALIDATOR_INVALID_VALUE_X_H_
  32. #define _QX_VALIDATOR_INVALID_VALUE_X_H_
  33. #ifdef _MSC_VER
  34. #pragma once
  35. #endif
  36. /*!
  37. * \file QxInvalidValueX.h
  38. * \author Lionel Marty
  39. * \ingroup QxValidator
  40. * \brief List of invalid values
  41. */
  42. #ifdef _QX_ENABLE_BOOST_SERIALIZATION
  43. #include <boost/serialization/serialization.hpp>
  44. #include <boost/serialization/nvp.hpp>
  45. #endif // _QX_ENABLE_BOOST_SERIALIZATION
  46. #ifndef _QX_NO_JSON
  47. #include <QtCore/qjsonvalue.h>
  48. #endif // _QX_NO_JSON
  49. #include <QxSerialize/Qt/QxSerialize_QString.h>
  50. #include <QxSerialize/Qt/QxSerialize_QList.h>
  51. #include <QxValidator/QxInvalidValue.h>
  52. #include <QxConvert/QxConvert.h>
  53. #include <QxTraits/get_class_name.h>
  54. namespace qx {
  55. class QxInvalidValueX;
  56. } // namespace qx
  57. QX_DLL_EXPORT QDataStream & operator<< (QDataStream & stream, const qx::QxInvalidValueX & t) QX_USED;
  58. QX_DLL_EXPORT QDataStream & operator>> (QDataStream & stream, qx::QxInvalidValueX & t) QX_USED;
  59. #ifndef _QX_NO_JSON
  60. namespace qx {
  61. namespace cvt {
  62. namespace detail {
  63. template <> struct QxConvert_ToJson< qx::QxInvalidValueX >;
  64. template <> struct QxConvert_FromJson< qx::QxInvalidValueX >;
  65. QX_DLL_EXPORT QJsonValue QxConvert_ToJson_Helper(const qx::QxInvalidValueX & t, const QString & format) QX_USED;
  66. QX_DLL_EXPORT qx_bool QxConvert_FromJson_Helper(const QJsonValue & j, qx::QxInvalidValueX & t, const QString & format) QX_USED;
  67. } // namespace detail
  68. } // namespace cvt
  69. } // namespace qx
  70. #endif // _QX_NO_JSON
  71. namespace qx {
  72. /*!
  73. * \ingroup QxValidator
  74. * \brief qx::QxInvalidValueX : list of invalid values
  75. *
  76. * 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> :
  77. * <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>
  78. */
  79. class QX_DLL_EXPORT QxInvalidValueX
  80. {
  81. #ifdef _QX_ENABLE_BOOST_SERIALIZATION
  82. friend class boost::serialization::access;
  83. #endif // _QX_ENABLE_BOOST_SERIALIZATION
  84. friend QX_DLL_EXPORT QDataStream & ::operator<< (QDataStream & stream, const qx::QxInvalidValueX & t);
  85. friend QX_DLL_EXPORT QDataStream & ::operator>> (QDataStream & stream, qx::QxInvalidValueX & t);
  86. #ifndef _QX_NO_JSON
  87. friend struct qx::cvt::detail::QxConvert_ToJson< qx::QxInvalidValueX >;
  88. friend struct qx::cvt::detail::QxConvert_FromJson< qx::QxInvalidValueX >;
  89. friend QX_DLL_EXPORT QJsonValue qx::cvt::detail::QxConvert_ToJson_Helper(const qx::QxInvalidValueX & t, const QString & format);
  90. friend QX_DLL_EXPORT qx_bool qx::cvt::detail::QxConvert_FromJson_Helper(const QJsonValue & j, qx::QxInvalidValueX & t, const QString & format);
  91. #endif // _QX_NO_JSON
  92. protected:
  93. QList<QxInvalidValue> m_lstInvalidValues; //!< List of invalid values
  94. QString m_sCurrentPath; //!< Current path of validation process
  95. public:
  96. QxInvalidValueX();
  97. virtual ~QxInvalidValueX();
  98. QString getCurrentPath() const;
  99. void setCurrentPath(const QString & s);
  100. long count() const;
  101. QxInvalidValue at(long l) const;
  102. void insert(const IxValidator * pValidator);
  103. void insert(const QString & sMessage);
  104. void insert(const QxInvalidValue & invalidValue);
  105. void insert(const QxInvalidValueX & other);
  106. QString text() const;
  107. void dump() const;
  108. inline operator bool() const
  109. { return (m_lstInvalidValues.count() == 0); }
  110. private:
  111. #ifdef _QX_ENABLE_BOOST_SERIALIZATION
  112. template <class Archive>
  113. void serialize(Archive & ar, const unsigned int file_version)
  114. {
  115. Q_UNUSED(file_version);
  116. ar & boost::serialization::make_nvp("list_invalid_values", m_lstInvalidValues);
  117. ar & boost::serialization::make_nvp("current_path", m_sCurrentPath);
  118. }
  119. #endif // _QX_ENABLE_BOOST_SERIALIZATION
  120. };
  121. } // namespace qx
  122. QX_REGISTER_CLASS_NAME(qx::QxInvalidValueX)
  123. #endif // _QX_VALIDATOR_INVALID_VALUE_X_H_