@@ -16,90 +16,121 @@ limitations under the License.
1616
1717#pragma once
1818
19- #include < dc /declare.hpp>
19+ #include < dot /declare.hpp>
2020#include < dot/system/ptr.hpp>
21+ #include < dot/system/type.hpp>
2122#include < bsoncxx/oid.hpp>
2223
23- namespace dc
24+ namespace dot
2425{
25- class DC_CLASS ObjectId
26- {
26+ class local_date_time ;
2727
28- public:
28+ // / Repesents 12-byte MongoDB identifier that is unique within the server.
29+ // /
30+ // / This type is immutable.
31+ class DOT_CLASS object_id
32+ {
33+ public: // STATIC
2934
30- ObjectId ();
35+ // / Represents empty object id, all bytes are zero
36+ static object_id Empty;
3137
32- ObjectId (bsoncxx::oid id);
38+ public: // CONSTRUCTORS
3339
34- ObjectId (dot::object obj);
40+ // / <summary>Create with value object_id::empty.</summary>
41+ object_id ();
3542
36- ObjectId (dot::string str);
43+ // / <summary>Create from MongoDB driver object id type.</summary>
44+ object_id (bsoncxx::oid id);
3745
38- explicit ObjectId (const char * bytes, std::size_t len);
46+ // / <summary>Create from MongoDB driver object id type.</summary>
47+ object_id (dot::object obj);
3948
40- explicit ObjectId (dot::local_date_time value);
49+ // / <summary>Create from the hexidecimal string representation produced by to_string().</summary>
50+ object_id (dot::string str);
4151
42- bool operator ==(const ObjectId& rhs) const ;
52+ // / <summary>Create from byte array.</summary>
53+ object_id (const char * bytes, std::size_t len);
4354
44- bool operator !=(const ObjectId& rhs) const ;
55+ // / Create from UTC datetime, with all other components of object id empty.
56+ // / The created object is less or equal to any other object with time timestamp
57+ // / that falls on the same second.
58+ // /
59+ // / Error message if the timestamp does not fall on the second // TODO - need to check
60+ explicit object_id (dot::local_date_time value);
4561
46- bool operator >=( const ObjectId& rhs) const ;
62+ public: // METHODS
4763
48- bool operator <=(const ObjectId& rhs) const ;
64+ // / Return the internal BSON oid type
65+ bsoncxx::oid oid () const { return _id; }
4966
5067 bool is_empty ();
5168
52- bool operator <( const ObjectId& rhs) const ;
69+ static object_id GenerateNewId () ;
5370
54- // local_date_time GetTimeStamp();
71+ // / Returns hexadecimal string representation
72+ dot::string to_string () const ;
5573
56- static ObjectId GenerateNewId ();
74+ public: // OPERATORS
5775
58- dot::string to_string ();
76+ // / Equality operator
77+ bool operator ==(const object_id& rhs) const ;
5978
60- bsoncxx::oid _id;
79+ // / Inquality operator
80+ bool operator !=(const object_id& rhs) const ;
81+
82+ // / More of equal operator
83+ bool operator >=(const object_id& rhs) const ;
6184
62- static ObjectId Empty;
85+ // / Less or equal operator
86+ bool operator <=(const object_id& rhs) const ;
6387
64- operator dot::object ()
88+ // / Less operator
89+ bool operator <(const object_id& rhs) const ;
90+
91+ // / More operator
92+ bool operator >(const object_id& rhs) const ;
93+
94+ // / Boxing operator
95+ operator dot::object () const
6596 {
6697 if (_id != Empty._id )
67- return dot::object (new dot::struct_wrapper_impl<ObjectId >(*this ));
98+ return dot::object (new dot::struct_wrapper_impl<object_id >(*this ));
6899 else return dot::object ();
69100 }
70101
102+ private:
103+ bsoncxx::oid _id;
71104 };
72-
73105}
74106
75107namespace dot
76108{
77109 template <>
78- inline type_t typeof <dc::ObjectId >()
110+ inline type_t typeof <dot::object_id >()
79111 {
80- static dot::type_t type_ = dot::make_type_builder<dc::ObjectId >(" Mongo" , " ObjectId " )->build ();
112+ static dot::type_t type_ = dot::make_type_builder<dot::object_id >(" Mongo" , " object_id " )->build ();
81113 return type_;
82114 }
83-
84115}
85116
86117namespace std
87118{
88- // / <summary>Implements hash struct used by STL unordered_map for ObjectId .</summary>
119+ // / <summary>Implements hash struct used by STL unordered_map for object_id .</summary>
89120 template <>
90- struct hash <dc::ObjectId >
121+ struct hash <dot::object_id >
91122 {
92- size_t operator ()(const dc::ObjectId & id) const
123+ size_t operator ()(const dot::object_id & id) const
93124 {
94- return hash<string>()(id._id .to_string ());
125+ return hash<string>()(id.oid () .to_string ());
95126 }
96127 };
97128
98- // / <summary>Implements equal_to struct used by STL unordered_map for ObjectId .</summary>
129+ // / <summary>Implements equal_to struct used by STL unordered_map for object_id .</summary>
99130 template <>
100- struct equal_to <dc::ObjectId >
131+ struct equal_to <dot::object_id >
101132 {
102- bool operator ()(const dc::ObjectId & lhs, const dc::ObjectId & rhs) const
133+ bool operator ()(const dot::object_id & lhs, const dot::object_id & rhs) const
103134 {
104135 return lhs == rhs;
105136 }
0 commit comments