|
|
@@ -2,15 +2,19 @@
|
|
|
var LeafMatchExpression = require('./LeafMatchExpression.js');
|
|
|
var Value = require('../Value');
|
|
|
|
|
|
-
|
|
|
-// Autogenerated by cport.py on 2013-09-17 14:37
|
|
|
-var ComparisonMatchExpression = module.exports = function ComparisonMatchExpression( type ){
|
|
|
+/**
|
|
|
+ * ComparisonMatchExpression
|
|
|
+ * @class ComparisonMatchExpression
|
|
|
+ * @namespace mungedb-aggregate.pipeline.matcher
|
|
|
+ * @module mungedb-aggregate
|
|
|
+ * @constructor
|
|
|
+ */
|
|
|
+var ComparisonMatchExpression = module.exports = function ComparisonMatchExpression(type){
|
|
|
base.call(this);
|
|
|
this._matchType = type;
|
|
|
}, klass = ComparisonMatchExpression, base = LeafMatchExpression, proto = klass.prototype = Object.create(base.prototype, {constructor:{value:klass}});
|
|
|
|
|
|
|
|
|
-// File: expression_leaf.h lines: 88-88
|
|
|
proto._rhs = undefined;
|
|
|
|
|
|
/**
|
|
|
@@ -21,9 +25,8 @@ proto._rhs = undefined;
|
|
|
*
|
|
|
*/
|
|
|
proto.debugString = function debugString(level) {
|
|
|
- // File: expression_leaf.cpp lines: 135-154
|
|
|
- var retStr = this._debugAddSpace( level ) + this.path() + " ";
|
|
|
- switch (this._matchType){
|
|
|
+ var retStr = this._debugAddSpace(level) + this.path() + " ";
|
|
|
+ switch (this._matchType) {
|
|
|
case 'LT':
|
|
|
retStr += '$lt';
|
|
|
break;
|
|
|
@@ -45,7 +48,7 @@ proto.debugString = function debugString(level) {
|
|
|
}
|
|
|
|
|
|
retStr += (this._rhs ? this._rhs.toString() : '?');
|
|
|
- if ( this.getTag() ) {
|
|
|
+ if (this.getTag()) {
|
|
|
retStr += this.getTag().debugString();
|
|
|
}
|
|
|
return retStr + '\n';
|
|
|
@@ -59,7 +62,6 @@ proto.debugString = function debugString(level) {
|
|
|
*
|
|
|
*/
|
|
|
proto.equivalent = function equivalent(other) {
|
|
|
- // File: expression_leaf.cpp lines: 53-61
|
|
|
if (other._matchType != this._matchType) return false;
|
|
|
return this.path() === other.path() && Value.compare(this._rhs,other._rhs) === 0;
|
|
|
};
|
|
|
@@ -70,8 +72,7 @@ proto.equivalent = function equivalent(other) {
|
|
|
* @method getData
|
|
|
*
|
|
|
*/
|
|
|
-proto.getData = function getData(){
|
|
|
- // File: expression_leaf.h lines: 85-84
|
|
|
+proto.getData = function getData() {
|
|
|
return this._rhs;
|
|
|
};
|
|
|
|
|
|
@@ -81,8 +82,7 @@ proto.getData = function getData(){
|
|
|
* @method getRHS
|
|
|
*
|
|
|
*/
|
|
|
-proto.getRHS = function getRHS(){
|
|
|
- // File: expression_leaf.h lines: 79-78
|
|
|
+proto.getRHS = function getRHS() {
|
|
|
return this._rhs;
|
|
|
};
|
|
|
|
|
|
@@ -95,15 +95,14 @@ proto.getRHS = function getRHS(){
|
|
|
*
|
|
|
*/
|
|
|
proto.init = function init(path,rhs) {
|
|
|
- // File: expression_leaf.cpp lines: 65-87
|
|
|
this._rhs = rhs;
|
|
|
- if ( (rhs instanceof Object && Object.keys(rhs).length === 0)) { return {'code':'BAD_VALUE', 'description':'Need a real operand'};}
|
|
|
+ if ((rhs instanceof Object && Object.keys(rhs).length === 0)) return {'code':'BAD_VALUE', 'description':'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'};
|
|
|
if (!(this._matchType in {"LT":1, "LTE":1, "EQ":1, "GT":1, "GTE":1})) {
|
|
|
return {'code':'BAD_VALUE', 'description':'Bad match type for ComparisonMatchExpression'};
|
|
|
}
|
|
|
- return this.initPath( path );
|
|
|
+ return this.initPath(path);
|
|
|
};
|
|
|
|
|
|
/**
|
|
|
@@ -113,36 +112,21 @@ proto.init = function init(path,rhs) {
|
|
|
* @param e
|
|
|
*
|
|
|
*/
|
|
|
-proto.matchesSingleElement = function matchesSingleElement(e){
|
|
|
- // File: expression_leaf.cpp lines: 91-132
|
|
|
- if( typeof(e) != typeof(this._rhs) ){
|
|
|
- if( this._rhs === null) {
|
|
|
- if(this._matchType in {'EQ':1, 'LTE':1, 'GTE':1}){
|
|
|
- if(e === undefined || e === null || (e instanceof Object && Object.keys(e).length === 0)) {
|
|
|
- return true;
|
|
|
- }
|
|
|
- }
|
|
|
- return false;
|
|
|
- }
|
|
|
- if((e === null || e === undefined) && (this._rhs ===null || this._rhs === undefined)) {
|
|
|
+proto.matchesSingleElement = function matchesSingleElement(e) {
|
|
|
+ if (Value.canonicalize(e) !== Value.canonicalize(this._rhs)) {
|
|
|
+ if (Value.canonicalize(e) + Value.canonicalize(this._rhs) === 5) {
|
|
|
return ["EQ","LTE","GTE"].indexOf(this._matchType) != -1;
|
|
|
}
|
|
|
|
|
|
- if (this._rhs.constructor.name in {'MaxKey':1,'MinKey':1} ) {
|
|
|
- return this._matchType != "EQ";
|
|
|
+ if (['MaxKey','MinKey'].indexOf(Value.getType(this._rhs)) != -1) {
|
|
|
+ return this._matchType !== "EQ";
|
|
|
}
|
|
|
return false;
|
|
|
}
|
|
|
|
|
|
- if( this._rhs instanceof Array) {
|
|
|
- if( this._matchType != 'EQ') {
|
|
|
- return false;
|
|
|
- }
|
|
|
- }
|
|
|
+ var x = Value.compare(e, this._rhs);
|
|
|
|
|
|
- var x = Value.compare( e, this._rhs );
|
|
|
-
|
|
|
- switch( this._matchType ) {
|
|
|
+ switch(this._matchType) {
|
|
|
case "LT":
|
|
|
return x == -1;
|
|
|
case "LTE":
|
|
|
@@ -158,4 +142,3 @@ proto.matchesSingleElement = function matchesSingleElement(e){
|
|
|
}
|
|
|
return false;
|
|
|
};
|
|
|
-
|