EasyQtSql_ParamDirectionWrapper.h 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. #ifndef EASYQTSQL_PARAMETERWRAPPER_H
  2. #define EASYQTSQL_PARAMETERWRAPPER_H
  3. /*
  4. * The MIT License (MIT)
  5. * Copyright 2018 Alexey Kramin
  6. *
  7. * Permission is hereby granted, free of charge, to any person obtaining
  8. * a copy of this software and associated documentation files (the
  9. * "Software"), to deal in the Software without restriction, including
  10. * without limitation the rights to use, copy, modify, merge, publish,
  11. * distribute, sublicense, and/or sell copies of the Software, and to
  12. * permit persons to whom the Software is furnished to do so, subject to
  13. * the following conditions:
  14. *
  15. * The above copyright notice and this permission notice shall be
  16. * included in all copies or substantial portions of the Software.
  17. *
  18. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  19. * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  20. * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  21. * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
  22. * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
  23. * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
  24. * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  25. *
  26. */
  27. #ifndef EASY_QT_SQL_MAIN
  28. #include <QtCore>
  29. #endif
  30. /*!
  31. * \brief Base parameters wrapper struct
  32. *
  33. * The ParamDirectionWrapper struct is pure-virtual
  34. */
  35. struct ParamDirectionWrapper
  36. {
  37. ParamDirectionWrapper(const QVariant &val, const QString &aliasName)
  38. : value(val)
  39. , alias(aliasName.trimmed())
  40. { }
  41. virtual ~ParamDirectionWrapper() {}
  42. const QVariant value;
  43. const QString alias;
  44. /*!
  45. * \brief Protection against instantiating the class
  46. */
  47. virtual void doesNothing() const = 0;
  48. };
  49. /*!
  50. * \brief Input SQL parameters wrapper
  51. */
  52. struct In : public ParamDirectionWrapper
  53. {
  54. In(const QVariant &value, const QString &alias = QString())
  55. : ParamDirectionWrapper(value, alias.trimmed().toLower())
  56. { }
  57. /*!
  58. * \brief Does nothing
  59. */
  60. virtual void doesNothing() const override {}
  61. };
  62. /*!
  63. * \brief Output SQL parameters wrapper
  64. */
  65. struct Out : public ParamDirectionWrapper
  66. {
  67. explicit Out(const QString &alias)
  68. : ParamDirectionWrapper(QVariant(), alias)
  69. { }
  70. /*!
  71. * \brief Does nothing
  72. */
  73. virtual void doesNothing() const override {}
  74. };
  75. /*!
  76. * \brief Bidirectional SQL parameters wrapper
  77. */
  78. struct InOut : public ParamDirectionWrapper
  79. {
  80. InOut(const QVariant &value, const QString &alias)
  81. : ParamDirectionWrapper(value, alias)
  82. { }
  83. /*!
  84. * \brief Does nothing
  85. */
  86. virtual void doesNothing() const override {}
  87. };
  88. #endif // EASYQTSQL_PARAMETERWRAPPER_H