MongoDB C++ Driver  mongocxx-3.9.0
All Classes Namespaces Functions Typedefs Enumerations Enumerator Friends Pages
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 
25 namespace bsoncxx {
26 inline namespace v_noabi {
37 class BSONCXX_API oid {
38  public:
39  static constexpr std::size_t k_oid_length = 12;
40 
44  oid();
45 
56  explicit oid(const char* bytes, std::size_t len);
57 
67  explicit oid(const bsoncxx::stdx::string_view& str);
68 
74  std::string to_string() const;
75 
81  static std::size_t size() {
82  return k_oid_length;
83  }
84 
92  friend BSONCXX_API bool BSONCXX_CALL operator<(const oid& lhs, const oid& rhs);
93  friend BSONCXX_API bool BSONCXX_CALL operator>(const oid& lhs, const oid& rhs);
94  friend BSONCXX_API bool BSONCXX_CALL operator<=(const oid& lhs, const oid& rhs);
95  friend BSONCXX_API bool BSONCXX_CALL operator>=(const oid& lhs, const oid& rhs);
96  friend BSONCXX_API bool BSONCXX_CALL operator==(const oid& lhs, const oid& rhs);
97  friend BSONCXX_API bool BSONCXX_CALL operator!=(const oid& lhs, const oid& rhs);
101 
107  std::time_t get_time_t() const;
108 
114  const char* bytes() const;
115 
116  private:
117  friend BSONCXX_PRIVATE int oid_compare(const oid& lhs, const oid& rhs);
118 
119  std::array<char, k_oid_length> _bytes;
120 };
121 
122 } // namespace v_noabi
123 } // namespace bsoncxx
124 
125 #include <bsoncxx/config/postlude.hpp>
Represents a MongoDB ObjectId.
Definition: oid.hpp:37
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:81
friend bool operator<(const oid &lhs, const oid &rhs)
Relational operators for OIDs.
oid()
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.
friend bool operator<=(const oid &lhs, const oid &rhs)
Relational operators for OIDs.
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.
std::time_t get_time_t() const
Extracts the timestamp portion of the underlying ObjectId.
The top-level namespace for bsoncxx library entities.
Definition: element.hpp:24