diff options
author | Charlie Swanson <charlie.swanson@mongodb.com> | 2016-06-09 19:09:42 -0400 |
---|---|---|
committer | Charlie Swanson <charlie.swanson@mongodb.com> | 2016-06-24 11:51:21 -0400 |
commit | 46b4dfbdefe018e1f125a5ebac8b584b20274502 (patch) | |
tree | 9c6fea4905fdb235833d2f2010231dbacdcffb2f /src/mongo/db/pipeline/document_source_tee_consumer.cpp | |
parent | 20e9b2798d69fb2367ff9f16a1b30f4f9b73d93b (diff) | |
download | mongo-46b4dfbdefe018e1f125a5ebac8b584b20274502.tar.gz |
SERVER-23654 Add $facet aggregation stage
Diffstat (limited to 'src/mongo/db/pipeline/document_source_tee_consumer.cpp')
-rw-r--r-- | src/mongo/db/pipeline/document_source_tee_consumer.cpp | 81 |
1 files changed, 81 insertions, 0 deletions
diff --git a/src/mongo/db/pipeline/document_source_tee_consumer.cpp b/src/mongo/db/pipeline/document_source_tee_consumer.cpp new file mode 100644 index 00000000000..321d228b7cc --- /dev/null +++ b/src/mongo/db/pipeline/document_source_tee_consumer.cpp @@ -0,0 +1,81 @@ +/** + * Copyright (C) 2016 MongoDB 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/>. + * + * As a special exception, the copyright holders give permission to link the + * code of portions of this program with the OpenSSL library under certain + * conditions as described in each individual source file and distribute + * linked combinations including the program with the OpenSSL library. You + * must comply with the GNU Affero General Public License in all respects for + * all of the code used other than as permitted herein. If you modify file(s) + * with this exception, you may extend this exception to your version of the + * file(s), but you are not obligated to do so. If you do not wish to do so, + * delete this exception statement from your version. If you delete this + * exception statement from all source files in the program, then also delete + * it in the license file. + */ + +#include "mongo/platform/basic.h" + +#include "mongo/db/pipeline/document_source_tee_consumer.h" + +#include <boost/intrusive_ptr.hpp> +#include <boost/optional.hpp> +#include <vector> + +#include "mongo/db/pipeline/document.h" +#include "mongo/db/pipeline/expression_context.h" + +namespace mongo { + +using boost::intrusive_ptr; + +DocumentSourceTeeConsumer::DocumentSourceTeeConsumer(const intrusive_ptr<ExpressionContext>& expCtx, + const intrusive_ptr<TeeBuffer>& bufferSource) + : DocumentSource(expCtx), _bufferSource(bufferSource), _iterator() {} + +boost::intrusive_ptr<DocumentSourceTeeConsumer> DocumentSourceTeeConsumer::create( + const boost::intrusive_ptr<ExpressionContext>& expCtx, + const boost::intrusive_ptr<TeeBuffer>& bufferSource) { + return new DocumentSourceTeeConsumer(expCtx, bufferSource); +} + +boost::optional<Document> DocumentSourceTeeConsumer::getNext() { + pExpCtx->checkForInterrupt(); + + if (!_initialized) { + _bufferSource->populate(); + _initialized = true; + _iterator = _bufferSource->begin(); + } + + if (_iterator == _bufferSource->end()) { + return boost::none; + } + + return {*_iterator++}; +} + +void DocumentSourceTeeConsumer::dispose() { + // Release our reference to the buffer. We shouldn't call dispose() on the buffer, since there + // might be other consumers that need to use it. + _bufferSource.reset(); +} + +Value DocumentSourceTeeConsumer::serialize(bool explain) const { + // This stage will be inserted into the beginning of a pipeline, but should not show up in the + // explain output. + return Value(); +} +} // namespace mongo |