|
||||
File indexing completed on 2024-11-15 09:19:40
0001 // 0002 // Copyright (c) 2019-2023 Ruben Perez Hidalgo (rubenperez038 at gmail dot com) 0003 // 0004 // Distributed under the Boost Software License, Version 1.0. (See accompanying 0005 // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) 0006 // 0007 0008 #ifndef BOOST_MYSQL_ROW_HPP 0009 #define BOOST_MYSQL_ROW_HPP 0010 0011 #include <boost/mysql/field.hpp> 0012 #include <boost/mysql/field_view.hpp> 0013 #include <boost/mysql/row_view.hpp> 0014 0015 #include <boost/mysql/detail/row_impl.hpp> 0016 0017 #include <cstddef> 0018 #include <vector> 0019 0020 namespace boost { 0021 namespace mysql { 0022 0023 /** 0024 * \brief An owning, read-only sequence of fields. 0025 * \details 0026 * Although owning, `row` is read-only. It's optimized for memory re-use. If you need to mutate 0027 * fields, use a `std::vector<field>` instead (see \ref row_view::as_vector and \ref 0028 * row::as_vector). 0029 * 0030 * \par Object lifetimes 0031 * A `row` object owns a chunk of memory in which it stores its elements. On element access (using 0032 * iterators, \ref row::at or \ref row::operator[]) it returns \ref field_view's pointing into the 0033 * `row`'s internal storage. These views behave like references, and are valid as long as pointers, 0034 * iterators and references into the `row` remain valid. 0035 */ 0036 class row 0037 { 0038 detail::row_impl impl_; 0039 0040 public: 0041 #ifdef BOOST_MYSQL_DOXYGEN 0042 /** 0043 * \brief A random access iterator to an element. 0044 * \details The exact type of the iterator is unspecified. 0045 */ 0046 using iterator = __see_below__; 0047 #else 0048 using iterator = const field_view*; 0049 #endif 0050 0051 /// \copydoc iterator 0052 using const_iterator = iterator; 0053 0054 /// A type that can hold elements in this collection with value semantics. 0055 using value_type = field; 0056 0057 /// The reference type. 0058 using reference = field_view; 0059 0060 /// \copydoc reference 0061 using const_reference = field_view; 0062 0063 /// An unsigned integer type to represent sizes. 0064 using size_type = std::size_t; 0065 0066 /// A signed integer type used to represent differences. 0067 using difference_type = std::ptrdiff_t; 0068 0069 /** 0070 * \brief Constructs an empty row. 0071 * \par Exception safety 0072 * No-throw guarantee. 0073 */ 0074 row() = default; 0075 0076 /** 0077 * \brief Copy constructor. 0078 * \par Exception safety 0079 * Strong guarantee. Internal allocations may throw. 0080 * 0081 * \par Object lifetimes 0082 * `*this` lifetime will be independent of `other`'s. 0083 * 0084 * \par Complexity 0085 * Linear on `other.size()`. 0086 */ 0087 row(const row& other) = default; 0088 0089 /** 0090 * \brief Move constructor. 0091 * \par Exception safety 0092 * No-throw guarantee. 0093 * 0094 * \par Object lifetimes 0095 * Iterators and references (including \ref row_view's and \ref field_view's) to 0096 * elements in `other` remain valid. 0097 * 0098 * \par Complexity 0099 * Constant. 0100 */ 0101 row(row&& other) = default; 0102 0103 /** 0104 * \brief Copy assignment. 0105 * \par Exception safety 0106 * Basic guarantee. Internal allocations may throw. 0107 * 0108 * \par Object lifetimes 0109 * `*this` lifetime will be independent of `other`'s. Iterators and references 0110 * (including \ref row_view's and \ref field_view's) to elements in `*this` are invalidated. 0111 * 0112 * \par Complexity 0113 * Linear on `this->size()` and `other.size()`. 0114 */ 0115 row& operator=(const row& other) = default; 0116 0117 /** 0118 * \brief Move assignment. 0119 * \par Exception safety 0120 * No-throw guarantee. 0121 * 0122 * \par Object lifetimes 0123 * Iterators and references (including \ref row_view's and \ref field_view's) to 0124 * elements in `*this` are invalidated. Iterators and references to elements in `other` remain 0125 * valid. 0126 * 0127 * \par Complexity 0128 * Constant. 0129 */ 0130 row& operator=(row&& other) = default; 0131 0132 /** 0133 * \brief Destructor. 0134 */ 0135 ~row() = default; 0136 0137 /** 0138 * \brief Constructs a row from a \ref row_view. 0139 * \par Exception safety 0140 * Strong guarantee. Internal allocations may throw. 0141 * 0142 * \par Object lifetimes 0143 * `*this` lifetime will be independent of `r`'s (the contents of `r` will be copied 0144 * into `*this`). 0145 * 0146 * \par Complexity 0147 * Linear on `r.size()`. 0148 */ 0149 row(row_view r) : impl_(r.begin(), r.size()) {} 0150 0151 /** 0152 * \brief Replaces the contents with a \ref row_view. 0153 * \par Exception safety 0154 * Basic guarantee. Internal allocations may throw. 0155 * 0156 * \par Object lifetimes 0157 * `*this` lifetime will be independent of `r`'s (the contents of `r` will be copied 0158 * into `*this`). Iterators and references (including \ref row_view's and \ref field_view's) to 0159 * elements in `*this` are invalidated. 0160 * 0161 * \par Complexity 0162 * Linear on `this->size()` and `r.size()`. 0163 */ 0164 row& operator=(row_view r) 0165 { 0166 impl_.assign(r.begin(), r.size()); 0167 return *this; 0168 } 0169 0170 /// \copydoc row_view::begin 0171 const_iterator begin() const noexcept { return impl_.fields().data(); } 0172 0173 /// \copydoc row_view::end 0174 const_iterator end() const noexcept { return impl_.fields().data() + impl_.fields().size(); } 0175 0176 /// \copydoc row_view::at 0177 field_view at(std::size_t i) const { return impl_.fields().at(i); } 0178 0179 /// \copydoc row_view::operator[] 0180 field_view operator[](std::size_t i) const noexcept { return impl_.fields()[i]; } 0181 0182 /// \copydoc row_view::front 0183 field_view front() const noexcept { return impl_.fields().front(); } 0184 0185 /// \copydoc row_view::back 0186 field_view back() const noexcept { return impl_.fields().back(); } 0187 0188 /// \copydoc row_view::empty 0189 bool empty() const noexcept { return impl_.fields().empty(); } 0190 0191 /// \copydoc row_view::size 0192 std::size_t size() const noexcept { return impl_.fields().size(); } 0193 0194 /** 0195 * \brief Creates a \ref row_view that references `*this`. 0196 * \par Exception safety 0197 * No-throw guarantee. 0198 * 0199 * \par Object lifetimes 0200 * The returned view will be valid until any function that invalidates iterators and 0201 * references is invoked on `*this` or `*this` is destroyed. 0202 * 0203 * \par Complexity 0204 * Constant. 0205 */ 0206 operator row_view() const noexcept { return row_view(impl_.fields().data(), impl_.fields().size()); } 0207 0208 /// \copydoc row_view::as_vector 0209 template <class Allocator> 0210 void as_vector(std::vector<field, Allocator>& out) const 0211 { 0212 out.assign(begin(), end()); 0213 } 0214 0215 /// \copydoc row_view::as_vector 0216 std::vector<field> as_vector() const { return std::vector<field>(begin(), end()); } 0217 }; 0218 0219 /** 0220 * \relates row 0221 * \brief Equality operator. 0222 * \details The containers are considered equal if they have the same number of elements and they 0223 * all compare equal, as defined by \ref field_view::operator==. 0224 * 0225 * \par Exception safety 0226 * No-throw guarantee. 0227 * 0228 * \par Complexity 0229 * Linear in `lhs.size()` and `rhs.size()`. 0230 */ 0231 inline bool operator==(const row& lhs, const row& rhs) noexcept { return row_view(lhs) == row_view(rhs); } 0232 0233 /** 0234 * \relates row 0235 * \brief Inequality operator. 0236 * 0237 * \par Exception safety 0238 * No-throw guarantee. 0239 * 0240 * \par Complexity 0241 * Linear in `lhs.size()` and `rhs.size()`. 0242 */ 0243 inline bool operator!=(const row& lhs, const row& rhs) { return !(lhs == rhs); } 0244 0245 /** 0246 * \relates row 0247 * \copydoc row::operator==(const row&,const row&) 0248 */ 0249 inline bool operator==(const row& lhs, const row_view& rhs) noexcept { return row_view(lhs) == rhs; } 0250 0251 /** 0252 * \relates row 0253 * \copydoc row::operator!=(const row&,const row&) 0254 */ 0255 inline bool operator!=(const row& lhs, const row_view& rhs) noexcept { return !(lhs == rhs); } 0256 0257 /** 0258 * \relates row 0259 * \copydoc row::operator==(const row&,const row&) 0260 */ 0261 inline bool operator==(const row_view& lhs, const row& rhs) noexcept { return lhs == row_view(rhs); } 0262 0263 /** 0264 * \relates row 0265 * \copydoc row::operator!=(const row&,const row&) 0266 */ 0267 inline bool operator!=(const row_view& lhs, const row& rhs) noexcept { return !(lhs == rhs); } 0268 0269 } // namespace mysql 0270 } // namespace boost 0271 0272 #endif
[ Source navigation ] | [ Diff markup ] | [ Identifier search ] | [ general search ] |
This page was automatically generated by the 2.3.7 LXR engine. The LXR team |