diff options
author | Eliot Horowitz <eliot@10gen.com> | 2010-04-13 15:23:57 -0400 |
---|---|---|
committer | Eliot Horowitz <eliot@10gen.com> | 2010-04-13 15:23:57 -0400 |
commit | 61ae5fa244e5a38b1778d2bd8df21211b0edcfd1 (patch) | |
tree | 845b29b1c0e7f932b15c3d3338297cc523f7518b /db/matcher_covered.cpp | |
parent | 552fe0fc2c60202e3a437e3c37a9347b68533941 (diff) | |
download | mongo-61ae5fa244e5a38b1778d2bd8df21211b0edcfd1.tar.gz |
a bunch of refactoring for mongos linking
Diffstat (limited to 'db/matcher_covered.cpp')
-rw-r--r-- | db/matcher_covered.cpp | 72 |
1 files changed, 72 insertions, 0 deletions
diff --git a/db/matcher_covered.cpp b/db/matcher_covered.cpp new file mode 100644 index 00000000000..6ed31ee0524 --- /dev/null +++ b/db/matcher_covered.cpp @@ -0,0 +1,72 @@ +// matcher_covered.cpp + +/* Matcher is our boolean expression evaluator for "where" clauses */ + +/** +* Copyright (C) 2008 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 "stdafx.h" +#include "matcher.h" +#include "../util/goodies.h" +#include "../util/unittest.h" +#include "diskloc.h" +#include "../scripting/engine.h" +#include "db.h" +#include "client.h" + +#include "pdfile.h" + +namespace mongo { + + CoveredIndexMatcher::CoveredIndexMatcher(const BSONObj &jsobj, const BSONObj &indexKeyPattern) : + _keyMatcher(jsobj.filterFieldsUndotted(indexKeyPattern, true), + indexKeyPattern), + _docMatcher(jsobj) + { + _needRecord = ! ( + _docMatcher.keyMatch() && + _keyMatcher.jsobj.nFields() == _docMatcher.jsobj.nFields() && + ! _keyMatcher.hasType( BSONObj::opEXISTS ) + ); + + } + + bool CoveredIndexMatcher::matchesCurrent( Cursor * cursor , MatchDetails * details ){ + return matches( cursor->currKey() , cursor->currLoc() , details ); + } + + bool CoveredIndexMatcher::matches(const BSONObj &key, const DiskLoc &recLoc , MatchDetails * details ) { + if ( details ) + details->reset(); + + if ( _keyMatcher.keyMatch() ) { + if ( !_keyMatcher.matches(key, details ) ){ + return false; + } + } + + if ( ! _needRecord ){ + return true; + } + + if ( details ) + details->loadedObject = true; + + return _docMatcher.matches(recLoc.rec() , details ); + } + + +} |