選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

126 行
3.0 KiB

  1. #pragma once
  2. #include <string>
  3. #include <limits>
  4. #include <memory>
  5. #include <cppmariadb/config.h>
  6. #include <cppmariadb/impl/handle.h>
  7. namespace cppmariadb
  8. {
  9. namespace __impl
  10. {
  11. template<typename T>
  12. struct row_iterator;
  13. }
  14. /**
  15. * @brief Represents a row inside the result set.
  16. */
  17. struct row
  18. : public __impl::handle<MYSQL_ROW>
  19. {
  20. public:
  21. using iterator_type = __impl::row_iterator<field>;
  22. using const_iterator_type = __impl::row_iterator<const field>;
  23. static constexpr size_t npos = std::numeric_limits<size_t>::max();
  24. private:
  25. const result& _result; //!< Result this row belongs to.
  26. mutable unsigned long* _lengths; //!< Number of fields stored in this row.
  27. public:
  28. /**
  29. * @brief Constructor to create a row from a mariadb handle.
  30. *
  31. * @param[in] p_result Result this row belongs to.
  32. * @param[in] p_row Row handle from mariadb.
  33. */
  34. inline row(const result& p_result, MYSQL_ROW p_row);
  35. public:
  36. /**
  37. * @brief Access operator to get the field at the given index.
  38. */
  39. inline field operator[](size_t i) const;
  40. /**
  41. * @brief Access operator to get the field with the given name.
  42. */
  43. inline field operator[](const std::string& name) const;
  44. public:
  45. /**
  46. * @brief Get the columns that belong to this rows.
  47. */
  48. inline const column_vector& columns() const;
  49. /**
  50. * @brief Get the number of fields stored in this row.
  51. */
  52. inline unsigned int size() const;
  53. /**
  54. * @brief Get the begin iterator.
  55. */
  56. inline iterator_type begin() const;
  57. /**
  58. * @brief Get the end iterator.
  59. */
  60. inline iterator_type end() const;
  61. /**
  62. * @brief Get the const begin iterator.
  63. */
  64. inline const_iterator_type cbegin() const;
  65. /**
  66. * @brief Get the const end iterator.
  67. */
  68. inline const_iterator_type cend() const;
  69. /**
  70. * @brief Get the reverse begin iterator.
  71. */
  72. inline iterator_type rbegin() const;
  73. /**
  74. * @brief Get the reverse end iterator.
  75. */
  76. inline iterator_type rend() const;
  77. /**
  78. * @brief Get the const reverse begin iterator.
  79. */
  80. inline const_iterator_type crbegin() const;
  81. /**
  82. * @brief Get the const reverse end iterator.
  83. */
  84. inline const_iterator_type crend() const;
  85. public:
  86. /**
  87. * @brief Get the index of a field by its name.
  88. */
  89. size_t find(const std::string& name) const;
  90. /**
  91. * @brief Get the field at the given index.
  92. */
  93. field at(size_t i) const;
  94. /**
  95. * @brief Get the field with the given name.
  96. */
  97. field at(const std::string name) const;
  98. };
  99. }