Loading...
Searching...
No Matches
cursor.hpp
Go to the documentation of this file.
// Copyright 2009-present MongoDB, Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#pragma once
#include <mongocxx/cursor-fwd.hpp> // IWYU pragma: export
//
#include <mongocxx/v1/cursor.hpp> // IWYU pragma: export
#include <cstddef>
#include <iterator>
#include <memory> // IWYU pragma: keep: backward compatibility, to be removed.
#include <utility>
#include <mongocxx/client-fwd.hpp> // IWYU pragma: keep: backward compatibility, to be removed.
#include <mongocxx/client_encryption-fwd.hpp> // IWYU pragma: keep: backward compatibility, to be removed.
#include <mongocxx/collection-fwd.hpp> // IWYU pragma: keep: backward compatibility, to be removed.
#include <mongocxx/database-fwd.hpp> // IWYU pragma: keep: backward compatibility, to be removed.
#include <mongocxx/index_view-fwd.hpp> // IWYU pragma: keep: backward compatibility, to be removed.
#include <mongocxx/search_index_view-fwd.hpp> // IWYU pragma: keep: backward compatibility, to be removed.
#include <bsoncxx/document/view.hpp>
#include <bsoncxx/stdx/optional.hpp> // IWYU pragma: keep: backward compatibility, to be removed.
#include <mongocxx/config/prelude.hpp>
namespace mongocxx {
namespace v_noabi {
class cursor {
private:
v1::cursor _cursor;
bsoncxx::v_noabi::document::view _doc;
public:
using type = v1::cursor::type;
class iterator;
MONGOCXX_ABI_EXPORT_CDECL_UNSTABLE() cursor(cursor&& other) noexcept;
MONGOCXX_ABI_EXPORT_CDECL_UNSTABLE(cursor&) operator=(cursor&& other) noexcept;
MONGOCXX_ABI_EXPORT_CDECL_UNSTABLE() ~cursor();
cursor(cursor const& other) = delete;
cursor& operator=(cursor const& other) = delete;
/* explicit(false) */ cursor(v1::cursor cursor) : _cursor{std::move(cursor)} {}
explicit operator v1::cursor() && {
return std::move(_cursor);
}
explicit operator v1::cursor() const& = delete;
MONGOCXX_ABI_EXPORT_CDECL_UNSTABLE(iterator) begin();
MONGOCXX_ABI_EXPORT_CDECL_UNSTABLE(iterator) end();
class internal;
};
class cursor::iterator {
public:
using value_type = bsoncxx::v_noabi::document::view;
using reference = bsoncxx::v_noabi::document::view&;
using pointer = bsoncxx::v_noabi::document::view*;
using iterator_category = std::input_iterator_tag;
using difference_type = std::ptrdiff_t;
MONGOCXX_ABI_EXPORT_CDECL_UNSTABLE(bsoncxx::v_noabi::document::view const&) operator*() const;
MONGOCXX_ABI_EXPORT_CDECL_UNSTABLE(bsoncxx::v_noabi::document::view const*) operator->() const;
MONGOCXX_ABI_EXPORT_CDECL_UNSTABLE(iterator&) operator++();
void operator++(int) {
this->operator++();
}
friend MONGOCXX_ABI_EXPORT_CDECL_UNSTABLE(bool) operator==(iterator const&, iterator const&);
friend bool operator!=(cursor::iterator const& lhs, cursor::iterator const& rhs) noexcept {
return !(lhs == rhs);
}
private:
friend cursor;
explicit iterator(cursor* cursor);
bool is_exhausted() const;
// If this pointer is null, the iterator is considered "past-the-end".
cursor* _cursor;
};
} // namespace v_noabi
} // namespace mongocxx
namespace mongocxx {
namespace v_noabi {
inline v_noabi::cursor from_v1(v1::cursor v) {
return {std::move(v)};
}
inline v1::cursor to_v1(v_noabi::cursor v) {
return v1::cursor{std::move(v)};
}
} // namespace v_noabi
} // namespace mongocxx
#include <mongocxx/config/postlude.hpp>
bsoncxx::v_noabi::document::view
A read-only, non-owning view of a BSON document.
Definition view.hpp:40
mongocxx::cursor::iterator
An input iterator of documents in a MongoDB cursor result set.
Definition cursor.hpp:154
mongocxx::cursor::cursor
cursor(cursor &&other) noexcept
Move constructs a cursor.
mongocxx::v1::cursor
A MongoDB cursor.
Definition cursor.hpp:39
mongocxx::v1::cursor::type
type
Enumeration identifying the type of the cursor.
Definition cursor.hpp:48
mongocxx::v_noabi::cursor::iterator
An input iterator of documents in a MongoDB cursor result set.
Definition cursor.hpp:154
mongocxx::v_noabi::cursor::iterator::operator==
friend bool operator==(iterator const &, iterator const &)
Compare two iterators for (in)-equality. Iterators compare equal if they point to the same underlying...
mongocxx::v_noabi::cursor::iterator::operator++
iterator & operator++()
Pre-increments the iterator to move to the next document.
mongocxx::v_noabi::cursor::iterator::operator->
bsoncxx::v_noabi::document::view const * operator->() const
Accesses a member of the dereferenced document currently being pointed to.
mongocxx::v_noabi::cursor::iterator::operator*
bsoncxx::v_noabi::document::view const & operator*() const
Dereferences the view for the document currently being pointed to.
mongocxx::v_noabi::cursor::iterator::value_type
bsoncxx::v_noabi::document::view value_type
std::iterator_traits
Definition cursor.hpp:159
mongocxx::v_noabi::cursor::iterator::operator!=
friend bool operator!=(cursor::iterator const &lhs, cursor::iterator const &rhs) noexcept
Compare two iterators for (in)-equality. Iterators compare equal if they point to the same underlying...
Definition cursor.hpp:200
mongocxx::v_noabi::cursor::iterator::operator++
void operator++(int)
Post-increments the iterator to move to the next document.
Definition cursor.hpp:187
mongocxx::v_noabi::cursor
A cursor over the documents returned by a query to a MongoDB server.
Definition cursor.hpp:50
mongocxx::v_noabi::cursor::end
iterator end()
A cursor::iterator indicating cursor exhaustion, meaning that no documents are available from the cur...
mongocxx::v_noabi::cursor::begin
iterator begin()
A cursor::iterator points to the beginning of any available results.
mongocxx::v_noabi::cursor::cursor
cursor(cursor &&other) noexcept
Move constructs a cursor.
index_view-fwd.hpp
Declares mongocxx::v_noabi::index_view.
MONGOCXX_ABI_EXPORT_CDECL_UNSTABLE
#define MONGOCXX_ABI_EXPORT_CDECL_UNSTABLE(...)
Equivalent to MONGOCXX_ABI_EXPORT_UNSTABLE with MONGOCXX_ABI_CDECL.
Definition config.hpp:28
postlude.hpp
The mongocxx v_noabi macro guard postlude header.
prelude.hpp
The mongocxx v_noabi macro guard prelude header.
mongocxx::v1
Declares entities whose ABI stability is guaranteed for documented symbols.
mongocxx::v_noabi
Declares entities whose ABI stability is NOT guaranteed.
mongocxx::v_noabi::to_v1
v1::bulk_write to_v1(v_noabi::bulk_write v)
Convert to the mongocxx::v1 equivalent of v.
Definition bulk_write.hpp:162
mongocxx::v_noabi::from_v1
v_noabi::bulk_write from_v1(v1::bulk_write v)
Convert to the mongocxx::v_noabi equivalent of v.
Definition bulk_write.hpp:155
mongocxx
The top-level namespace within which all mongocxx library entities are declared.
search_index_view-fwd.hpp
Declares mongocxx::v_noabi::search_index_view.
cursor.hpp
Provides mongocxx::v1::cursor.
view.hpp
Provides bsoncxx::v_noabi::document::view.
optional.hpp
Provides std::optional-related polyfills for library API usage.
client-fwd.hpp
Declares mongocxx::v_noabi::client.
client_encryption-fwd.hpp
Declares mongocxx::v_noabi::client_encryption.
collection-fwd.hpp
Declares mongocxx::v_noabi::collection.
cursor-fwd.hpp
Declares mongocxx::v_noabi::cursor.
database-fwd.hpp
Declares mongocxx::v_noabi::database.