| 1 | // |
|---|---|
| 2 | // Array.cpp |
| 3 | // |
| 4 | // Library: MongoDB |
| 5 | // Package: MongoDB |
| 6 | // Module: Array |
| 7 | // |
| 8 | // Copyright (c) 2012, Applied Informatics Software Engineering GmbH. |
| 9 | // and Contributors. |
| 10 | // |
| 11 | // SPDX-License-Identifier: BSL-1.0 |
| 12 | // |
| 13 | |
| 14 | |
| 15 | #include "Poco/MongoDB/Array.h" |
| 16 | #include <sstream> |
| 17 | |
| 18 | |
| 19 | namespace Poco { |
| 20 | namespace MongoDB { |
| 21 | |
| 22 | |
| 23 | Array::Array(): |
| 24 | Document() |
| 25 | { |
| 26 | } |
| 27 | |
| 28 | |
| 29 | Array::~Array() |
| 30 | { |
| 31 | } |
| 32 | |
| 33 | |
| 34 | Element::Ptr Array::get(int pos) const |
| 35 | { |
| 36 | std::string name = Poco::NumberFormatter::format(pos); |
| 37 | return Document::get(name); |
| 38 | } |
| 39 | |
| 40 | |
| 41 | std::string Array::toString(int indent) const |
| 42 | { |
| 43 | std::ostringstream oss; |
| 44 | |
| 45 | oss << "["; |
| 46 | |
| 47 | if (indent > 0) oss << std::endl; |
| 48 | |
| 49 | for (ElementSet::const_iterator it = _elements.begin(); it != _elements.end(); ++it) |
| 50 | { |
| 51 | if (it != _elements.begin()) |
| 52 | { |
| 53 | oss << ","; |
| 54 | if (indent > 0) oss << std::endl; |
| 55 | } |
| 56 | |
| 57 | for (int i = 0; i < indent; ++i) oss << ' '; |
| 58 | |
| 59 | oss << (*it)->toString(indent > 0 ? indent + 2 : 0); |
| 60 | } |
| 61 | |
| 62 | if (indent > 0) |
| 63 | { |
| 64 | oss << std::endl; |
| 65 | if (indent >= 2) indent -= 2; |
| 66 | for (int i = 0; i < indent; ++i) oss << ' '; |
| 67 | } |
| 68 | |
| 69 | oss << "]"; |
| 70 | |
| 71 | return oss.str(); |
| 72 | } |
| 73 | |
| 74 | |
| 75 | } } // Namespace Poco::Mongo |
| 76 |