Files
poco/MongoDB/src/ObjectId.cpp
Roger Meier b0581433a7 LICENSE: add info about SPDX-License-Identifier usage and use it
fix: remove executable flag and change back to 100644 (was 100755)

Signed-off-by: Roger Meier <r.meier@siemens.com>
2014-05-14 08:38:09 +02:00

60 lines
930 B
C++

//
// 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