blob: 5d187b03ef910d4395f5a044d74942d078183b50 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
|
/**
* Copyright 2011 (c) 10gen Inc.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License, version 3,
* as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "pch.h"
#include "db/pipeline/document_source.h"
#include "db/pipeline/document.h"
namespace mongo {
DocumentSourceBsonArray::~DocumentSourceBsonArray() {
}
bool DocumentSourceBsonArray::eof() {
return !haveCurrent;
}
bool DocumentSourceBsonArray::advance() {
if (eof())
return false;
if (!arrayIterator.more()) {
haveCurrent = false;
return false;
}
currentElement = arrayIterator.next();
return true;
}
intrusive_ptr<Document> DocumentSourceBsonArray::getCurrent() {
assert(haveCurrent);
BSONObj documentObj(currentElement.Obj());
intrusive_ptr<Document> pDocument(
Document::createFromBsonObj(&documentObj));
return pDocument;
}
void DocumentSourceBsonArray::setSource(
const intrusive_ptr<DocumentSource> &pSource) {
/* this doesn't take a source */
assert(false);
}
DocumentSourceBsonArray::DocumentSourceBsonArray(
BSONElement *pBsonElement):
embeddedObject(pBsonElement->embeddedObject()),
arrayIterator(embeddedObject),
haveCurrent(false) {
if (arrayIterator.more()) {
currentElement = arrayIterator.next();
haveCurrent = true;
}
}
intrusive_ptr<DocumentSourceBsonArray> DocumentSourceBsonArray::create(
BSONElement *pBsonElement) {
assert(pBsonElement->type() == Array);
intrusive_ptr<DocumentSourceBsonArray> pSource(
new DocumentSourceBsonArray(pBsonElement));
return pSource;
}
void DocumentSourceBsonArray::sourceToBson(BSONObjBuilder *pBuilder) const {
assert(false); // this has no analog in the BSON world
}
}
|