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.
|
|
|
|
//
|
2014-05-04 21:02:42 +02:00
|
|
|
// 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
|
|
|
|
2017-02-13 15:53:08 +01:00
|
|
|
Array::Array():
|
|
|
|
Document()
|
2013-02-02 21:52:49 +01:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Array::~Array()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2013-02-14 22:50:55 +01:00
|
|
|
|
2013-02-27 19:51:33 +01:00
|
|
|
Element::Ptr Array::get(int pos) const
|
|
|
|
{
|
|
|
|
std::string name = Poco::NumberFormatter::format(pos);
|
|
|
|
return Document::get(name);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-02-15 22:32:24 +01:00
|
|
|
std::string Array::toString(int indent) const
|
2013-02-14 22:50:55 +01:00
|
|
|
{
|
|
|
|
std::ostringstream oss;
|
2013-03-09 20:45:22 +01:00
|
|
|
|
2013-02-15 22:32:24 +01:00
|
|
|
oss << "[";
|
2013-03-09 20:45:22 +01:00
|
|
|
|
2017-02-13 15:53:08 +01:00
|
|
|
if (indent > 0) oss << std::endl;
|
2013-02-15 22:32:24 +01:00
|
|
|
|
2017-02-13 15:53:08 +01:00
|
|
|
for (ElementSet::const_iterator it = _elements.begin(); it != _elements.end(); ++it)
|
2013-02-14 22:50:55 +01:00
|
|
|
{
|
2017-02-13 15:53:08 +01:00
|
|
|
if (it != _elements.begin())
|
2013-02-14 22:50:55 +01:00
|
|
|
{
|
2013-02-15 22:32:24 +01:00
|
|
|
oss << ",";
|
2017-02-13 15:53:08 +01:00
|
|
|
if (indent > 0) oss << std::endl;
|
2013-02-14 22:50:55 +01:00
|
|
|
}
|
2013-02-17 18:41:36 +01:00
|
|
|
|
2017-02-13 15:53:08 +01:00
|
|
|
for (int i = 0; i < indent; ++i) oss << ' ';
|
2013-03-09 20:45:22 +01:00
|
|
|
|
2017-02-12 23:13:51 +01:00
|
|
|
oss << (*it)->toString(indent > 0 ? indent + 2 : 0);
|
2013-02-14 22:50:55 +01:00
|
|
|
}
|
2013-02-15 22:32:24 +01:00
|
|
|
|
2017-02-13 15:53:08 +01:00
|
|
|
if (indent > 0)
|
2013-02-15 22:32:24 +01:00
|
|
|
{
|
|
|
|
oss << std::endl;
|
2017-02-13 15:53:08 +01:00
|
|
|
if (indent >= 2) indent -= 2;
|
|
|
|
for (int i = 0; i < indent; ++i) oss << ' ';
|
2013-02-15 22:32:24 +01:00
|
|
|
}
|
|
|
|
|
2013-02-17 18:41:36 +01:00
|
|
|
oss << "]";
|
|
|
|
|
2013-02-14 22:50:55 +01:00
|
|
|
return oss.str();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-02-13 15:53:08 +01:00
|
|
|
} } // Namespace Poco::Mongo
|