Просмотр исходного кода

ref #3253: FieldRef.js ComparisonMatchExpression.js ElementPath.js LeafMatchExpression.js modified, pass a couple of tests.

Brennan Chesley 12 лет назад
Родитель
Сommit
b1ef96dbb0

+ 4 - 3
lib/pipeline/matcher/ComparisonMatchExpression.js

@@ -1,11 +1,12 @@
 "use strict";
 "use strict";
 
 
-LeafMatchExpression = require('LeafMatchExpression');
-Value = require('../Value');
+var  LeafMatchExpression = require('./LeafMatchExpression');
+var Value = require('../Value');
 
 
 // Autogenerated by cport.py on 2013-09-17 14:37
 // Autogenerated by cport.py on 2013-09-17 14:37
 var ComparisonMatchExpression = module.exports = function ComparisonMatchExpression( type ){
 var ComparisonMatchExpression = module.exports = function ComparisonMatchExpression( type ){
 	this._matchType = type;
 	this._matchType = type;
+	return this;
 }, klass = ComparisonMatchExpression, base =  LeafMatchExpression, proto = klass.prototype = Object.create(base.prototype, {constructor:{value:klass}});
 }, klass = ComparisonMatchExpression, base =  LeafMatchExpression, proto = klass.prototype = Object.create(base.prototype, {constructor:{value:klass}});
 
 
 
 
