MongoDB: fixes for style and consistency

This commit is contained in:
Guenter Obiltschnig
2017-02-13 15:53:08 +01:00
parent 9f8146ccaa
commit 1aa6f72085
47 changed files with 642 additions and 514 deletions

View File

@@ -7,8 +7,6 @@
// Package: MongoDB
// Module: Array
//
// Implementation of the Array class.
//
// Copyright (c) 2012, Applied Informatics Software Engineering GmbH.
// and Contributors.
//
@@ -24,7 +22,8 @@ namespace Poco {
namespace MongoDB {
Array::Array() : Document()
Array::Array():
Document()
{
}
@@ -47,26 +46,26 @@ std::string Array::toString(int indent) const
oss << "[";
if ( indent > 0 ) oss << std::endl;
if (indent > 0) oss << std::endl;
for(ElementSet::const_iterator it = _elements.begin(); it != _elements.end(); ++it)
for (ElementSet::const_iterator it = _elements.begin(); it != _elements.end(); ++it)
{
if ( it != _elements.begin() )
if (it != _elements.begin())
{
oss << ",";
if ( indent > 0 ) oss << std::endl;
if (indent > 0) oss << std::endl;
}
for(int i = 0; i < indent; ++i) oss << ' ';
for (int i = 0; i < indent; ++i) oss << ' ';
oss << (*it)->toString(indent > 0 ? indent + 2 : 0);
}
if ( indent > 0 )
if (indent > 0)
{
oss << std::endl;
if ( indent >= 2 ) indent -= 2;
for(int i = 0; i < indent; ++i) oss << ' ';
if (indent >= 2) indent -= 2;
for (int i = 0; i < indent; ++i) oss << ' ';
}
oss << "]";
@@ -75,4 +74,4 @@ std::string Array::toString(int indent) const
}
}} // Namespace Poco::Mongo
} } // Namespace Poco::Mongo

View File

@@ -7,8 +7,6 @@
// Package: MongoDB
// Module: Binary
//
// Implementation of the Binary class.
//
// Copyright (c) 2012, Applied Informatics Software Engineering GmbH.
// and Contributors.
//
@@ -76,9 +74,10 @@ std::string Binary::toString(int indent) const
return oss.str();
}
UUID Binary::uuid() const
{
if ( _subtype == 0x04 && _buffer.size() == 16 )
if (_subtype == 0x04 && _buffer.size() == 16)
{
UUID uuid;
uuid.copyFrom((const char*) _buffer.begin());
@@ -87,4 +86,5 @@ UUID Binary::uuid() const
throw BadCastException("Invalid subtype");
}
} } // namespace Poco::MongoDB

View File

