MongoDB C++ Driver 4.1.0
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
oid.hpp
Go to the documentation of this file.
1// Copyright 2009-present MongoDB, Inc.
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7// http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15#pragma once
16
17#include <array>
18#include <ctime>
19#include <string>
20
21#include <bsoncxx/oid-fwd.hpp>
22
24
26
27namespace bsoncxx {
28namespace v_noabi {
29
36class oid {
37 public:
38 static constexpr std::size_t k_oid_length = 12;
39
44
55 explicit BSONCXX_ABI_EXPORT_CDECL() oid(char const* bytes, std::size_t len);
56
66 explicit BSONCXX_ABI_EXPORT_CDECL() oid(stdx::string_view const& str);
67
73 BSONCXX_ABI_EXPORT_CDECL(std::string) to_string() const;
74
80 static std::size_t size() {
81 return k_oid_length;
82 }
83
90 friend BSONCXX_ABI_EXPORT_CDECL(bool) operator<(oid const& lhs, oid const& rhs);
91 friend BSONCXX_ABI_EXPORT_CDECL(bool) operator>(oid const& lhs, oid const& rhs);
92 friend BSONCXX_ABI_EXPORT_CDECL(bool) operator<=(oid const& lhs, oid const& rhs);
93 friend BSONCXX_ABI_EXPORT_CDECL(bool) operator>=(oid const& lhs, oid const& rhs);
94 friend BSONCXX_ABI_EXPORT_CDECL(bool) operator==(oid const& lhs, oid const& rhs);
95 friend BSONCXX_ABI_EXPORT_CDECL(bool) operator!=(oid const& lhs, oid const& rhs);
98
106
112 BSONCXX_ABI_EXPORT_CDECL(char const*) bytes() const;
113
114 private:
115 friend int oid_compare(oid const& lhs, oid const& rhs);
116
117 std::array<char, k_oid_length> _bytes;
118};
119
120} // namespace v_noabi
121} // namespace bsoncxx
122
124
#define BSONCXX_ABI_EXPORT_CDECL(...)
Equivalent to BSONCXX_ABI_EXPORT with BSONCXX_ABI_CDECL.
Definition export.hpp:52
The bsoncxx v_noabi macro guard postlude header.
The bsoncxx v_noabi macro guard prelude header.
oid()
Constructs an oid and initializes it to a newly generated ObjectId.
std::string to_string() const
Converts this oid to a hexadecimal string.
friend bool operator>=(oid const &lhs, oid const &rhs)
Relational operators for OIDs.
static std::size_t size()
Returns the number of bytes in this ObjectId.
Definition oid.hpp:80
friend bool operator!=(oid const &lhs, oid const &rhs)
Relational operators for OIDs.
std::time_t get_time_t() const
Extracts the timestamp portion of the underlying ObjectId.
oid()
Constructs an oid and initializes it to a newly generated ObjectId.
friend bool operator<(oid const &lhs, oid const &rhs)
Relational operators for OIDs.
friend bool operator==(oid const &lhs, oid const &rhs)
Relational operators for OIDs.
friend bool operator<=(oid const &lhs, oid const &rhs)
Relational operators for OIDs.
char const * bytes() const
An accessor for the internal data buffer in the oid.
friend bool operator>(oid const &lhs, oid const &rhs)
Relational operators for OIDs.
Declares C++17 standard library polyfills.
Declares entities whose ABI stability is NOT guaranteed.
The top-level namespace within which all bsoncxx library entities are declared.
Declares bsoncxx::v_noabi::oid.
Provides std::string_view-related polyfills for library API usage.