summaryrefslogtreecommitdiff
path: root/src/mongo/db/matcher/schema/expression_internal_schema_xor.h
diff options
context:
space:
mode:
authorAnne Lim <anne.lim@mongodb.com>2017-07-05 11:19:40 -0400
committerAnne Lim <anne.lim@mongodb.com>2017-07-05 11:19:40 -0400
commit4ca0e0a50a58dc1cb3b798c962e943170162c1ec (patch)
tree0487c7fd372a6cec4ed614a30b7f6ca77ba24348 /src/mongo/db/matcher/schema/expression_internal_schema_xor.h
parent1323edbe69bc44d6911169486de33fb59233ff8f (diff)
downloadmongo-4ca0e0a50a58dc1cb3b798c962e943170162c1ec.tar.gz
SERVER-29575: Add an $_internalSchemaXor MatchExpression
Diffstat (limited to 'src/mongo/db/matcher/schema/expression_internal_schema_xor.h')
-rw-r--r--src/mongo/db/matcher/schema/expression_internal_schema_xor.h64
1 files changed, 64 insertions, 0 deletions
diff --git a/src/mongo/db/matcher/schema/expression_internal_schema_xor.h b/src/mongo/db/matcher/schema/expression_internal_schema_xor.h
new file mode 100644
index 00000000000..2c3c65f9147
--- /dev/null
+++ b/src/mongo/db/matcher/schema/expression_internal_schema_xor.h
@@ -0,0 +1,64 @@
+/**
+ * Copyright (C) 2017 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.
+ */
+
+#pragma once
+
+#include "mongo/db/matcher/expression_tree.h"
+
+namespace mongo {
+
+/**
+ * MatchExpression for $_internalSchemaXor keyword. Returns true only if exactly
+ * one of its child nodes matches.
+ */
+class InternalSchemaXorMatchExpression final : public ListOfMatchExpression {
+public:
+ static constexpr StringData kInternalSchemaXor = "$_internalSchemaXor"_sd;
+
+ InternalSchemaXorMatchExpression() : ListOfMatchExpression(INTERNAL_SCHEMA_XOR) {}
+
+ bool matches(const MatchableDocument* doc, MatchDetails* details = nullptr) const final;
+
+ bool matchesSingleElement(const BSONElement& element) const final;
+
+ virtual std::unique_ptr<MatchExpression> shallowClone() const {
+ auto xorCopy = stdx::make_unique<InternalSchemaXorMatchExpression>();
+ for (size_t i = 0; i < numChildren(); ++i) {
+ xorCopy->add(getChild(i)->shallowClone().release());
+ }
+ if (getTag()) {
+ xorCopy->setTag(getTag()->clone());
+ }
+ return std::move(xorCopy);
+ }
+
+ void debugString(StringBuilder& debug, int level = 0) const final;
+
+ void serialize(BSONObjBuilder* out) const final;
+};
+} // namespace mongo \ No newline at end of file