Loading...
Searching...
No Matches
view.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 <bsoncxx/v1/array/view-fwd.hpp> // IWYU pragma: export
//
#include <bsoncxx/v1/detail/prelude.hpp>
#include <bsoncxx/v1/config/export.hpp>
#include <bsoncxx/v1/document/view.hpp> // IWYU pragma: export
#include <bsoncxx/v1/element/view.hpp> // IWYU pragma: export
#include <cstddef>
#include <cstdint>
namespace bsoncxx {
namespace v1 {
namespace array {
class view {
public:
using const_iterator = v1::document::view::const_iterator;
using iterator = const_iterator;
private:
v1::document::view _view;
public:
view() = default;
explicit view(std::uint8_t const* data) : _view{data} {}
view(std::uint8_t const* data, std::size_t length) : _view{data, length} {}
std::uint8_t const* data() const {
return _view.data();
}
std::size_t size() const {
return _view.size();
}
std::size_t length() const {
return _view.length();
}
bool empty() const {
return _view.empty();
}
explicit operator bool() const {
return _view.operator bool();
}
const_iterator cbegin() const {
return _view.cbegin();
}
const_iterator cend() const {
return {};
}
const_iterator begin() const {
return this->cbegin();
}
const_iterator end() const {
return this->cend();
}
BSONCXX_ABI_EXPORT_CDECL(const_iterator) find(std::uint32_t i) const;
v1::element::view operator[](std::uint32_t i) const {
return *(this->find(i));
}
/* explicit(false) */ operator v1::document::view() const {
return _view;
}
friend bool operator==(view lhs, view rhs) {
return lhs._view == rhs._view;
}
friend bool operator!=(view lhs, view rhs) {
return !(lhs == rhs);
}
};
} // namespace array
} // namespace v1
} // namespace bsoncxx
#include <bsoncxx/v1/detail/postlude.hpp>
export.hpp
Provides macros to control the set of symbols exported in the ABI.
BSONCXX_ABI_EXPORT_CDECL
#define BSONCXX_ABI_EXPORT_CDECL(...)
Equivalent to BSONCXX_ABI_EXPORT with BSONCXX_ABI_CDECL.
Definition export.hpp:52
postlude.hpp
The bsoncxx v1 macro guard postlude header.
prelude.hpp
The bsoncxx v1 macro guard prelude header.
bsoncxx::v1::array::view::data
std::uint8_t const * data() const
Return a pointer to the BSON bytes being represented.
Definition view.hpp:69
bsoncxx::v1::array::view::view
view(std::uint8_t const *data, std::size_t length)
Equivalent to view(std::uint8_t const* data), but validates the embedded length against length.
Definition view.hpp:66
bsoncxx::v1::array::view::begin
const_iterator begin() const
Return a const iterator to the beginning of the range of BSON elements within this view.
Definition view.hpp:104
bsoncxx::v1::array::view::length
std::size_t length() const
Return the length of the BSON bytes being represented.
Definition view.hpp:79
bsoncxx::v1::array::view::operator!=
friend bool operator!=(view lhs, view rhs)
Compare equal when the BSON bytes represented by lhs and rhs compare equal.
Definition view.hpp:154
bsoncxx::v1::array::view::operator==
friend bool operator==(view lhs, view rhs)
Compare equal when the BSON bytes represented by lhs and rhs compare equal.
Definition view.hpp:149
bsoncxx::v1::array::view::iterator
const_iterator iterator
Equivalent to const_iterator.
Definition view.hpp:53
bsoncxx::v1::array::view::cbegin
const_iterator cbegin() const
Return a const iterator to the beginning of the range of BSON elements within this view.
Definition view.hpp:94
bsoncxx::v1::array::view::empty
bool empty() const
Return true when the BSON bytes represents an empty view:
Definition view.hpp:84
bsoncxx::v1::array::view::const_iterator
v1::document::view::const_iterator const_iterator
A const iterator over the elements of a view.
Definition view.hpp:50
bsoncxx::v1::array::view::size
std::size_t size() const
Return the length of the BSON bytes being represented.
Definition view.hpp:74
bsoncxx::v1::array::view::find
const_iterator find(std::uint32_t i) const
Return a const iterator to the element within the represented BSON array at index i via key string co...
bsoncxx::v1::array::view::cend
const_iterator cend() const
Return a const iterator to the end of the range of BSON elements within this view.
Definition view.hpp:99
bsoncxx::v1::array::view::operator[]
v1::element::view operator[](std::uint32_t i) const
Return the first element within the represented BSON array whose key compares equal to i.
Definition view.hpp:137
bsoncxx::v1::array::view::view
view(std::uint8_t const *data)
Initialize with the given BSON bytes.
Definition view.hpp:63
bsoncxx::v1::array::view::end
const_iterator end() const
Return a const iterator to the end of the range of BSON elements within this view.
Definition view.hpp:109
bsoncxx::v1::array::view::view
view()=default
Initialize as an empty view.
bsoncxx::v1::document::view::const_iterator
A const iterator over the elements of a view.
Definition view.hpp:264
bsoncxx::v1::document::view
A non-owning, read-only BSON document.
Definition view.hpp:52
bsoncxx::v1::element::view
A non-owning, read-only BSON element.
Definition view.hpp:82
bsoncxx::v1::array
Declares entities representing a BSON array.
bsoncxx::v1
Declares entities whose ABI stability is guaranteed for documented symbols.
bsoncxx
The top-level namespace within which all bsoncxx library entities are declared.
view-fwd.hpp
Declares bsoncxx::v1::array::view.
view.hpp
Provides bsoncxx::v1::document::view.
view.hpp
Provides bsoncxx::v1::element::view.