MongoDB C++ Driver mongocxx-3.0.3
Loading...
Searching...
No Matches
oid.hpp
1// Copyright 2014 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/stdx/string_view.hpp>
22
23#include <bsoncxx/config/prelude.hpp>
24
25namespace bsoncxx {
26BSONCXX_INLINE_NAMESPACE_BEGIN
27
38class BSONCXX_API oid {
39 public:
43 oid();
44
45 struct init_tag_t {};
46
47 // TODO(MSVC): Ideally this would be constexpr, but VS2015U1 can't
48 // handle it.
49 //
50 // See https://connect.microsoft.com/VisualStudio/feedback/details/2092790
51 //
52 static const init_tag_t init_tag;
53
63 BSONCXX_DEPRECATED explicit oid(init_tag_t tag);
64
75 explicit oid(const char* bytes, std::size_t len);
76
86 explicit oid(const bsoncxx::stdx::string_view& str);
87
93 std::string to_string() const;
94
102 friend BSONCXX_API bool BSONCXX_CALL operator<(const oid& lhs, const oid& rhs);
103 friend BSONCXX_API bool BSONCXX_CALL operator>(const oid& lhs, const oid& rhs);
104 friend BSONCXX_API bool BSONCXX_CALL operator<=(const oid& lhs, const oid& rhs);
105 friend BSONCXX_API bool BSONCXX_CALL operator>=(const oid& lhs, const oid& rhs);
106 friend BSONCXX_API bool BSONCXX_CALL operator==(const oid& lhs, const oid& rhs);
107 friend BSONCXX_API bool BSONCXX_CALL operator!=(const oid& lhs, const oid& rhs);
111
120 BSONCXX_DEPRECATED explicit operator bool() const;
121
127 std::time_t get_time_t() const;
128
134 const char* bytes() const;
135
136 private:
137 friend BSONCXX_PRIVATE int oid_compare(const oid& lhs, const oid& rhs);
138
139 std::array<char, 12> _bytes;
140};
141
142BSONCXX_INLINE_NAMESPACE_END
143} // namespace bsoncxx
144
145#include <bsoncxx/config/postlude.hpp>
Represents a MongoDB ObjectId.
Definition oid.hpp:38
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.
oid(init_tag_t tag)
Constructs an oid and initializes it to a newly generated ObjectId.
oid(const bsoncxx::stdx::string_view &str)
Constructs an oid and initializes it from the provided hex 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.
std::string to_string() const
Converts this oid to a hexadecimal string.
oid()
Constructs an oid and initializes it to a newly generated 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.
std::time_t get_time_t() const
Extracts the timestamp portion of the underlying ObjectId.
const char * bytes() const
An accessor for the internal data buffer in the oid.
oid(const char *bytes, std::size_t len)
Constructs an oid initializes it to the contents of the provided buffer.
Definition oid.hpp:45