|
|
@@ -1,163 +1,163 @@
|
|
|
"use strict";
|
|
|
+
|
|
|
var MatchExpression = require('./MatchExpression');
|
|
|
var ElementPath = require('./ElementPath');
|
|
|
|
|
|
-// Autogenerated by cport.py on 2013-09-17 14:37
|
|
|
-var TypeMatchExpression = module.exports = function TypeMatchExpression(){
|
|
|
- base.call(this);
|
|
|
- this._elementPath = new ElementPath();
|
|
|
- this._matchType = 'TYPE_OPERATOR';
|
|
|
-}, klass = TypeMatchExpression, base = MatchExpression, proto = klass.prototype = Object.create(base.prototype, {constructor:{value:klass}});
|
|
|
+var TypeMatchExpression = module.exports = function TypeMatchExpression() {
|
|
|
+ base.call(this, 'TYPE_OPERATOR');
|
|
|
|
|
|
+ this._elementPath = new ElementPath();
|
|
|
+}, klass = TypeMatchExpression, base = MatchExpression, proto = klass.prototype = Object.create(base.prototype, {constructor: {value: klass}});
|
|
|
|
|
|
-// File: expression_leaf.h lines: 338-338
|
|
|
proto._elementPath = undefined;
|
|
|
-
|
|
|
-// File: expression_leaf.h lines: 337-337
|
|
|
proto._path = undefined;
|
|
|
-
|
|
|
-// File: expression_leaf.h lines: 339-339
|
|
|
proto._type = undefined;
|
|
|
|
|
|
/**
|
|
|
+ * Initialize the current object.
|
|
|
*
|
|
|
- * Writes a debug string for this object
|
|
|
- * @method debugString
|
|
|
- * @param level
|
|
|
- *
|
|
|
+ * @param path
|
|
|
+ * @param type
|
|
|
+ * @returns {*}
|
|
|
*/
|
|
|
-proto.debugString = function debugString(level) {
|
|
|
- // File: expression_leaf.cpp lines: 335-343
|
|
|
- return this._debugAddSapce( level ) + this.path() + " type: " + this._type + (this.getTag() ? this.getTag().debugString() : '' ) + "\n";
|
|
|
+proto.init = function init(path, type) {
|
|
|
+ this._path = path;
|
|
|
+ this._type = type;
|
|
|
+
|
|
|
+ return this._elementPath.init(path);
|
|
|
};
|
|
|
|
|
|
/**
|
|
|
*
|
|
|
- * checks if this expression is == to the other
|
|
|
- * @method equivalent
|
|
|
- * @param other
|
|
|
+ * Returns a shallow copy of the instance.
|
|
|
*
|
|
|
+ * @returns {TypeMatchExpression}
|
|
|
*/
|
|
|
-proto.equivalent = function equivalent(other) {
|
|
|
- // File: expression_leaf.cpp lines: 347-352
|
|
|
- if( other._matchType != 'TYPE_OPERATOR' ) {
|
|
|
- return false;
|
|
|
+proto.shallowClone = function shallowClone(){
|
|
|
+ var clone = new TypeMatchExpression();
|
|
|
+
|
|
|
+ clone.init(this._path, this._type);
|
|
|
+
|
|
|
+ if (this.getTag()) {
|
|
|
+ clone.setTag(this.getTag().clone());
|
|
|
}
|
|
|
- return this._path == other._path && this._type == other._type;
|
|
|
+
|
|
|
+ return clone;
|
|
|
};
|
|
|
|
|
|
/**
|
|
|
+ * Used number reference to types like C++.
|
|
|
*
|
|
|
- * Return the _type property
|
|
|
- * @method getData
|
|
|
- *
|
|
|
+ * @param e
|
|
|
+ * @returns {number}
|
|
|
*/
|
|
|
-proto.getData = function getData(){
|
|
|
- // File: expression_leaf.h lines: 328-327
|
|
|
- return this._type;
|
|
|
+var _type = function _type(e) {
|
|
|
+ if(e === undefined) {
|
|
|
+ return 6;
|
|
|
+ } else if (e === null) {
|
|
|
+ return 10;
|
|
|
+ }
|
|
|
+
|
|
|
+ switch (typeof e) {
|
|
|
+ case 'number':
|
|
|
+ return 1;
|
|
|
+ case 'string':
|
|
|
+ return 2;
|
|
|
+ case 'boolean':
|
|
|
+ return 8;
|
|
|
+ case 'object':
|
|
|
+ console.log(e.constructor);
|
|
|
+ if (e instanceof Array)
|
|
|
+ return 4;
|
|
|
+ if (e instanceof RegExp)
|
|
|
+ return 11;
|
|
|
+ if (e instanceof Date)
|
|
|
+ return 9;
|
|
|
+ if (e.constructor.name == 'MinKey')
|
|
|
+ return -1;
|
|
|
+ if (e.constructor.name == 'MaxKey')
|
|
|
+ return 127;
|
|
|
+ default:
|
|
|
+ return 42;
|
|
|
+ }
|
|
|
};
|
|
|
|
|
|
/**
|
|
|
+ * Matches single element.
|
|
|
*
|
|
|
- * Initialize the necessary items
|
|
|
- * @method init
|
|
|
- * @param path
|
|
|
- * @param type
|
|
|
- *
|
|
|
+ * @param e
|
|
|
+ * @returns {boolean}
|
|
|
*/
|
|
|
-proto.init = function init(path,type) {
|
|
|
- // File: expression_leaf.cpp lines: 308-311
|
|
|
- this._path = path;
|
|
|
- this._type = type;
|
|
|
- return this._elementPath.init( path );
|
|
|
+proto.matchesSingleElement = function matchesSingleElement(e) {
|
|
|
+ console.log(e);
|
|
|
+ return _type() === this._type;
|
|
|
};
|
|
|
|
|
|
/**
|
|
|
+ * Matches against the document.
|
|
|
*
|
|
|
- * matches checks the input doc against the internal element path to see if it is a match
|
|
|
- * @method matches
|
|
|
* @param doc
|
|
|
* @param details
|
|
|
- *
|
|
|
+ * @returns {*}
|
|
|
*/
|
|
|
-proto.matches = function matches(doc,details) {
|
|
|
- // File: expression_leaf.cpp lines: 318-332
|
|
|
+proto.matches = function matches(doc, details) {
|
|
|
var self = this,
|
|
|
- checker = function(element) {
|
|
|
- if (!self.matchesSingleElement(element, details))
|
|
|
+ matcher = function matcher(element) {
|
|
|
+ if (!self.matchesSingleElement(element, details)) {
|
|
|
return false;
|
|
|
+ }
|
|
|
|
|
|
- //var amIRoot = (element.length === 0);
|
|
|
return true;
|
|
|
};
|
|
|
- return this._elementPath._matches(doc, details, checker);
|
|
|
+
|
|
|
+ return this._elementPath._matches(doc, details, matcher);
|
|
|
};
|
|
|
|
|
|
/**
|
|
|
- * Return a number indicating the type of the input element
|
|
|
- * @method typeNumber
|
|
|
- * @param e
|
|
|
+ * Writes a debug string for this object.
|
|
|
*
|
|
|
+ * @param level
|
|
|
+ * @returns {string}
|
|
|
*/
|
|
|
-klass.typeNumber = function typeNumber(e){
|
|
|
- if(e === undefined)
|
|
|
- return 6;
|
|
|
- if(e === null)
|
|
|
- return 10;
|
|
|
- if(typeof(e) == 'number')
|
|
|
- return 1;
|
|
|
- if(typeof(e) == 'string')
|
|
|
- return 2;
|
|
|
- if(typeof(e) == 'boolean')
|
|
|
- return 8;
|
|
|
- if(typeof(e) == 'object') {
|
|
|
- if(e instanceof Array)
|
|
|
- return 4;
|
|
|
- if(e instanceof RegExp)
|
|
|
- return 11;
|
|
|
- if(e instanceof Date)
|
|
|
- return 9;
|
|
|
- if(e.constructor.name == 'MinKey')
|
|
|
- return -1;
|
|
|
- if(e.constructor.name == 'MAxKey')
|
|
|
- return 127;
|
|
|
+proto.debugString = function debugString(level) {
|
|
|
+ var rtn = this._debugAddSpace(level) + this.path() + ' type: ' + this._type;
|
|
|
+
|
|
|
+ if (this.getTag()) {
|
|
|
+ rtn += ' ' + this.getTag().debugString();
|
|
|
}
|
|
|
- return 42; // Can't tell
|
|
|
+
|
|
|
+ return rtn + '\n';
|
|
|
};
|
|
|
|
|
|
/**
|
|
|
+ * Checks to see if the other instance is equivalent to the current instance.
|
|
|
*
|
|
|
- * Check if the input element matches
|
|
|
- * @method matchesSingleElement
|
|
|
- * @param e
|
|
|
- *
|
|
|
+ * @param other
|
|
|
+ * @returns {boolean}
|
|
|
*/
|
|
|
-proto.matchesSingleElement = function matchesSingleElement(e) {
|
|
|
- // File: expression_leaf.cpp lines: 314-315
|
|
|
- return klass.typeNumber( e ) == this._type;
|
|
|
+proto.equivalent = function equivalent(other) {
|
|
|
+ if (this.matchType() !== other.matchType()) {
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+
|
|
|
+ return (this._path === other._path && this._type === other._type);
|
|
|
};
|
|
|
|
|
|
/**
|
|
|
+ * Return the type we're matching against.
|
|
|
*
|
|
|
- * return the internal path
|
|
|
- * @method path
|
|
|
- *
|
|
|
+ * @returns {undefined|*}
|
|
|
*/
|
|
|
-proto.path = function path(){
|
|
|
- // File: expression_leaf.h lines: 330-329
|
|
|
- return this._path;
|
|
|
+proto.getData = function getData() {
|
|
|
+ return this._type;
|
|
|
};
|
|
|
|
|
|
/**
|
|
|
+ * Return the path associated with the current object.
|
|
|
*
|
|
|
- * clone this instance to a new one
|
|
|
- * @method shallowClone
|
|
|
- *
|
|
|
+ * @returns {undefined|*|klass._path}
|
|
|
*/
|
|
|
-proto.shallowClone = function shallowClone(){
|
|
|
- // File: expression_leaf.h lines: 311-314
|
|
|
- var e = new TypeMatchExpression();
|
|
|
- e.init( this._path,this._type );
|
|
|
- return e;
|
|
|
+proto.path = function path() {
|
|
|
+ return this._path;
|
|
|
};
|
|
|
|