poco/MongoDB/src/Array.cpp

76 lines
1.1 KiB
C++
Raw Normal View History

2013-02-02 21:52:49 +01:00
//
// Array.cpp
//
// Library: MongoDB
// Package: MongoDB
// Module: Array
//
// Copyright (c) 2012, Applied Informatics Software Engineering GmbH.
// and Contributors.
//
// SPDX-License-Identifier: BSL-1.0
2013-02-02 21:52:49 +01:00
//
2013-03-17 19:34:36 +01:00
2013-02-02 21:52:49 +01:00
#include "Poco/MongoDB/Array.h"
2013-03-17 19:34:36 +01:00
#include <sstream>
2013-02-02 21:52:49 +01:00
2013-02-13 19:10:57 +01:00
namespace Poco {
namespace MongoDB {
2013-02-02 21:52:49 +01:00
2013-03-17 19:34:36 +01:00
Array::Array():
Document()
2013-02-02 21:52:49 +01:00
{
}
Array::~Array()
{
}
2013-02-14 22:50:55 +01:00
Element::Ptr Array::get(int pos) const
{
std::string name = Poco::NumberFormatter::format(pos);
return Document::get(name);
}
std::string Array::toString(int indent) const
2013-02-14 22:50:55 +01:00
{
std::ostringstream oss;
oss << "[";
if (indent > 0) oss << std::endl;
for (ElementSet::const_iterator it = _elements.begin(); it != _elements.end(); ++it)
2013-02-14 22:50:55 +01:00
{
if (it != _elements.begin())
2013-02-14 22:50:55 +01:00
{
oss << ",";
if (indent > 0) oss << std::endl;
2013-02-14 22:50:55 +01:00
}
2013-02-17 18:41:36 +01:00
for (int i = 0; i < indent; ++i) oss << ' ';
oss << (*it)->toString(indent > 0 ? indent + 2 : 0);
2013-02-14 22:50:55 +01:00
}
if (indent > 0)
{
oss << std::endl;
if (indent >= 2) indent -= 2;
for (int i = 0; i < indent; ++i) oss << ' ';
}
2013-02-17 18:41:36 +01:00
oss << "]";
2013-02-14 22:50:55 +01:00
return oss.str();
}
} } // Namespace Poco::Mongo