diff options
author | Eliot Horowitz <eliot@10gen.com> | 2013-04-29 15:18:49 -0400 |
---|---|---|
committer | Eliot Horowitz <eliot@10gen.com> | 2013-04-29 15:18:49 -0400 |
commit | ddd82aecad2179230b487285d6e081424550b7d8 (patch) | |
tree | bb1eee4c2483b1061788cb2cdfe041ddbfaff090 /src/mongo/db | |
parent | b4ee2f8e1691d54391362513598d02fcf1f7aa82 (diff) | |
download | mongo-ddd82aecad2179230b487285d6e081424550b7d8.tar.gz |
SERVER-6400 - framework and start of Matcher replacement. using Matcher2 name
Diffstat (limited to 'src/mongo/db')
-rw-r--r-- | src/mongo/db/matcher/matcher.cpp | 43 | ||||
-rw-r--r-- | src/mongo/db/matcher/matcher.h | 38 |
2 files changed, 81 insertions, 0 deletions
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; + }; + +} |