@@ -7,8 +7,6 @@
// Package: MongoDB
// Module: Connection
//
// Implementation of the Connection class.
//
// Copyright (c) 2012, Applied Informatics Software Engineering GmbH.
// and Contributors.
//
@@ -18,41 +16,55 @@
#include "Poco/Net/SocketStream.h"
#include "Poco/MongoDB/Connection.h"
#include <iostream>
namespace Poco {
namespace MongoDB {
Connection::Connection() : _address(), _socket()
Connection::Connection():
_address(),
_socket()
{
}
Connection::Connection(const std::string& hostAndPort) : _address(hostAndPort), _socket()
Connection::Connection(const std::string& hostAndPort):
_address(hostAndPort),
_socket()
{
connect();
}
Connection::Connection(const std::string& host, int port) : _address(host, port), _socket()
Connection::Connection(const std::string& host, int port):
_address(host, port),
_socket()
{
connect();
}
Connection::Connection(const Net::SocketAddress& addrs) : _address(addrs), _socket()
Connection::Connection(const Poco::Net::SocketAddress& addrs):
_address(addrs),
_socket()
{
connect();
}
Connection::Connection(const Poco::Net::StreamSocket& socket):
_address(socket.peerAddress()),
_socket(socket)
{
}
Connection::~Connection()
{
try
{
_socket.close();
disconnect();
}
catch (...)
{
@@ -68,25 +80,32 @@ void Connection::connect()
void Connection::connect(const std::string& hostAndPort)
{
_address = Net::SocketAddress(hostAndPort);
_address = Poco::Net::SocketAddress(hostAndPort);
connect();
}
void Connection::connect(const std::string& host, int port)
{
_address = Net::SocketAddress(host, port);
_address = Poco::Net::SocketAddress(host, port);
connect();
}
void Connection::connect(const Net::SocketAddress& addrs)
void Connection::connect(const Poco::Net::SocketAddress& addrs)
{
_address = addrs;
connect();
}
void Connection::connect(const Poco::Net::StreamSocket& socket)
{
_address = socket.peerAddress();
_socket = socket;
}
void Connection::disconnect()
{
_socket.close();
@@ -95,7 +114,7 @@ void Connection::disconnect()
void Connection::sendRequest(RequestMessage& request)
{
Net::SocketOutputStream sos(_socket);
Poco::Net::SocketOutputStream sos(_socket);
request.send(sos);
}
@@ -104,8 +123,9 @@ void Connection::sendRequest(RequestMessage& request, ResponseMessage& response)
{
sendRequest(request);
Net::SocketInputStream sis(_socket);
Poco::Net::SocketInputStream sis(_socket);
response.read(sis);
}
} } // Poco::MongoDB

View File

@@ -7,8 +7,6 @@
// Package: MongoDB
// Module: Cursor
//
// Implementation of the Cursor class.
//
// Copyright (c) 2012, Applied Informatics Software Engineering GmbH.
// and Contributors.
//
@@ -25,14 +23,14 @@ namespace Poco {
namespace MongoDB {
Cursor::Cursor(const std::string& db, const std::string& collection, QueryRequest::Flags flags)
: _query(db + '.' + collection, flags)
Cursor::Cursor(const std::string& db, const std::string& collection, QueryRequest::Flags flags):
_query(db + '.' + collection, flags)
{
}
Cursor::Cursor(const std::string& fullCollectionName, QueryRequest::Flags flags)
: _query(fullCollectionName, flags)
Cursor::Cursor(const std::string& fullCollectionName, QueryRequest::Flags flags):
_query(fullCollectionName, flags)
{
}
@@ -42,7 +40,6 @@ Cursor::~Cursor()
try
{
poco_assert_dbg(!_response.cursorID());
}
catch (...)
{
@@ -52,7 +49,7 @@ Cursor::~Cursor()
ResponseMessage& Cursor::next(Connection& connection)
{
if ( _response.cursorID() == 0 )
if (_response.cursorID() == 0)
{
connection.sendRequest(_query, _response);
}
@@ -69,7 +66,7 @@ ResponseMessage& Cursor::next(Connection& connection)
void Cursor::kill(Connection& connection)
{
if ( _response.cursorID() != 0 )
if (_response.cursorID() != 0)
{
KillCursorsRequest killRequest;
killRequest.cursors().push_back(_response.cursorID());

View File

@@ -7,8 +7,6 @@
// Package: MongoDB
// Module: Database
//
// Implementation of the Database class.
//
// Copyright (c) 2012, Applied Informatics Software Engineering GmbH.
// and Contributors.
//
@@ -158,19 +156,11 @@ bool Database::authCR(Connection& connection, const std::string& username, const
if (response.documents().size() > 0)
{
Document::Ptr pDoc = response.documents()[0];
try
{
double ok = pDoc->get<double>("ok");
if (ok != 1) return false;
nonce = pDoc->get<std::string>("nonce", "");
if (nonce.empty()) return false;
}
catch (Poco::NotFoundException&)
{
return false;
}
if (pDoc->get<double>("ok") != 1) return false;
nonce = pDoc->get<std::string>("nonce", "");
if (nonce.empty()) throw Poco::ProtocolException("no nonce received");
}
else return false;
else throw Poco::ProtocolException("empty response for getnonce");
std::string credsDigest = hashCredentials(username, password);
@@ -191,15 +181,9 @@ bool Database::authCR(Connection& connection, const std::string& username, const
if (response.documents().size() > 0)
{
Document::Ptr pDoc = response.documents()[0];
try
{
return pDoc->get<double>("ok") == 1;
}
catch (Poco::NotFoundException&)
{
}
return pDoc->get<double>("ok") == 1;
}
return false;
else throw Poco::ProtocolException("empty response for authenticate");
}
@@ -224,22 +208,15 @@ bool Database::authSCRAM(Connection& connection, const std::string& username, co
if (response.documents().size() > 0)
{
Document::Ptr pDoc = response.documents()[0];
try
if (pDoc->get<double>("ok") == 1)
{
if (pDoc->get<double>("ok") == 1)
{
Binary::Ptr pPayload = pDoc->get<Binary::Ptr>("payload");
serverFirstMsg = pPayload->toRawString();
conversationId = pDoc->get<Int32>("conversationId");
}
else return false;
}
catch (Poco::NotFoundException&)
{
return false;
Binary::Ptr pPayload = pDoc->get<Binary::Ptr>("payload");
serverFirstMsg = pPayload->toRawString();
conversationId = pDoc->get<Int32>("conversationId");
}
else return false;
}
else return false;
else throw Poco::ProtocolException("empty response for saslStart");
std::map<std::string, std::string> kvm = parseKeyValueList(serverFirstMsg);
const std::string serverNonce = kvm["r"];
@@ -287,21 +264,14 @@ bool Database::authSCRAM(Connection& connection, const std::string& username, co
if (response.documents().size() > 0)
{
Document::Ptr pDoc = response.documents()[0];
try
if (pDoc->get<double>("ok") == 1)
{
if (pDoc->get<double>("ok") == 1)
{
Binary::Ptr pPayload = pDoc->get<Binary::Ptr>("payload");
serverSecondMsg.assign(reinterpret_cast<const char*>(pPayload->buffer().begin()), pPayload->buffer().size());
}
else return false;
}
catch (Poco::NotFoundException&)
{
return false;
Binary::Ptr pPayload = pDoc->get<Binary::Ptr>("payload");
serverSecondMsg.assign(reinterpret_cast<const char*>(pPayload->buffer().begin()), pPayload->buffer().size());
}
else return false;
}
else return false;
else throw Poco::ProtocolException("empty response for saslContinue");
Poco::HMACEngine<Poco::SHA1Engine> hmacSKey(saltedPassword);
hmacSKey.update(std::string("Server Key"));
@@ -314,7 +284,8 @@ bool Database::authSCRAM(Connection& connection, const std::string& username, co
kvm = parseKeyValueList(serverSecondMsg);
std::string serverSignatureReceived = kvm["v"];
if (serverSignature != serverSignatureReceived) return false;
if (serverSignature != serverSignatureReceived)
throw Poco::ProtocolException("server signature verification failed");
pCommand = createCommand();
pCommand->selector()
@@ -328,8 +299,7 @@ bool Database::authSCRAM(Connection& connection, const std::string& username, co
Document::Ptr pDoc = response.documents()[0];
return pDoc->get<double>("ok") == 1;
}
return false;
else throw Poco::ProtocolException("empty response for saslContinue");
}
@@ -340,7 +310,7 @@ Int64 Database::count(Connection& connection, const std::string& collectionName)
Poco::MongoDB::ResponseMessage response;
connection.sendRequest(*countRequest, response);
if ( response.documents().size() > 0 )
if (response.documents().size() > 0)
{
Poco::MongoDB::Document::Ptr doc = response.documents()[0];
return doc->getInteger("n");
@@ -357,22 +327,22 @@ Poco::MongoDB::Document::Ptr Database::ensureIndex(Connection& connection, const
index->add("name", indexName);
index->add("key", keys);
if ( version > 0 )
if (version > 0)
{
index->add("version", version);
}
if ( unique )
if (unique)
{
index->add("unique", true);
}
if ( background )
if (background)
{
index->add("background", true);
}
if ( ttl > 0 )
if (ttl > 0)
{
index->add("expireAfterSeconds", ttl);
}
@@ -396,7 +366,7 @@ Document::Ptr Database::getLastErrorDoc(Connection& connection) const
Poco::MongoDB::ResponseMessage response;
connection.sendRequest(*request, response);
if ( response.documents().size() > 0 )
if (response.documents().size() > 0)
{
errorDoc = response.documents()[0];
}
@@ -408,7 +378,7 @@ Document::Ptr Database::getLastErrorDoc(Connection& connection) const
std::string Database::getLastError(Connection& connection) const
{
Document::Ptr errorDoc = getLastErrorDoc(connection);
if ( !errorDoc.isNull() && errorDoc->isType<std::string>("err") )
if (!errorDoc.isNull() && errorDoc->isType<std::string>("err"))
{
return errorDoc->get<std::string>("err");
}

View File

@@ -7,8 +7,6 @@
// Package: MongoDB
// Module: DeleteRequest
//
// Implementation of the DeleteRequest class.
//
// Copyright (c) 2012, Applied Informatics Software Engineering GmbH.
// and Contributors.
//
@@ -23,8 +21,8 @@ namespace Poco {
namespace MongoDB {
DeleteRequest::DeleteRequest(const std::string& collectionName, DeleteRequest::Flags flags)
: RequestMessage(MessageHeader::Delete),
DeleteRequest::DeleteRequest(const std::string& collectionName, DeleteRequest::Flags flags):
RequestMessage(MessageHeader::OP_DELETE),
_flags(flags),
_fullCollectionName(collectionName),
_selector()
@@ -32,9 +30,9 @@ DeleteRequest::DeleteRequest(const std::string& collectionName, DeleteRequest::F
}
DeleteRequest::DeleteRequest(const std::string& collectionName, bool justOne)
: RequestMessage(MessageHeader::Delete),
_flags(justOne ? DELETE_SINGLE_REMOVE : DELETE_NONE),
DeleteRequest::DeleteRequest(const std::string& collectionName, bool justOne):
RequestMessage(MessageHeader::OP_DELETE),
_flags(justOne ? DELETE_SINGLE_REMOVE : DELETE_DEFAULT),
_fullCollectionName(collectionName),
_selector()
{

View File

@@ -7,8 +7,6 @@
// Package: MongoDB
// Module: Document
//
// Implementation of the Document class.
//
// Copyright (c) 2012, Applied Informatics Software Engineering GmbH.
// and Contributors.
//
@@ -44,7 +42,7 @@ Element::Ptr Document::get(const std::string& name) const
Element::Ptr element;
ElementSet::const_iterator it = std::find_if(_elements.begin(), _elements.end(), ElementFindByName(name));
if ( it != _elements.end() )
if (it != _elements.end())
{
return *it;
}
@@ -52,29 +50,31 @@ Element::Ptr Document::get(const std::string& name) const
return element;
}
Int64 Document::getInteger(const std::string& name) const
{
Element::Ptr element = get(name);
if ( element.isNull() ) throw NotFoundException(name);
if (element.isNull()) throw Poco::NotFoundException(name);
if ( ElementTraits<double>::TypeId == element->type() )
if (ElementTraits<double>::TypeId == element->type())
{
ConcreteElement<double>* concrete = dynamic_cast<ConcreteElement<double>* >(element.get());
if ( concrete != NULL ) return concrete->value();
ConcreteElement<double>* concrete = dynamic_cast<ConcreteElement<double>*>(element.get());
if (concrete) return concrete->value();
}
else if ( ElementTraits<Int32>::TypeId == element->type() )
else if (ElementTraits<Int32>::TypeId == element->type())
{
ConcreteElement<Int32>* concrete = dynamic_cast<ConcreteElement<Int32>* >(element.get());
if ( concrete != NULL ) return concrete->value();
ConcreteElement<Int32>* concrete = dynamic_cast<ConcreteElement<Int32>*>(element.get());
if (concrete) return concrete->value();
}
else if ( ElementTraits<Int64>::TypeId == element->type() )
else if (ElementTraits<Int64>::TypeId == element->type())
{
ConcreteElement<Int64>* concrete = dynamic_cast<ConcreteElement<Int64>* >(element.get());
if ( concrete != NULL ) return concrete->value();
ConcreteElement<Int64>* concrete = dynamic_cast<ConcreteElement<Int64>*>(element.get());
if (concrete) return concrete->value();
}
throw BadCastException("Invalid type mismatch!");
throw Poco::BadCastException("Invalid type mismatch!");
}
void Document::read(BinaryReader& reader)
{
int size;
@@ -83,13 +83,13 @@ void Document::read(BinaryReader& reader)
unsigned char type;
reader >> type;
while( type != '\0' )
while (type != '\0')
{
Element::Ptr element;
std::string name = BSONReader(reader).readCString();
switch(type)
switch (type)
{
case ElementTraits<double>::TypeId:
element = new ConcreteElement<double>(name, 0);
@@ -101,16 +101,16 @@ void Document::read(BinaryReader& reader)
element = new ConcreteElement<std::string>(name, "");
break;
case ElementTraits<Document::Ptr>::TypeId:
element = new ConcreteElement<Document::Ptr>(name, new Document());
element = new ConcreteElement<Document::Ptr>(name, new Document);
break;
case ElementTraits<Array::Ptr>::TypeId:
element = new ConcreteElement<Array::Ptr>(name, new Array());
element = new ConcreteElement<Array::Ptr>(name, new Array);
break;
case ElementTraits<Binary::Ptr>::TypeId:
element = new ConcreteElement<Binary::Ptr>(name, new Binary());
element = new ConcreteElement<Binary::Ptr>(name, new Binary);
break;
case ElementTraits<ObjectId::Ptr>::TypeId:
element = new ConcreteElement<ObjectId::Ptr>(name, new ObjectId());
element = new ConcreteElement<ObjectId::Ptr>(name, new ObjectId);
break;
case ElementTraits<bool>::TypeId:
element = new ConcreteElement<bool>(name, false);
@@ -158,31 +158,31 @@ std::string Document::toString(int indent) const
oss << '{';
if ( indent > 0 ) oss << std::endl;
if (indent > 0) oss << std::endl;
for(ElementSet::const_iterator it = _elements.begin(); it != _elements.end(); ++it)
for (ElementSet::const_iterator it = _elements.begin(); it != _elements.end(); ++it)
{
if ( it != _elements.begin() )
if (it != _elements.begin())
{
oss << ',';
if ( indent > 0 ) oss << std::endl;
if (indent > 0) oss << std::endl;
}
for(int i = 0; i < indent; ++i) oss << ' ';
for (int i = 0; i < indent; ++i) oss << ' ';
oss << '"' << (*it)->name() << '"';
oss << (( indent > 0 ) ? " : " : ":");
oss << (indent > 0 ? " : " : ":");
oss << (*it)->toString(indent > 0 ? indent + 2 : 0);
}
if ( indent > 0 )
if (indent > 0)
{
oss << std::endl;
if ( indent >= 2 ) indent -= 2;
if (indent >= 2) indent -= 2;
for(int i = 0; i < indent; ++i) oss << ' ';
for (int i = 0; i < indent; ++i) oss << ' ';
}
oss << '}';
@@ -193,7 +193,7 @@ std::string Document::toString(int indent) const
void Document::write(BinaryWriter& writer)
{
if ( _elements.empty() )
if (_elements.empty())
{
writer << 5;
}
@@ -201,7 +201,7 @@ void Document::write(BinaryWriter& writer)
{
std::stringstream sstream;
Poco::BinaryWriter tempWriter(sstream);
for(ElementSet::iterator it = _elements.begin(); it != _elements.end(); ++it)
for (ElementSet::iterator it = _elements.begin(); it != _elements.end(); ++it)
{
tempWriter << static_cast<unsigned char>((*it)->type());
BSONWriter(tempWriter).writeCString((*it)->name());

View File

@@ -7,8 +7,6 @@
// Package: MongoDB
// Module: Element
//
// Implementation of the Element class.
//
// Copyright (c) 2012, Applied Informatics Software Engineering GmbH.
// and Contributors.
//

View File

@@ -7,8 +7,6 @@
// Package: MongoDB
// Module: GetMoreRequest
//
// Implementation of the GetMoreRequest class.
//
// Copyright (c) 2012, Applied Informatics Software Engineering GmbH.
// and Contributors.
//
@@ -24,8 +22,8 @@ namespace Poco {
namespace MongoDB {
GetMoreRequest::GetMoreRequest(const std::string& collectionName, Int64 cursorID)
: RequestMessage(MessageHeader::GetMore),
GetMoreRequest::GetMoreRequest(const std::string& collectionName, Int64 cursorID):
RequestMessage(MessageHeader::OP_GET_MORE),
_fullCollectionName(collectionName),
_numberToReturn(100),
_cursorID(cursorID)

View File

@@ -7,8 +7,6 @@
// Package: MongoDB
// Module: InsertRequest
//
// Implementation of the InsertRequest class.
//
// Copyright (c) 2012, Applied Informatics Software Engineering GmbH.
// and Contributors.
//
@@ -23,8 +21,8 @@ namespace Poco {
namespace MongoDB {
InsertRequest::InsertRequest(const std::string& collectionName, Flags flags)
: RequestMessage(MessageHeader::Insert),
InsertRequest::InsertRequest(const std::string& collectionName, Flags flags):
RequestMessage(MessageHeader::OP_INSERT),
_flags(flags),
_fullCollectionName(collectionName)
{
@@ -38,12 +36,12 @@ InsertRequest::~InsertRequest()
void InsertRequest::buildRequest(BinaryWriter& writer)
{
//TODO: throw exception when no document is added
poco_assert (!_documents.empty());
writer << _flags;
BSONWriter bsonWriter(writer);
bsonWriter.writeCString(_fullCollectionName);
for(Document::Vector::iterator it = _documents.begin(); it != _documents.end(); ++it)
for (Document::Vector::iterator it = _documents.begin(); it != _documents.end(); ++it)
{
bsonWriter.write(*it);
}

View File

@@ -7,8 +7,6 @@
// Package: MongoDB
// Module: JavaScriptCode
//
// Implementation of the JavaScriptCode class.
//
// Copyright (c) 2012, Applied Informatics Software Engineering GmbH.
// and Contributors.
//

View File

@@ -7,8 +7,6 @@
// Package: MongoDB
// Module: KillCursorsRequest
//
// Implementation of the KillCursorsRequest class.
//
// Copyright (c) 2012, Applied Informatics Software Engineering GmbH.
// and Contributors.
//
@@ -23,8 +21,8 @@ namespace Poco {
namespace MongoDB {
KillCursorsRequest::KillCursorsRequest()
: RequestMessage(MessageHeader::KillCursors)
KillCursorsRequest::KillCursorsRequest():
RequestMessage(MessageHeader::OP_KILL_CURSORS)
{
}
@@ -38,7 +36,7 @@ void KillCursorsRequest::buildRequest(BinaryWriter& writer)
{
writer << 0; // 0 - reserved for future use
writer << _cursors.size();
for(std::vector<Int64>::iterator it = _cursors.begin(); it != _cursors.end(); ++it)
for (std::vector<Int64>::iterator it = _cursors.begin(); it != _cursors.end(); ++it)
{
writer << *it;
}

View File

@@ -7,8 +7,6 @@
// Package: MongoDB
// Module: Message
//
// Implementation of the Message class.
//
// Copyright (c) 2012, Applied Informatics Software Engineering GmbH.
// and Contributors.
//
@@ -23,7 +21,8 @@ namespace Poco {
namespace MongoDB {
Message::Message(MessageHeader::OpCode opcode) : _header(opcode)
Message::Message(MessageHeader::OpCode opcode):
_header(opcode)
{
}

View File

@@ -7,8 +7,6 @@
// Package: MongoDB
// Module: MessageHeader
//
// Implementation of the MessageHeader class.
//
// Copyright (c) 2012, Applied Informatics Software Engineering GmbH.
// and Contributors.
//
@@ -18,15 +16,17 @@
#include "Poco/MongoDB/Message.h"
#include "Poco/Exception.h"
#include "Poco/Net/SocketStream.h"
#include "Poco/StreamCopier.h"
namespace Poco {
namespace MongoDB {
MessageHeader::MessageHeader(OpCode opCode) : _messageLength(0), _requestID(0), _responseTo(0), _opCode(opCode)
MessageHeader::MessageHeader(OpCode opCode):
_messageLength(0),
_requestID(0),
_responseTo(0),
_opCode(opCode)
{
}

View File

@@ -7,42 +7,47 @@
// 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"
#include <cstring>
namespace Poco {
namespace MongoDB {
ObjectId::ObjectId()
{
memset(_id, 0, sizeof(_id));
std::memset(_id, 0, sizeof(_id));
}
ObjectId::ObjectId(const std::string& id)
{
poco_assert_dbg(id.size() == 24);
const char *p = id.c_str();
for (std::size_t i = 0; i < 12; ++i) {
const char* p = id.c_str();
for (std::size_t i = 0; i < 12; ++i)
{
_id[i] = fromHex(p);
p += 2;
}
}
ObjectId::ObjectId(const ObjectId& copy)
{
memcpy(_id, copy._id, sizeof(_id));
std::memcpy(_id, copy._id, sizeof(_id));
}
ObjectId::~ObjectId()
{
}
@@ -52,7 +57,7 @@ std::string ObjectId::toString(const std::string& fmt) const
{
std::string s;
for(int i = 0; i < 12; ++i)
for (int i = 0; i < 12; ++i)
{
s += format(fmt, (unsigned int) _id[i]);
}

View File

@@ -7,8 +7,6 @@
// Package: MongoDB
// Module: QueryRequest
//
// Implementation of the QueryRequest class.
//
// Copyright (c) 2012, Applied Informatics Software Engineering GmbH.
// and Contributors.
//
@@ -23,8 +21,8 @@ namespace Poco {
namespace MongoDB {
QueryRequest::QueryRequest(const std::string& collectionName, QueryRequest::Flags flags)
: RequestMessage(MessageHeader::Query),
QueryRequest::QueryRequest(const std::string& collectionName, QueryRequest::Flags flags):
RequestMessage(MessageHeader::OP_QUERY),
_flags(flags),
_fullCollectionName(collectionName),
_numberToSkip(0),
@@ -48,7 +46,7 @@ void QueryRequest::buildRequest(BinaryWriter& writer)
writer << _numberToReturn;
_selector.write(writer);
if ( ! _returnFieldSelector.empty() )
if (!_returnFieldSelector.empty())
{
_returnFieldSelector.write(writer);
}

View File

@@ -7,8 +7,6 @@
// Package: MongoDB
// Module: RegularExpression
//
// Implementation of the RegularExpression class.
//
// Copyright (c) 2012, Applied Informatics Software Engineering GmbH.
// and Contributors.
//
@@ -29,7 +27,9 @@ RegularExpression::RegularExpression()
}
RegularExpression::RegularExpression(const std::string& pattern, const std::string& options) : _pattern(pattern), _options(options)
RegularExpression::RegularExpression(const std::string& pattern, const std::string& options):
_pattern(pattern),
_options(options)
{
}
@@ -42,9 +42,9 @@ RegularExpression::~RegularExpression()
SharedPtr<Poco::RegularExpression> RegularExpression::createRE() const
{
int options = 0;
for(std::string::const_iterator optIt = _options.begin(); optIt != _options.end(); ++optIt)
for (std::string::const_iterator optIt = _options.begin(); optIt != _options.end(); ++optIt)
{
switch(*optIt)
switch (*optIt)
{
case 'i': // Case Insensitive
options |= Poco::RegularExpression::RE_CASELESS;

View File

@@ -7,8 +7,6 @@
// Package: MongoDB
// Module: ReplicaSet
//
// Implementation of the ReplicaSet class.
//
// Copyright (c) 2012, Applied Informatics Software Engineering GmbH.
// and Contributors.
//
@@ -20,11 +18,13 @@
#include "Poco/MongoDB/QueryRequest.h"
#include "Poco/MongoDB/ResponseMessage.h"
namespace Poco {
namespace MongoDB {
ReplicaSet::ReplicaSet(const std::vector<Net::SocketAddress> &addresses) : _addresses(addresses)
ReplicaSet::ReplicaSet(const std::vector<Net::SocketAddress> &addresses):
_addresses(addresses)
{
}
@@ -38,10 +38,10 @@ Connection::Ptr ReplicaSet::findMaster()
{
Connection::Ptr master;
for(std::vector<Net::SocketAddress>::iterator it = _addresses.begin(); it != _addresses.end(); ++it)
for (std::vector<Net::SocketAddress>::iterator it = _addresses.begin(); it != _addresses.end(); ++it)
{
master = isMaster(*it);
if ( ! master.isNull() )
if (!master.isNull())
{
break;
}
@@ -66,25 +66,25 @@ Connection::Ptr ReplicaSet::isMaster(const Net::SocketAddress& address)
ResponseMessage response;
conn->sendRequest(request, response);
if ( response.documents().size() > 0 )
if (response.documents().size() > 0)
{
Document::Ptr doc = response.documents()[0];
if ( doc->get<bool>("ismaster") )
if (doc->get<bool>("ismaster"))
{
return conn;
}
else if ( doc->exists("primary") )
else if (doc->exists("primary"))
{
return isMaster(Net::SocketAddress(doc->get<std::string>("primary")));
}
}
}
catch(...)
catch (...)
{
conn = NULL;
conn = 0;
}
return NULL;
return 0;
}

View File

@@ -7,8 +7,6 @@
// Package: MongoDB
// Module: RequestMessage
//
// Implementation of the RequestMessage class.
//
// Copyright (c) 2012, Applied Informatics Software Engineering GmbH.
// and Contributors.
//
@@ -25,7 +23,8 @@ namespace Poco {
namespace MongoDB {
RequestMessage::RequestMessage(MessageHeader::OpCode opcode) : Message(opcode)
RequestMessage::RequestMessage(MessageHeader::OpCode opcode):
Message(opcode)
{
}

View File

@@ -7,8 +7,6 @@
// Package: MongoDB
// Module: ResponseMessage
//
// Implementation of the ResponseMessage class.
//
// Copyright (c) 2012, Applied Informatics Software Engineering GmbH.
// and Contributors.
//
@@ -24,7 +22,12 @@ namespace Poco {
namespace MongoDB {
ResponseMessage::ResponseMessage() : Message(MessageHeader::Reply), _responseFlags(0), _cursorID(0), _startingFrom(0), _numberReturned(0)
ResponseMessage::ResponseMessage():
Message(MessageHeader::OP_REPLY),
_responseFlags(0),
_cursorID(0),
_startingFrom(0),
_numberReturned(0)
{
}
@@ -57,7 +60,7 @@ void ResponseMessage::read(std::istream& istr)
reader >> _startingFrom;
reader >> _numberReturned;
for(int i = 0; i < _numberReturned; ++i)
for (int i = 0; i < _numberReturned; ++i)
{
Document::Ptr doc = new Document();
doc->read(reader);

View File

@@ -7,8 +7,6 @@
// Package: MongoDB
// Module: UpdateRequest
//
// Implementation of the UpdateRequest class.
//
// Copyright (c) 2012, Applied Informatics Software Engineering GmbH.
// and Contributors.
//
@@ -23,8 +21,8 @@ namespace Poco {
namespace MongoDB {
UpdateRequest::UpdateRequest(const std::string& collectionName, UpdateRequest::Flags flags)
: RequestMessage(MessageHeader::Update),
UpdateRequest::UpdateRequest(const std::string& collectionName, UpdateRequest::Flags flags):
RequestMessage(MessageHeader::OP_UPDATE),
_flags(flags),
_fullCollectionName(collectionName),
_selector(),