@@ -115,7 +116,7 @@ proto.getRHS = function getRHS( /*  */ ){
 proto.init = function init( path,rhs ) { //  const StringData& path, const BSONElement& rhs
 proto.init = function init( path,rhs ) { //  const StringData& path, const BSONElement& rhs
 // File: expression_leaf.cpp lines: 65-87
 // File: expression_leaf.cpp lines: 65-87
 	this._rhs = rhs;
 	this._rhs = rhs;
-	if ( rhs === {}) { return {'code':'BAD_VALUE', 'desc':'Need a real operand'};}
+	if ( rhs === null || (rhs instanceof Object && Object.keys(rhs).length === 0)) { return {'code':'BAD_VALUE', 'desc':'Need a real operand'};}
 
 
 	if ( rhs === undefined ) { return {'code':'BAD_VALUE', 'desc':'Cannot compare to undefined'};}
 	if ( rhs === undefined ) { return {'code':'BAD_VALUE', 'desc':'Cannot compare to undefined'};}
 
 

+ 5 - 19
lib/pipeline/matcher/ElementPath.js

@@ -1,10 +1,11 @@
 "use strict";
 "use strict";
 
 
-FieldRef = require('FieldRef');
+var FieldRef = require('./FieldRef');
 
 
 // Autogenerated by cport.py on 2013-09-17 14:37
 // Autogenerated by cport.py on 2013-09-17 14:37
-var ElementPath = module.exports = function (){
-
+var ElementPath = module.exports = function ElementPath(){
+	this._fieldRef = new FieldRef();
+	this.shouldTraverseLeafArray = false;
 }, klass = ElementPath, base =  Object  , proto = klass.prototype = Object.create(base.prototype, {constructor:{value:klass}});
 }, klass = ElementPath, base =  Object  , proto = klass.prototype = Object.create(base.prototype, {constructor:{value:klass}});
 
 
 
 
@@ -19,21 +20,6 @@ proto._fieldRef = undefined;
 
 
 proto._shouldTraverseLeafArray = undefined;
 proto._shouldTraverseLeafArray = undefined;
 
 
-
-// File: path.h lines: 41-41
-//         FieldRef _fieldRef;
-
-proto._fieldRef = undefined;
-
-
-// File: path.h lines: 42-42
-//         bool _shouldTraverseLeafArray;
-
-proto._shouldTraverseLeafArray = undefined;
-
-
-// File: path_internal.cpp
-
 /**
 /**
  * getFieldDottedOrArray 
  * getFieldDottedOrArray 
  *
  *
@@ -113,7 +99,7 @@ proto.init = function init( path ){  //  const StringData& path
 // File: path.cpp lines: 26-29
 // File: path.cpp lines: 26-29
 	this._shouldTraverseLeafArray = true;
 	this._shouldTraverseLeafArray = true;
 	this._fieldRef.parse( path );
 	this._fieldRef.parse( path );
-	return Status.OK;
+	return {'code':'OK'};
 };
 };
 
 
 
 

+ 110 - 0
lib/pipeline/matcher/FieldRef.js

@@ -0,0 +1,110 @@
+"use strict";
+
+var FieldRef = module.exports = function FieldRef (){
+	this._array = [];
+	this._path = '';
+}, klass = FieldRef, base = Object, proto = klass.prototype = Object.create(base.prototype, {constructor:{value:klass}});
+
+
+proto.parse = function parse( str ) {
+	this._array = str.split('.');
+};
+
+proto.setPart = function setPart( i, part ) {
+	this._array[i] = part;
+	this._path = this._array.join('.');
+};
+
+proto.getPart = function getPArt( i ) {
+	return this._array[i];
+};
+
+
+proto.isPrefixOf = function isPrefixOf( other ) {
+	return ( other._path.indexOf(this.path) === 0 );
+};
+
+proto.commonPrefixSize = function commonPrefixSize ( other ) {
+	var i = 0;
+	while(other._array[i] == this._array[i]) { i++; }
+	return i;
+};
+
+proto.dottedField = function dottedField( ) {
+	var offset = 0;
+	if(arguments.length == 1){
+		offset = arguments[0];
+	}	
+	return this._array.slice( offset ).join('.');
+};
+
+proto.equalsDottedField = function equalsDottedField ( other ) {
+	return this._path == other._path;
+};
+
+proto.compare = function compare( other ) {
+	return (this._path < other._path ? -1 : this._path > other._path ? 1 : 0);
+};
+
+proto.clear = function clear() {
+	this._path = '';
+	this._array = [];
+};
+
+proto.numParts = function numParts() {
+	return this._array.length;
+};
+
+proto.numReplaced = function numReplaced() {
+	throw new Error('Why?');
+};
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+

+ 27 - 87
lib/pipeline/matcher/LeafMatchExpression.js

@@ -1,11 +1,13 @@
-"use strict"
-
+"use strict";
 
 
+var MatchExpression = require('./MatchExpression');
+var ElementPath = require('./ElementPath');
 
 
 // Autogenerated by cport.py on 2013-09-17 14:37
 // Autogenerated by cport.py on 2013-09-17 14:37
-var LeafMatchExpression = module.exports = function (){
-
-}, klass = LeafMatchExpression, base =  Object  , proto = klass.prototype = Object.create(base.prototype, {constructor:{value:klass}});
+var LeafMatchExpression = module.exports = function LeafMatchExpression( type ){
+	this._matchType = type;
+	this._elementPath = new ElementPath();
+}, klass = LeafMatchExpression, base =  MatchExpression, proto = klass.prototype = Object.create(base.prototype, {constructor:{value:klass}});
 
 
 
 
 // File: expression_leaf.h lines: 63-63
 // File: expression_leaf.h lines: 63-63
@@ -20,40 +22,6 @@ proto._elementPath = undefined;
 proto._path = undefined;
 proto._path = undefined;
 
 
 
 
-// File: expression_leaf.h lines: 63-63
-//         ElementPath _elementPath;
-
-proto._elementPath = undefined;
-
-
-// File: expression_leaf.h lines: 62-62
-//         StringData _path;
-
-proto._path = undefined;
-
-
-
-
-
-/**
- * 
- * This documentation was automatically generated. Please update when you touch this function.
- * @method LeafMatchExpression
- * @param
- *
- */
-proto.LeafMatchExpression = function LeafMatchExpression( /*  MatchType matchType  */ ){
-// File: expression_leaf.h lines: 46-47
-//         LeafMatchExpression( MatchType matchType )
-//             : MatchExpression( matchType ) {
-//         }
-
-
-
-
-}
-
-
 /**
 /**
  * 
  * 
  * This documentation was automatically generated. Please update when you touch this function.
  * This documentation was automatically generated. Please update when you touch this function.
@@ -61,17 +29,14 @@ proto.LeafMatchExpression = function LeafMatchExpression( /*  MatchType matchTyp
  * @param
  * @param
  *
  *
  */
  */
-proto.initPath = function initPath( /*  const StringData& path  */ ){
-
+proto.initPath = function initPath( path ) { //  const StringData& path
 // File: expression_leaf.cpp lines: 31-33
 // File: expression_leaf.cpp lines: 31-33
-//     Status LeafMatchExpression::initPath( const StringData& path ) {
-//         _path = path;
-//         return _elementPath.init( _path );
-//     }
-
-
-
-}
+	this._path = path;
+	if(this._elementPath === undefined){
+		this._elementPath = new ElementPath();
+	}
+	return this._elementPath.init( this._path );
+};
 
 
 
 
 /**
 /**
@@ -82,25 +47,20 @@ proto.initPath = function initPath( /*  const StringData& path  */ ){
  *
  *
  */
  */
 proto.matches = function matches( /*  const MatchableDocument* doc, MatchDetails* details  */ ){
 proto.matches = function matches( /*  const MatchableDocument* doc, MatchDetails* details  */ ){
-
 // File: expression_leaf.cpp lines: 37-48
 // File: expression_leaf.cpp lines: 37-48
-//     bool LeafMatchExpression::matches( const MatchableDocument* doc, MatchDetails* details ) const {
-//         boost::scoped_ptr<ElementIterator> cursor( doc->getIterator( _elementPath ) );
-//         while ( cursor->more() ) {
-//             ElementIterator::Context e = cursor->next();
-//             if ( !matchesSingleElement( e.element() ) )
-//                 continue;
-//             if ( details && details->needRecord() && !e.arrayOffset().eoo() ) {
-//                 details->setElemMatchKey( e.arrayOffset().fieldName() );
-//             }
-//             return true;
-//         }
-//         return false;
-//     }
-
+	var docKeys = Object.keys(doc);
+	for(var i = 0;i < docKeys.length; i++ ) {
+		if(!this.matchesSingleElement( doc[docKeys[i]] ))
+			continue;
+		if( details && details.needRecord() && (doc instanceof Array) && i < docKeys.length-1 ) {
+			details.setElemMatchKey( docKeys[i+1] );
+		}
+		return true;
+	}
+	return false;
+};
 
 
 
 
-}
 
 
 
 
 /**
 /**
@@ -112,26 +72,6 @@ proto.matches = function matches( /*  const MatchableDocument* doc, MatchDetails
  */
  */
 proto.path = function path( /*  */ ){
 proto.path = function path( /*  */ ){
 // File: expression_leaf.h lines: 56-55
 // File: expression_leaf.h lines: 56-55
-//         virtual const StringData path() const { return _path; }
-
-
-
-
-}
-
-
-/**
- * 
- * This documentation was automatically generated. Please update when you touch this function.
- * @method ~LeafMatchExpression
- * @param
- *
- */
-proto.~LeafMatchExpression = function ~LeafMatchExpression( /*  */ ){
-// File: expression_leaf.h lines: 50-49
-//         virtual ~LeafMatchExpression(){}
-
-
-
+	return this._path;
+};
 
 
-}