3 #include <ozo/impl/result.h>
4 #include <boost/iterator/iterator_facade.hpp>
22 #ifndef OZO_DOCUMENTATION
23 template <
typename Result>
33 value(
const coordinates& v) noexcept : v_(v) {}
41 return impl::field_type(res(), column());
52 return impl::field_format(res(), column()) == impl::result_format::text;
63 return impl::field_format(res(), column()) == impl::result_format::binary;
72 const char*
data() const noexcept {
73 return impl::get_value(res(),
row(), column());
82 std::size_t
size() const noexcept {
83 return impl::get_length(res(),
row(), column());
93 return impl::get_isnull(res(),
row(), column());
97 int column() const noexcept {
return v_.col;}
98 int row() const noexcept {
return v_.row;}
99 const Result& res() const noexcept {
return *(v_.res);}
109 #ifndef OZO_DOCUMENTATION
110 template <
typename Result>
115 using coordinates =
typename value::coordinates;
117 #ifdef OZO_DOCUMENTATION
131 boost::random_access_traversal_tag,
140 value dereference()
const noexcept {
return {v_}; }
143 return v_.res == rhs.v_.res && v_.col == rhs.v_.col && v_.row == rhs.v_.row;
146 void increment() noexcept { advance(1); }
147 void decrement() noexcept { advance(-1); }
148 void advance(
int n) noexcept { v_.col += n; }
150 int distance_to(
const const_iterator& z) noexcept {
return z.col - v_.col; }
152 coordinates v_ {
nullptr, 0, 0};
154 friend class boost::iterator_core_access;
162 row(
const coordinates& first) noexcept : first_(first) {}
186 int i = impl::field_number(*(first_.res), name);
187 return i == -1 ?
end() :
begin() + i;
206 std::size_t
size() const noexcept {
return impl::nfields(*(first_.res)); }
214 [[nodiscard]]
bool empty() const noexcept {
return size() == 0; }
225 if (index < 0 ||
static_cast<std::size_t
>(index) >=
size()) {
226 throw std::out_of_range(
"ozo::row::at() field index "
227 + std::to_string(index) +
" out of range");
229 return (*
this)[index];
243 throw std::out_of_range(std::string(
"ozo::row::at() no such field name ")
262 template <
typename T>
265 using handle_type = T;
266 using native_handle_type = decltype(std::addressof(*std::declval<handle_type>()));
269 using coordinates =
typename row::coordinates;
271 #ifdef OZO_DOCUMENTATION
285 boost::random_access_traversal_tag,
294 row dereference()
const noexcept {
return {v_}; }
297 return v_.res == rhs.v_.res && v_.row == rhs.v_.row;
300 void increment() noexcept { advance(1); }
301 void decrement() noexcept { advance(-1); }
302 void advance(
int n) noexcept { v_.row += n; }
304 int distance_to(
const const_iterator& z) noexcept {
return z.row - v_.row; }
306 coordinates v_ {
nullptr, 0, 0};
308 friend class boost::iterator_core_access;
318 basic_result(handle_type res) noexcept(noexcept(handle_type(std::move(res))))
319 : handle_(std::move(res)) {}
321 template <
typename Other,
typename = hana::when<
322 hana::is_convertible<Other, T>::value && !std::is_same_v<T, Other>
325 noexcept(handle_type{hana::to<T>(std::move(x.release()))}))
326 : handle_(hana::to<T>(std::move(x.
release()))) {
356 [[nodiscard]]
bool empty() const noexcept {
return size() == 0; }
378 if (i < 0 ||
static_cast<std::size_t
>(i) >=
size()) {
379 throw std::out_of_range(
"ozo::result::at() index " + std::to_string(i) +
" out of range");
393 return std::addressof(*handle_);
399 bool valid() const noexcept {
return bool(handle_); }
409 handle_type
release() noexcept(std::is_nothrow_move_constructible_v<handle_type>) {
410 return std::move(handle_);
446 template <
typename T>
447 auto make_result(T&& handle) {