Skip to content

Commit 9dddc7a

Browse files
committed
Updated code for object_id to compile in DotCpp project.
(cherry picked from commit 4ab3729e4157526a3619d063aa56f9a7bcf005a6)
1 parent 826c463 commit 9dddc7a

3 files changed

Lines changed: 99 additions & 76 deletions

File tree

‎cpp/src/dotcpp/dot/DotCpp.Cpp.vcxproj‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
</ProjectConfiguration>
1212
</ItemGroup>
1313
<ItemGroup>
14+
<ClCompile Include="mongo_db\bson\object_id.cpp" />
1415
<ClCompile Include="noda_time\local_date.cpp" />
1516
<ClCompile Include="noda_time\local_date_time.cpp" />
1617
<ClCompile Include="noda_time\local_date_time_util.cpp" />
@@ -51,6 +52,7 @@
5152
<ClInclude Include="detail\traits.hpp" />
5253
<ClInclude Include="implement.hpp" />
5354
<ClInclude Include="import.hpp" />
55+
<ClInclude Include="mongo_db\bson\object_id.hpp" />
5456
<ClInclude Include="noda_time\local_date.hpp" />
5557
<ClInclude Include="noda_time\local_date_time.hpp" />
5658
<ClInclude Include="noda_time\local_date_time_util.hpp" />
@@ -150,7 +152,7 @@
150152
<SubSystem>NotSet</SubSystem>
151153
<GenerateDebugInformation>true</GenerateDebugInformation>
152154
<AdditionalLibraryDirectories>$(OutDir)</AdditionalLibraryDirectories>
153-
<AdditionalDependencies>libboost_date_time-vc141-mt-gd-x64-1_70.lib;%(AdditionalDependencies)</AdditionalDependencies>
155+
<AdditionalDependencies>libboost_date_time-vc141-mt-gd-x64-1_70.lib;Mongo.Cpp.lib;secur32.lib;ws2_32.lib;crypt32.lib;Bcrypt.lib;Dnsapi.lib;%(AdditionalDependencies)</AdditionalDependencies>
154156
</Link>
155157
</ItemDefinitionGroup>
156158
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
@@ -174,7 +176,7 @@
174176
<EnableCOMDATFolding>true</EnableCOMDATFolding>
175177
<OptimizeReferences>true</OptimizeReferences>
176178
<AdditionalLibraryDirectories>$(OutDir)</AdditionalLibraryDirectories>
177-
<AdditionalDependencies>libboost_date_time-vc141-mt-x64-1_70.lib;%(AdditionalDependencies)</AdditionalDependencies>
179+
<AdditionalDependencies>libboost_date_time-vc141-mt-x64-1_70.lib;Mongo.Cpp.lib;secur32.lib;ws2_32.lib;crypt32.lib;Bcrypt.lib;Dnsapi.lib;%(AdditionalDependencies)</AdditionalDependencies>
178180
</Link>
179181
</ItemDefinitionGroup>
180182
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />

‎cpp/src/dotcpp/dot/mongo_db/bson/object_id.cpp‎

Lines changed: 30 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -14,37 +14,40 @@ See the License for the specific language governing permissions and
1414
limitations under the License.
1515
*/
1616

17-
#include <dc/implement.hpp>
18-
#include <dc/platform/data_source/mongo/ObjectId.hpp>
17+
#include <dot/precompiled.hpp>
18+
#include <dot/implement.hpp>
19+
#include <dot/mongo_db/bson/object_id.hpp>
1920
#include <dot/system/string.hpp>
2021
#include <dot/noda_time/local_date_time.hpp>
22+
#include "dot/system/object.hpp"
2123

22-
namespace dc
24+
namespace dot
2325
{
26+
object_id object_id::Empty = object_id();
2427

25-
ObjectId::ObjectId()
28+
object_id::object_id()
2629
{
2730
static const char Empty[12] = { 0 };
2831
_id = bsoncxx::oid(Empty, 12);
2932
}
3033

31-
ObjectId::ObjectId(bsoncxx::oid id) : _id(id) {}
34+
object_id::object_id(bsoncxx::oid id) : _id(id) {}
3235

33-
ObjectId::ObjectId(dot::object obj)
36+
object_id::object_id(dot::object obj)
3437
{
35-
_id = ((dot::struct_wrapper<ObjectId>)obj)->_id;
38+
_id = ((struct_wrapper<object_id>)obj)->_id;
3639
}
3740

38-
ObjectId::ObjectId(dot::string str)
41+
object_id::object_id(dot::string str)
3942
: _id(*str)
4043
{}
4144

42-
ObjectId::ObjectId(const char* bytes, std::size_t len)
45+
object_id::object_id(const char* bytes, std::size_t len)
4346
: _id(bytes, len)
4447
{
4548
}
4649

47-
ObjectId::ObjectId(dot::local_date_time value)
50+
object_id::object_id(dot::local_date_time value)
4851
{
4952
char bytes[12] = { 0 };
5053

@@ -55,56 +58,43 @@ namespace dc
5558
_id = bsoncxx::oid(bytes, 12);
5659
}
5760

58-
bool ObjectId::operator==(const ObjectId& rhs) const
61+
bool object_id::is_empty()
5962
{
60-
return _id == rhs._id;
63+
return *_id.bytes() == 0; // TODO check
6164
}
6265

63-
bool ObjectId::operator!=(const ObjectId& rhs) const
66+
object_id object_id::GenerateNewId()
6467
{
65-
return _id != rhs._id;
68+
return bsoncxx::oid();
6669
}
6770

68-
bool ObjectId::operator>=(const ObjectId& rhs) const
71+
dot::string object_id::to_string() const
6972
{
70-
return _id >= rhs._id;
73+
return _id.to_string();
7174
}
7275

73-
bool ObjectId::operator<=(const ObjectId& rhs) const
76+
bool object_id::operator==(const object_id& rhs) const
7477
{
75-
return _id <= rhs._id;
78+
return _id == rhs._id;
7679
}
7780

78-
bool ObjectId::is_empty()
81+
bool object_id::operator!=(const object_id& rhs) const
7982
{
80-
return *_id.bytes() == 0; // TODO check
83+
return _id != rhs._id;
8184
}
8285

83-
bool ObjectId::operator<(const ObjectId& rhs) const
86+
bool object_id::operator>=(const object_id& rhs) const
8487
{
85-
return _id < rhs._id;
88+
return _id >= rhs._id;
8689
}
8790

88-
//local_date_time ObjectId::GetTimeStamp()
89-
//{
90-
// ptime epoch(boost::gregorian::date(1970, boost::date_time::Jan, 1));
91-
// int64_t seconds;
92-
// std::memcpy(&seconds, _id.bytes(), sizeof(seconds));
93-
//
94-
// boost::posix_time::time_duration d = boost::posix_time::seconds(seconds);
95-
// return epoch + d;
96-
//}
97-
98-
ObjectId ObjectId::GenerateNewId()
91+
bool object_id::operator<=(const object_id& rhs) const
9992
{
100-
return bsoncxx::oid();
93+
return _id <= rhs._id;
10194
}
10295

103-
dot::string ObjectId::to_string()
96+
bool object_id::operator<(const object_id& rhs) const
10497
{
105-
return _id.to_string();
98+
return _id < rhs._id;
10699
}
107-
108-
ObjectId ObjectId::Empty = ObjectId();
109-
110-
}
100+
}

‎cpp/src/dotcpp/dot/mongo_db/bson/object_id.hpp‎

Lines changed: 65 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -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

75107
namespace 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

86117
namespace 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

Comments
 (0)