Loading...
Searching...
No Matches
oid.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/oid-fwd.hpp> // IWYU pragma: export
//
#include <bsoncxx/v1/detail/type_traits.hpp> // IWYU pragma: keep: backward compatibility, to be removed.
#include <bsoncxx/v1/oid.hpp> // IWYU pragma: export
#include <array> // IWYU pragma: keep: backward compatibility, to be removed.
#include <ctime>
#include <string>
#include <bsoncxx/stdx/string_view.hpp>
#include <bsoncxx/config/prelude.hpp>
namespace bsoncxx {
namespace v_noabi {
class oid {
private:
v1::oid _oid;
public:
static constexpr std::size_t k_oid_length = v1::oid::k_oid_length;
BSONCXX_ABI_EXPORT_CDECL_UNSTABLE() oid();
/* explicit(false) */ oid(v1::oid const& oid) noexcept : _oid{oid} {}
explicit BSONCXX_ABI_EXPORT_CDECL_UNSTABLE() oid(char const* bytes, std::size_t len);
explicit BSONCXX_ABI_EXPORT_CDECL_UNSTABLE() oid(v1::stdx::string_view const& str);
explicit operator v1::oid() const noexcept {
return _oid;
}
std::string to_string() const {
return _oid.to_string();
}
static std::size_t size() {
return k_oid_length;
}
std::time_t get_time_t() const {
return _oid.get_time_t();
}
char const* bytes() const {
return reinterpret_cast<char const*>(_oid.bytes());
}
int compare(oid const& other) const {
return _oid.compare(other._oid);
}
friend bool operator<(oid const& lhs, oid const& rhs) {
return lhs._oid < rhs._oid;
}
friend bool operator>(oid const& lhs, oid const& rhs) {
return lhs._oid > rhs._oid;
}
friend bool operator<=(oid const& lhs, oid const& rhs) {
return lhs._oid <= rhs._oid;
}
friend bool operator>=(oid const& lhs, oid const& rhs) {
return lhs._oid >= rhs._oid;
}
friend bool operator==(oid const& lhs, oid const& rhs) {
return lhs._oid == rhs._oid;
}
friend bool operator!=(oid const& lhs, oid const& rhs) {
return lhs._oid != rhs._oid;
}
private:
friend BSONCXX_ABI_EXPORT_CDECL_UNSTABLE(int) oid_compare(oid const& lhs, oid const& rhs);
};
BSONCXX_PRIVATE_INLINE_CXX17 constexpr std::size_t oid::k_oid_length;
inline oid from_v1(v1::oid const& v) {
return {v};
}
inline v1::oid to_v1(v_noabi::oid const& v) {
return v1::oid{v};
}
} // namespace v_noabi
} // namespace bsoncxx
#include <bsoncxx/config/postlude.hpp>
BSONCXX_ABI_EXPORT_CDECL_UNSTABLE
#define BSONCXX_ABI_EXPORT_CDECL_UNSTABLE(...)
Equivalent to BSONCXX_ABI_EXPORT_UNSTABLE with BSONCXX_ABI_CDECL.
Definition config.hpp:28
postlude.hpp
The bsoncxx v_noabi macro guard postlude header.
prelude.hpp
The bsoncxx v_noabi macro guard prelude header.
bsoncxx::oid::oid
oid()
Constructs an oid and initializes it to a newly generated ObjectId.
bsoncxx::v1::oid
A BSON ObjectID.
Definition oid.hpp:41
bsoncxx::v1::oid::k_oid_length
static constexpr std::size_t k_oid_length
The number of bytes required to represent an ObjectID.
Definition oid.hpp:46
bsoncxx::v_noabi::oid
Represents a MongoDB BSON ObjectId.
Definition oid.hpp:41
bsoncxx::v_noabi::oid::to_string
std::string to_string() const
Converts this oid to a hexadecimal string.
Definition oid.hpp:93
bsoncxx::v_noabi::oid::operator>=
friend bool operator>=(oid const &lhs, oid const &rhs)
Relational comparison operator.
Definition oid.hpp:150
bsoncxx::v_noabi::oid::compare
int compare(oid const &other) const
Equivalent to bson_oid_compare.
Definition oid.hpp:128
bsoncxx::v_noabi::oid::size
static std::size_t size()
Returns the number of bytes in this ObjectId.
Definition oid.hpp:102
bsoncxx::v_noabi::oid::operator!=
friend bool operator!=(oid const &lhs, oid const &rhs)
Relational comparison operator.
Definition oid.hpp:158
bsoncxx::v_noabi::oid::get_time_t
std::time_t get_time_t() const
Extracts the timestamp portion of the underlying ObjectId.
Definition oid.hpp:112
bsoncxx::v_noabi::oid::oid
oid()
Constructs an oid and initializes it to a newly generated ObjectId.
bsoncxx::v_noabi::oid::operator<
friend bool operator<(oid const &lhs, oid const &rhs)
Relational comparison operator.
Definition oid.hpp:138
bsoncxx::v_noabi::oid::operator==
friend bool operator==(oid const &lhs, oid const &rhs)
Relational comparison operator.
Definition oid.hpp:154
bsoncxx::v_noabi::oid::operator<=
friend bool operator<=(oid const &lhs, oid const &rhs)
Relational comparison operator.
Definition oid.hpp:146
bsoncxx::v_noabi::oid::bytes
char const * bytes() const
An accessor for the internal data buffer in the oid.
Definition oid.hpp:121
bsoncxx::v_noabi::oid::operator>
friend bool operator>(oid const &lhs, oid const &rhs)
Relational comparison operator.
Definition oid.hpp:142
bsoncxx::v1
Declares entities whose ABI stability is guaranteed for documented symbols.
bsoncxx::v_noabi::stdx
Declares C++17 standard library polyfills.
bsoncxx::v_noabi
Declares entities whose ABI stability is NOT guaranteed.
bsoncxx::v_noabi::to_v1
v1::element::view to_v1(v_noabi::array::element const &v)
Convert to the bsoncxx::v1 equivalent of v.
Definition element.hpp:132
bsoncxx::v_noabi::from_v1
v_noabi::array::value from_v1(v1::array::value const &v)
Convert from the bsoncxx::v1 equivalent of v.
Definition value.hpp:263
bsoncxx
The top-level namespace within which all bsoncxx library entities are declared.
type_traits.hpp
For internal use only!
oid.hpp
Provides bsoncxx::v1::oid.
oid-fwd.hpp
Declares bsoncxx::v_noabi::oid.
string_view.hpp
Provides std::string_view-related polyfills for library API usage.