summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorEliot Horowitz <eliot@10gen.com>2013-04-29 15:18:49 -0400
committerEliot Horowitz <eliot@10gen.com>2013-04-29 15:18:49 -0400
commitddd82aecad2179230b487285d6e081424550b7d8 (patch)
treebb1eee4c2483b1061788cb2cdfe041ddbfaff090 /src
parentb4ee2f8e1691d54391362513598d02fcf1f7aa82 (diff)
downloadmongo-ddd82aecad2179230b487285d6e081424550b7d8.tar.gz
SERVER-6400 - framework and start of Matcher replacement. using Matcher2 name
Diffstat (limited to 'src')
-rw-r--r--src/mongo/SConscript1
-rw-r--r--src/mongo/db/matcher/matcher.cpp43
-rw-r--r--src/mongo/db/matcher/matcher.h38
-rw-r--r--src/mongo/dbtests/matchertests.cpp12
4 files changed, 91 insertions, 3 deletions
diff --git a/src/mongo/SConscript b/src/mongo/SConscript
index 360e4d89efa..cd36650e456 100644
--- a/src/mongo/SConscript
+++ b/src/mongo/SConscript
@@ -271,6 +271,7 @@ env.StaticLibrary("coredb", [
"db/index_names.cpp",
"db/keypattern.cpp",
"db/matcher.cpp",
+ "db/matcher/matcher.cpp",
"db/pipeline/accumulator.cpp",
"db/pipeline/accumulator_add_to_set.cpp",
"db/pipeline/accumulator_avg.cpp",
diff --git a/src/mongo/db/matcher/matcher.cpp b/src/mongo/db/matcher/matcher.cpp
new file mode 100644
index 00000000000..4db18bb6e55
--- /dev/null
+++ b/src/mongo/db/matcher/matcher.cpp
@@ -0,0 +1,43 @@
+// matcher.cpp
+
+/**
+* Copyright (C) 2013 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 "mongo/pch.h"
+
+#include "mongo/db/matcher/expression_parser.h"
+#include "mongo/db/matcher/matcher.h"
+#include "mongo/util/mongoutils/str.h"
+
+namespace mongo {
+
+ Matcher2::Matcher2( const BSONObj& pattern )
+ : _pattern( pattern ) {
+
+ StatusWithExpression result = ExpressionParser::parse( pattern );
+ uassert( 16810,
+ mongoutils::str::stream() << "bad query: " << result.toString(),
+ result.isOK() );
+
+ _expression.reset( result.getValue() );
+ }
+
+ bool Matcher2::matches(const BSONObj& doc, MatchDetails* details ) const {
+ return _expression->matches( doc, details );
+ }
+
+
+}
diff --git a/src/mongo/db/matcher/matcher.h b/src/mongo/db/matcher/matcher.h
new file mode 100644
index 00000000000..ced17a44c84
--- /dev/null
+++ b/src/mongo/db/matcher/matcher.h
@@ -0,0 +1,38 @@
+// matcher.h
+
+/**
+* Copyright (C) 2013 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/>.
+*/
+
+#pragma once
+
+#include "mongo/bson/bsonobj.h"
+#include "mongo/db/matcher/expression.h"
+#include "mongo/db/matcher/match_details.h"
+
+namespace mongo {
+
+ class Matcher2 : boost::noncopyable {
+ public:
+ Matcher2( const BSONObj& pattern );
+
+ bool matches(const BSONObj& doc, MatchDetails* details = NULL ) const;
+
+ private:
+ const BSONObj& _pattern; // this is owned by who created us
+ boost::scoped_ptr<Expression> _expression;
+ };
+
+}
diff --git a/src/mongo/dbtests/matchertests.cpp b/src/mongo/dbtests/matchertests.cpp
index 1830d531962..2142fe4a3c6 100644
--- a/src/mongo/dbtests/matchertests.cpp
+++ b/src/mongo/dbtests/matchertests.cpp
@@ -25,6 +25,7 @@
#include "mongo/db/json.h"
#include "mongo/db/namespace_details.h"
#include "mongo/db/query_optimizer.h"
+#include "mongo/db/matcher/matcher.h"
#include "mongo/dbtests/dbtests.h"
#include "mongo/util/timer.h"
@@ -45,12 +46,13 @@ namespace MatcherTests {
const char * const _ns;
DBDirectClient _client;
};
-
+
+ template <typename M>
class Basic {
public:
void run() {
BSONObj query = fromjson( "{\"a\":\"b\"}" );
- Matcher m( query );
+ M m( query );
ASSERT( m.matches( fromjson( "{\"a\":\"b\"}" ) ) );
}
};
@@ -399,8 +401,12 @@ namespace MatcherTests {
All() : Suite( "matcher" ) {
}
+#define ADD_BOTH(TEST) \
+ add< TEST<Matcher> >(); \
+ add< TEST<Matcher2> >();
+
void setupTests() {
- add<Basic>();
+ ADD_BOTH(Basic);
add<DoubleEqual>();
add<MixedNumericEqual>();
add<MixedNumericGt>();