summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--db/btree.h2
-rw-r--r--db/cloner.cpp2
-rw-r--r--db/cursor.h2
-rw-r--r--db/jsobj.cpp2
-rw-r--r--db/matcher.cpp44
-rw-r--r--db/matcher.h39
-rw-r--r--db/update.h6
-rw-r--r--dbtests/matchertests.cpp12
8 files changed, 54 insertions, 55 deletions
diff --git a/db/btree.h b/db/btree.h
index 09a832878cd..2c2ab81e95a 100644
--- a/db/btree.h
+++ b/db/btree.h
@@ -257,7 +257,7 @@ namespace mongo {
virtual void noteLocation(); // updates keyAtKeyOfs...
virtual void checkLocation();
- /* used for multikey index traversal to avoid sending back dups. see JSMatcher::matches().
+ /* used for multikey index traversal to avoid sending back dups. see Matcher::matches().
if a multikey index traversal:
if loc has already been sent, returns true.
otherwise, marks loc as sent.
diff --git a/db/cloner.cpp b/db/cloner.cpp
index 6fd1ffe1ee2..862f37c41ba 100644
--- a/db/cloner.cpp
+++ b/db/cloner.cpp
@@ -347,7 +347,7 @@ namespace mongo {
}
void Cloner::replayOpLog( DBClientCursor *c, const BSONObj &query ) {
- JSMatcher matcher( query );
+ Matcher matcher( query );
while( 1 ) {
BSONObj op;
{
diff --git a/db/cursor.h b/db/cursor.h
index c447b2bdecd..3868cca46b7 100644
--- a/db/cursor.h
+++ b/db/cursor.h
@@ -81,7 +81,7 @@ namespace mongo {
return "abstract?";
}
- /* used for multikey index traversal to avoid sending back dups. see JSMatcher::matches().
+ /* used for multikey index traversal to avoid sending back dups. see Matcher::matches().
if a multikey index traversal:
if loc has already been sent, returns true.
otherwise, marks loc as sent.
diff --git a/db/jsobj.cpp b/db/jsobj.cpp
index 8f5a83d70b9..c4c4bbf1dfd 100644
--- a/db/jsobj.cpp
+++ b/db/jsobj.cpp
@@ -600,7 +600,7 @@ namespace mongo {
}
}
- /* JSMatcher --------------------------------------*/
+ /* Matcher --------------------------------------*/
// If the element is something like:
// a : { $gt : 3 }
diff --git a/db/matcher.cpp b/db/matcher.cpp
index 0cb22e0140e..d71b7ef6f0f 100644
--- a/db/matcher.cpp
+++ b/db/matcher.cpp
@@ -1,6 +1,6 @@
// matcher.cpp
-/* JSMatcher is our boolean expression evaluator for "where" clauses */
+/* Matcher is our boolean expression evaluator for "where" clauses */
/**
* Copyright (C) 2008 10gen Inc.
@@ -61,12 +61,12 @@ namespace mongo {
};
- JSMatcher::~JSMatcher() {
+ Matcher::~Matcher() {
delete where;
where = 0;
}
- BasicMatcher::BasicMatcher( BSONElement _e , int _op ) : toMatch( _e ) , compareOp( _op ) {
+ ElementMatcher::ElementMatcher( BSONElement _e , int _op ) : toMatch( _e ) , compareOp( _op ) {
if ( _op == BSONObj::opMOD ){
BSONObj o = _e.embeddedObject().firstElement().embeddedObject();
mod = o["0"].numberInt();
@@ -80,12 +80,12 @@ namespace mongo {
else if ( _op == BSONObj::opELEM_MATCH ){
BSONElement m = toMatch.embeddedObjectUserCheck().firstElement();
uassert( 12517 , "$elemMatch needs an Object" , m.type() == Object );
- subMatcher.reset( new JSMatcher( m.embeddedObject() ) );
+ subMatcher.reset( new Matcher( m.embeddedObject() ) );
}
}
- BasicMatcher::~BasicMatcher(){
+ ElementMatcher::~ElementMatcher(){
}
@@ -141,14 +141,12 @@ namespace mongo {
/* _jsobj - the query pattern
*/
- JSMatcher::JSMatcher(const BSONObj &_jsobj, const BSONObj &constrainIndexKey) :
- where(0), jsobj(_jsobj), haveSize(), all(), hasArray(0), _atomic(false), nRegex(0){
-
+ Matcher::Matcher(const BSONObj &_jsobj, const BSONObj &constrainIndexKey) :
+ where(0), jsobj(_jsobj), haveSize(), all(), hasArray(0), _atomic(false), nRegex(0) {
+
BSONObjIterator i(jsobj);
- while ( i.moreWithEOO() ) {
+ while ( i.more() ) {
BSONElement e = i.next();
- if ( e.eoo() )
- break;
if ( ( e.type() == CodeWScope || e.type() == Code || e.type() == String ) && strcmp(e.fieldName(), "$where")==0 ) {
// $where: function()...
@@ -236,13 +234,13 @@ namespace mongo {
all = true;
case BSONObj::opIN:
case BSONObj::NIN:
- basics.push_back( BasicMatcher( e , op , fe.embeddedObject() ) );
+ basics.push_back( ElementMatcher( e , op , fe.embeddedObject() ) );
break;
case BSONObj::opMOD:
case BSONObj::opTYPE:
case BSONObj::opELEM_MATCH:
- // these are types where BasicMatcher has all the info
- basics.push_back( BasicMatcher( e , op ) );
+ // these are types where ElementMatcher has all the info
+ basics.push_back( ElementMatcher( e , op ) );
break;
case BSONObj::opSIZE:{
shared_ptr< BSONObjBuilder > b( new BSONObjBuilder() );
@@ -306,7 +304,7 @@ namespace mongo {
constrainIndexKey_ = constrainIndexKey;
}
- inline int JSMatcher::valuesMatch(const BSONElement& l, const BSONElement& r, int op, const BasicMatcher& bm) {
+ inline int Matcher::valuesMatch(const BSONElement& l, const BSONElement& r, int op, const ElementMatcher& bm) {
assert( op != BSONObj::NE && op != BSONObj::NIN );
if ( op == BSONObj::Equality )
@@ -352,7 +350,7 @@ namespace mongo {
return (op & z);
}
- int JSMatcher::matchesNe(const char *fieldName, const BSONElement &toMatch, const BSONObj &obj, const BasicMatcher& bm ) {
+ int Matcher::matchesNe(const char *fieldName, const BSONElement &toMatch, const BSONObj &obj, const ElementMatcher& bm ) {
int ret = matchesDotted( fieldName, toMatch, obj, BSONObj::Equality, bm );
if ( bm.toMatch.type() != jstNULL )
return ( ret <= 0 ) ? 1 : 0;
@@ -360,7 +358,7 @@ namespace mongo {
return -ret;
}
- int retMissing( const BasicMatcher &bm ) {
+ int retMissing( const ElementMatcher &bm ) {
if ( bm.compareOp != BSONObj::opEXISTS )
return 0;
return bm.toMatch.boolean() ? -1 : 1;
@@ -385,7 +383,7 @@ namespace mongo {
0 missing element
1 match
*/
- int JSMatcher::matchesDotted(const char *fieldName, const BSONElement& toMatch, const BSONObj& obj, int compareOp, const BasicMatcher& bm , bool isArr) {
+ int Matcher::matchesDotted(const char *fieldName, const BSONElement& toMatch, const BSONObj& obj, int compareOp, const ElementMatcher& bm , bool isArr) {
if ( compareOp == BSONObj::opALL ) {
if ( bm.myset->size() == 0 )
@@ -518,13 +516,13 @@ namespace mongo {
/* See if an object matches the query.
*/
- bool JSMatcher::matches(const BSONObj& jsobj ) {
+ bool Matcher::matches(const BSONObj& jsobj ) {
/* assuming there is usually only one thing to match. if more this
could be slow sometimes. */
// check normal non-regex cases:
for ( unsigned i = 0; i < basics.size(); i++ ) {
- BasicMatcher& bm = basics[i];
+ ElementMatcher& bm = basics[i];
BSONElement& m = bm.toMatch;
// -1=mismatch. 0=missing element. 1=match
int cmp = matchesDotted(m.fieldName(), m, jsobj, bm.compareOp, bm );
@@ -617,17 +615,17 @@ namespace mongo {
BSONObj j1((const char *) &js1);
BSONObj j2((const char *) &js2);
- JSMatcher m(j2);
+ Matcher m(j2);
assert( m.matches(j1) );
js2.sval[0] = 'z';
assert( !m.matches(j1) );
- JSMatcher n(j1);
+ Matcher n(j1);
assert( n.matches(j1) );
assert( !n.matches(j2) );
BSONObj j0 = BSONObj();
// BSONObj j0((const char *) &js0);
- JSMatcher p(j0);
+ Matcher p(j0);
assert( p.matches(j1) );
assert( p.matches(j2) );
}
diff --git a/db/matcher.h b/db/matcher.h
index 8e172ca45dd..f1609f9b8ad 100644
--- a/db/matcher.h
+++ b/db/matcher.h
@@ -1,6 +1,6 @@
// matcher.h
-/* JSMatcher is our boolean expression evaluator for "where" clauses */
+/* Matcher is our boolean expression evaluator for "where" clauses */
/**
* Copyright (C) 2008 10gen Inc.
@@ -26,7 +26,7 @@
namespace mongo {
class CoveredIndexMatcher;
- class JSMatcher;
+ class Matcher;
class RegexMatcher {
public:
@@ -52,15 +52,15 @@ namespace mongo {
};
- class BasicMatcher {
+ class ElementMatcher {
public:
- BasicMatcher() {
+ ElementMatcher() {
}
- BasicMatcher( BSONElement _e , int _op );
+ ElementMatcher( BSONElement _e , int _op );
- BasicMatcher( BSONElement _e , int _op , const BSONObj& array ) : toMatch( _e ) , compareOp( _op ) {
+ ElementMatcher( BSONElement _e , int _op , const BSONObj& array ) : toMatch( _e ) , compareOp( _op ) {
myset.reset( new set<BSONElement,element_lt>() );
@@ -71,7 +71,7 @@ namespace mongo {
}
}
- ~BasicMatcher();
+ ~ElementMatcher();
BSONElement toMatch;
int compareOp;
@@ -82,7 +82,7 @@ namespace mongo {
int modm;
BSONType type;
- shared_ptr<JSMatcher> subMatcher;
+ shared_ptr<Matcher> subMatcher;
};
// SQL where clause equivalent
@@ -103,16 +103,16 @@ namespace mongo {
TODO: we should rewrite the matcher to be more an AST style.
*/
- class JSMatcher : boost::noncopyable {
+ class Matcher : boost::noncopyable {
int matchesDotted(
const char *fieldName,
const BSONElement& toMatch, const BSONObj& obj,
- int compareOp, const BasicMatcher& bm, bool isArr = false);
+ int compareOp, const ElementMatcher& bm, bool isArr = false);
int matchesNe(
const char *fieldName,
const BSONElement &toMatch, const BSONObj &obj,
- const BasicMatcher&bm);
+ const ElementMatcher&bm);
public:
static int opDirection(int op) {
@@ -121,9 +121,9 @@ namespace mongo {
// Only specify constrainIndexKey if matches() will be called with
// index keys having empty string field names.
- JSMatcher(const BSONObj &pattern, const BSONObj &constrainIndexKey = BSONObj());
+ Matcher(const BSONObj &pattern, const BSONObj &constrainIndexKey = BSONObj());
- ~JSMatcher();
+ ~Matcher();
bool matches(const BSONObj& j);
@@ -136,15 +136,15 @@ namespace mongo {
// TODO May want to selectively ignore these element types based on op type.
if ( e.type() == MinKey || e.type() == MaxKey )
return;
- basics.push_back( BasicMatcher( e , c ) );
+ basics.push_back( ElementMatcher( e , c ) );
}
- int valuesMatch(const BSONElement& l, const BSONElement& r, int op, const BasicMatcher& bm);
+ int valuesMatch(const BSONElement& l, const BSONElement& r, int op, const ElementMatcher& bm);
Where *where; // set if query uses $where
BSONObj jsobj; // the query pattern. e.g., { name: "joe" }
BSONObj constrainIndexKey_;
- vector<BasicMatcher> basics;
+ vector<ElementMatcher> basics;
// int n; // # of basicmatcher items
bool haveSize;
bool all;
@@ -153,6 +153,7 @@ namespace mongo {
/* $atomic - if true, a multi document operation (some removes, updates)
should be done atomically. in that case, we do not yield -
i.e. we stay locked the whole time.
+ http://www.mongodb.org/display/DOCS/Removing[
*/
bool _atomic;
@@ -173,10 +174,10 @@ namespace mongo {
bool matches(const BSONObj &key, const DiskLoc &recLoc);
bool needRecord(){ return _needRecord; }
- JSMatcher& docMatcher() { return _docMatcher; }
+ Matcher& docMatcher() { return _docMatcher; }
private:
- JSMatcher _keyMatcher;
- JSMatcher _docMatcher;
+ Matcher _keyMatcher;
+ Matcher _docMatcher;
bool _needRecord;
};
diff --git a/db/update.h b/db/update.h
index 3597e955947..26a8a8d2a53 100644
--- a/db/update.h
+++ b/db/update.h
@@ -23,7 +23,7 @@
namespace mongo {
- /* Used for modifiers such as $inc, $set, ... */
+ /* Used for modifiers such as $inc, $set, $push, ... */
struct Mod {
// See opFromStr below
// 0 1 2 3 4 5 6 7 8 9 10
@@ -42,13 +42,13 @@ namespace mongo {
BSONElement elt; // x:5 note: this is the actual element from the updateobj
int pushStartSize;
- boost::shared_ptr<JSMatcher> matcher;
+ boost::shared_ptr<Matcher> matcher;
void init( Op o , BSONElement& e ){
op = o;
elt = e;
if ( op == PULL && e.type() == Object )
- matcher.reset( new JSMatcher( e.embeddedObject() ) );
+ matcher.reset( new Matcher( e.embeddedObject() ) );
}
void setFieldName( const char * s ){
diff --git a/dbtests/matchertests.cpp b/dbtests/matchertests.cpp
index 023cc9cda4f..e71988ee070 100644
--- a/dbtests/matchertests.cpp
+++ b/dbtests/matchertests.cpp
@@ -30,7 +30,7 @@ namespace MatcherTests {
public:
void run() {
BSONObj query = fromjson( "{\"a\":\"b\"}" );
- JSMatcher m( query );
+ Matcher m( query );
ASSERT( m.matches( fromjson( "{\"a\":\"b\"}" ) ) );
}
};
@@ -39,7 +39,7 @@ namespace MatcherTests {
public:
void run() {
BSONObj query = fromjson( "{\"a\":5}" );
- JSMatcher m( query );
+ Matcher m( query );
ASSERT( m.matches( fromjson( "{\"a\":5}" ) ) );
}
};
@@ -49,7 +49,7 @@ namespace MatcherTests {
void run() {
BSONObjBuilder query;
query.append( "a", 5 );
- JSMatcher m( query.done() );
+ Matcher m( query.done() );
ASSERT( m.matches( fromjson( "{\"a\":5}" ) ) );
}
};
@@ -58,7 +58,7 @@ namespace MatcherTests {
public:
void run() {
BSONObj query = fromjson( "{\"a\":{\"$gt\":4}}" );
- JSMatcher m( query );
+ Matcher m( query );
BSONObjBuilder b;
b.append( "a", 5 );
ASSERT( m.matches( b.done() ) );
@@ -72,7 +72,7 @@ namespace MatcherTests {
ASSERT_EQUALS( 4 , query["a"].embeddedObject()["$in"].embeddedObject()["0"].number() );
ASSERT_EQUALS( NumberInt , query["a"].embeddedObject()["$in"].embeddedObject()["0"].type() );
- JSMatcher m( query );
+ Matcher m( query );
{
BSONObjBuilder b;
@@ -100,7 +100,7 @@ namespace MatcherTests {
class Size {
public:
void run() {
- JSMatcher m( fromjson( "{a:{$size:4}}" ) );
+ Matcher m( fromjson( "{a:{$size:4}}" ) );
ASSERT( m.matches( fromjson( "{a:[1,2,3,4]}" ) ) );
ASSERT( !m.matches( fromjson( "{a:[1,2,3]}" ) ) );
ASSERT( !m.matches( fromjson( "{a:[1,2,3,'a','b']}" ) ) );