MongoDB C++ Driver  mongocxx-3.0.1
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/string/view_or_value.hpp>
22 
23 #include <bsoncxx/config/prelude.hpp>
24 
25 namespace bsoncxx {
26 BSONCXX_INLINE_NAMESPACE_BEGIN
27 
38 class BSONCXX_API oid {
39  public:
40  struct init_tag_t {};
41 
42  // TODO(MSVC): Ideally this would be constexpr, but VS2015U1 can't
43  // handle it.
44  //
45  // See https://connect.microsoft.com/VisualStudio/feedback/details/2092790
46  //
47  static const init_tag_t init_tag;
48 
52  oid();
53 
60  explicit oid(init_tag_t tag);
61 
70  explicit oid(const char* bytes, std::size_t len);
71 
78  explicit oid(const string::view_or_value& str);
79 
85  std::string to_string() const;
86 
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);
98  friend BSONCXX_API bool BSONCXX_CALL operator==(const oid& lhs, const oid& rhs);
99  friend BSONCXX_API bool BSONCXX_CALL operator!=(const oid& lhs, const oid& rhs);
103 
109  explicit operator bool() const;
110 
116  std::time_t get_time_t() const;
117 
123  const char* bytes() const;
124 
125  private:
126  friend BSONCXX_PRIVATE int oid_compare(const oid& lhs, const oid& rhs);
127 
128  bool _is_valid;
129 
130  std::array<char, 12> _bytes;
131 };
132 
133 BSONCXX_INLINE_NAMESPACE_END
134 } // namespace bsoncxx
135 
136 #include <bsoncxx/config/postlude.hpp>
Represents a MongoDB ObjectId.
Definition: oid.hpp:38
Definition: oid.hpp:40
Class representing a view-or-value variant type for strings.
Definition: view_or_value.hpp:36
Definition: element.hpp:24