summaryrefslogtreecommitdiff
path: root/src/mongo/db/matcher/expression_where_noop.cpp
diff options
context:
space:
mode:
authorJason Rassi <rassi@10gen.com>2015-10-30 14:51:02 -0400
committerJason Rassi <rassi@10gen.com>2015-11-06 12:08:52 -0500
commit81aca0ec6827eaffd54c91af46f9041ce62587c4 (patch)
tree17957a7ad33ad80d6c059a891434a0b924ec2e55 /src/mongo/db/matcher/expression_where_noop.cpp
parentd393cfcf7fefe99b1ffba05ce6282bb5c97f20fb (diff)
downloadmongo-81aca0ec6827eaffd54c91af46f9041ce62587c4.tar.gz
SERVER-19510 Refactor WhereMatchExpression/WhereNoOpMatchExpression
- Moves ExtensionsCallbackReal and ExtensionsCallbackNoop to their own files, and introduces a new library 'expressions_mongod_only' in db/matcher/. - Introduces a common base class for WhereMatchExpression and WhereNoOpMatchExpression. - Introduces a protected method extractWhereMatchExpressionParams() on ExtensionsCallback.
Diffstat (limited to 'src/mongo/db/matcher/expression_where_noop.cpp')
-rw-r--r--src/mongo/db/matcher/expression_where_noop.cpp113
1 files changed, 16 insertions, 97 deletions
diff --git a/src/mongo/db/matcher/expression_where_noop.cpp b/src/mongo/db/matcher/expression_where_noop.cpp
index ccb64190690..23bb7c287e5 100644
--- a/src/mongo/db/matcher/expression_where_noop.cpp
+++ b/src/mongo/db/matcher/expression_where_noop.cpp
@@ -29,110 +29,29 @@
*/
#include "mongo/platform/basic.h"
-#include "mongo/base/init.h"
-#include "mongo/db/matcher/expression.h"
-#include "mongo/db/matcher/expression_parser.h"
-#include "mongo/stdx/memory.h"
-
-namespace mongo {
-
-using std::unique_ptr;
-using std::string;
-using stdx::make_unique;
-
-/**
- * Bogus no-op $where match expression to parse $where in mongos,
- * since mongos doesn't have script engine to compile JS functions.
- *
- * Linked into mongos, instead of the real WhereMatchExpression.
- */
-class WhereNoOpMatchExpression : public MatchExpression {
-public:
- WhereNoOpMatchExpression() : MatchExpression(WHERE) {}
- virtual ~WhereNoOpMatchExpression() {}
-
- Status init(StringData theCode);
-
- virtual bool matches(const MatchableDocument* doc, MatchDetails* details = 0) const {
- return false;
- }
-
- virtual bool matchesSingleElement(const BSONElement& e) const {
- return false;
- }
-
- virtual unique_ptr<MatchExpression> shallowClone() const {
- unique_ptr<WhereNoOpMatchExpression> e = make_unique<WhereNoOpMatchExpression>();
- e->init(_code);
- if (getTag()) {
- e->setTag(getTag()->clone());
- }
- return std::move(e);
- }
-
- virtual void debugString(StringBuilder& debug, int level = 0) const;
-
- virtual void toBSON(BSONObjBuilder* out) const;
- virtual bool equivalent(const MatchExpression* other) const;
+#include "mongo/db/matcher/expression_where_noop.h"
- virtual void resetTag() {
- setTag(NULL);
- }
-
-private:
- string _code;
-};
-
-Status WhereNoOpMatchExpression::init(StringData theCode) {
- if (theCode.size() == 0)
- return Status(ErrorCodes::BadValue, "code for $where cannot be empty");
-
- _code = theCode.toString();
-
- return Status::OK();
-}
-
-void WhereNoOpMatchExpression::debugString(StringBuilder& debug, int level) const {
- _debugAddSpace(debug, level);
- debug << "$where (only in mongos)\n";
+#include "mongo/stdx/memory.h"
- _debugAddSpace(debug, level + 1);
- debug << "code: " << _code << "\n";
-}
+namespace mongo {
-void WhereNoOpMatchExpression::toBSON(BSONObjBuilder* out) const {
- out->append("$where", _code);
-}
+WhereNoOpMatchExpression::WhereNoOpMatchExpression(WhereParams params)
+ : WhereMatchExpressionBase(std::move(params)) {}
-bool WhereNoOpMatchExpression::equivalent(const MatchExpression* other) const {
- if (matchType() != other->matchType())
- return false;
- const WhereNoOpMatchExpression* noopOther = static_cast<const WhereNoOpMatchExpression*>(other);
- return _code == noopOther->_code;
+bool WhereNoOpMatchExpression::matches(const MatchableDocument* doc, MatchDetails* details) const {
+ return false;
}
-
-// -----------------
-
-ExtensionsCallbackNoop::ExtensionsCallbackNoop() {}
-
-StatusWithMatchExpression ExtensionsCallbackNoop::parseWhere(const BSONElement& where) const {
- unique_ptr<WhereNoOpMatchExpression> exp(new WhereNoOpMatchExpression());
- if (where.type() == String || where.type() == Code) {
- Status s = exp->init(where.valuestr());
- if (!s.isOK())
- return StatusWithMatchExpression(s);
- return {std::move(exp)};
- }
-
- if (where.type() == CodeWScope) {
- Status s = exp->init(where.codeWScopeCode());
- if (!s.isOK())
- return StatusWithMatchExpression(s);
- return {std::move(exp)};
+std::unique_ptr<MatchExpression> WhereNoOpMatchExpression::shallowClone() const {
+ WhereParams params;
+ params.code = getCode();
+ params.scope = getScope();
+ std::unique_ptr<WhereNoOpMatchExpression> e =
+ stdx::make_unique<WhereNoOpMatchExpression>(std::move(params));
+ if (getTag()) {
+ e->setTag(getTag()->clone());
}
-
- return StatusWithMatchExpression(ErrorCodes::BadValue, "$where got bad type");
+ return std::move(e);
}
}