summaryrefslogtreecommitdiff
path: root/src/mongo/db/pipeline/document_source_queue.cpp
diff options
context:
space:
mode:
authorCharlie Swanson <charlie.swanson@mongodb.com>2019-05-08 09:45:50 -0400
committerCharlie Swanson <charlie.swanson@mongodb.com>2019-05-21 11:20:22 -0400
commit1397d1398b3b9b1723cd9b93de6b345f940a17e8 (patch)
tree8c087879396b984caa369d2c4d107a03538e95bf /src/mongo/db/pipeline/document_source_queue.cpp
parenta3638ccc4889436984eb385cb7717eecd6af83cf (diff)
downloadmongo-1397d1398b3b9b1723cd9b93de6b345f940a17e8.tar.gz
SERVER-40539 Add DocumentSourceQueue
This stage is distinguished from the Mock stage in that it doesn't bother tracking state about which methods have been called. The queue version is simpler and is used in production code (namely the update system), whereas the mock is still preferred in testing environments.
Diffstat (limited to 'src/mongo/db/pipeline/document_source_queue.cpp')
-rw-r--r--src/mongo/db/pipeline/document_source_queue.cpp58
1 files changed, 58 insertions, 0 deletions
diff --git a/src/mongo/db/pipeline/document_source_queue.cpp b/src/mongo/db/pipeline/document_source_queue.cpp
new file mode 100644
index 00000000000..80559de1a71
--- /dev/null
+++ b/src/mongo/db/pipeline/document_source_queue.cpp
@@ -0,0 +1,58 @@
+/**
+ * Copyright (C) 2019-present MongoDB, Inc.
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the Server Side Public License, version 1,
+ * as published by MongoDB, Inc.
+ *
+ * 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
+ * Server Side Public License for more details.
+ *
+ * You should have received a copy of the Server Side Public License
+ * along with this program. If not, see
+ * <http://www.mongodb.com/licensing/server-side-public-license>.
+ *
+ * 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 Server Side 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_queue.h"
+
+namespace mongo {
+
+boost::intrusive_ptr<DocumentSourceQueue> DocumentSourceQueue::create(
+ const boost::intrusive_ptr<ExpressionContext>& expCtx) {
+ return new DocumentSourceQueue({}, expCtx);
+}
+
+DocumentSourceQueue::DocumentSourceQueue(std::deque<GetNextResult> results,
+ const boost::intrusive_ptr<ExpressionContext>& expCtx)
+ : DocumentSource(expCtx), _queue(std::move(results)) {}
+
+const char* DocumentSourceQueue::getSourceName() const {
+ return kStageName.rawData();
+}
+
+DocumentSource::GetNextResult DocumentSourceQueue::getNext() {
+ if (_queue.empty()) {
+ return GetNextResult::makeEOF();
+ }
+
+ auto next = std::move(_queue.front());
+ _queue.pop_front();
+ return next;
+}
+}