MongoDB C++ Driver mongocxx-3.11.0
Loading...
Searching...
No Matches
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
41class oid {
42 public:
43 static constexpr std::size_t k_oid_length = 12;
44
49
60 explicit BSONCXX_ABI_EXPORT_CDECL() oid(const char* bytes, std::size_t len);
61
71 explicit BSONCXX_ABI_EXPORT_CDECL() oid(const stdx::string_view& str);
72
79
85 static std::size_t size() {
86 return k_oid_length;
87 }
88
95 friend BSONCXX_ABI_EXPORT_CDECL(bool) operator<(const oid& lhs, const oid& rhs);
96 friend BSONCXX_ABI_EXPORT_CDECL(bool) operator>(const oid& lhs, const oid& rhs);
97 friend BSONCXX_ABI_EXPORT_CDECL(bool) operator<=(const oid& lhs, const oid& rhs);
98 friend BSONCXX_ABI_EXPORT_CDECL(bool) operator>=(const oid& lhs, const oid& rhs);
99 friend BSONCXX_ABI_EXPORT_CDECL(bool) operator==(const oid& lhs, const oid& rhs);
100 friend BSONCXX_ABI_EXPORT_CDECL(bool) operator!=(const oid& lhs, const oid& rhs);
103
111
117 BSONCXX_ABI_EXPORT_CDECL(const char*) bytes() const;
118
119 private:
120 friend int oid_compare(const oid& lhs, const oid& rhs);
121
122 std::array<char, k_oid_length> _bytes;
123};
124
125} // namespace v_noabi
126} // namespace bsoncxx
127
129
The bsoncxx macro guard postlude header.
The bsoncxx macro guard prelude header.
Represents a MongoDB ObjectId. As this BSON type is used within the MongoDB server as a primary key f...
Definition oid.hpp:41
std::string to_string() const
Converts this oid to a hexadecimal string.
friend bool operator==(const oid &lhs, const oid &rhs)
Relational operators for OIDs.
friend bool operator!=(const oid &lhs, const oid &rhs)
Relational operators for OIDs.
static std::size_t size()
Returns the number of bytes in this ObjectId.
Definition oid.hpp:85
const char * bytes() const
An accessor for the internal data buffer in the oid.
std::time_t get_time_t() const
Extracts the timestamp portion of the underlying ObjectId.
friend bool operator<(const oid &lhs, const oid &rhs)
Relational operators for OIDs.
friend bool operator>(const oid &lhs, const oid &rhs)
Relational operators for OIDs.
friend bool operator>=(const oid &lhs, const oid &rhs)
Relational operators for OIDs.
friend bool operator<=(const oid &lhs, const oid &rhs)
Relational operators for OIDs.
#define BSONCXX_ABI_EXPORT_CDECL(...)
Equivalent to BSONCXX_ABI_EXPORT with BSONCXX_ABI_CDECL.
Definition fwd.hpp:225
The top-level namespace within which all bsoncxx library entities are declared.
The top-level namespace reserved for the C++ standard library.
Declares bsoncxx::v_noabi::oid.
Provides std::string_view-related polyfills for library API usage.