forked from pocoproject/poco
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathObjectId.cpp
More file actions
executable file
·59 lines (46 loc) · 930 Bytes
/
ObjectId.cpp
File metadata and controls
executable file
·59 lines (46 loc) · 930 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
//
// ObjectId.cpp
//
// $Id$
//
// Library: MongoDB
// Package: MongoDB
// Module: ObjectId
//
// Implementation of the ObjectId class.
//
// Copyright (c) 2012, Applied Informatics Software Engineering GmbH.
// and Contributors.
//
// SPDX-License-Identifier: BSL-1.0
//
#include "Poco/MongoDB/ObjectId.h"
#include "Poco/Format.h"
namespace Poco {
namespace MongoDB {
ObjectId::ObjectId(const std::string& id)
{
if (id.size() == 12)
{
std::string::const_iterator it = id.begin();
std::string::const_iterator end = id.end();
for (int i = 0; i < 12; ++it, ++i) _id[i] = *it;
}
else if (id.size())
{
throw Poco::InvalidArgumentException("ID must be 12 characters long.");
}
}
ObjectId::~ObjectId()
{
}
std::string ObjectId::toString(const std::string& fmt) const
{
std::string s;
for(int i = 0; i < 12; ++i)
{
s += format(fmt, (unsigned int) _id[i]);
}
return s;
}
} } // namespace Poco::MongoDB