|
|
@@ -1,107 +1,70 @@
|
|
|
"use strict";
|
|
|
|
|
|
-var MatchExpression = require('./MatchExpression');
|
|
|
-var ElementPath = require('./ElementPath');
|
|
|
-
|
|
|
-// Autogenerated by cport.py on 2013-09-17 14:37
|
|
|
-var LeafMatchExpression = module.exports = function LeafMatchExpression( type ){
|
|
|
- base.call(this);
|
|
|
- this._matchType = type;
|
|
|
- this._elementPath = new ElementPath();
|
|
|
-}, klass = LeafMatchExpression, base = MatchExpression, proto = klass.prototype = Object.create(base.prototype, {constructor:{value:klass}});
|
|
|
+var MatchExpression = require('./MatchExpression'),
|
|
|
+ ElementPath = require('./ElementPath');
|
|
|
|
|
|
+var LeafMatchExpression = module.exports = function LeafMatchExpression(type) {
|
|
|
+ base.call(this, type);
|
|
|
|
|
|
-// File: expression_leaf.h lines: 63-63
|
|
|
-// ElementPath _elementPath;
|
|
|
+ this._elementPath = new ElementPath();
|
|
|
+}, klass = LeafMatchExpression, base = MatchExpression, proto = klass.prototype = Object.create(base.prototype, {constructor: {value: klass}});
|
|
|
|
|
|
proto._elementPath = undefined;
|
|
|
-
|
|
|
-
|
|
|
-// File: expression_leaf.h lines: 62-62
|
|
|
-// StringData _path;
|
|
|
-
|
|
|
proto._path = undefined;
|
|
|
|
|
|
-
|
|
|
/**
|
|
|
*
|
|
|
- * Initialize the ElementPath to the input path
|
|
|
- * @method initPath
|
|
|
- * @param path
|
|
|
- *
|
|
|
- */
|
|
|
-proto.initPath = function initPath( path ) { // const StringData& path
|
|
|
-// File: expression_leaf.cpp lines: 31-33
|
|
|
- this._path = path;
|
|
|
- if(this._elementPath === undefined){
|
|
|
- this._elementPath = new ElementPath();
|
|
|
- }
|
|
|
- return this._elementPath.init( this._path );
|
|
|
-};
|
|
|
-
|
|
|
-
|
|
|
-/**
|
|
|
+ * Checks whether the document matches against what was searched.
|
|
|
*
|
|
|
- * Check whether the input doc matches
|
|
|
- * @method matches
|
|
|
* @param doc
|
|
|
- *
|
|
|
+ * @param details
|
|
|
+ * @returns {*}
|
|
|
*/
|
|
|
-proto.matches = function matches( doc, details ) { // const MatchableDocument* doc, MatchDetails* details
|
|
|
- // File: expression_leaf.cpp lines: 37-48
|
|
|
+proto.matches = function matches(doc, details) {
|
|
|
var self = this,
|
|
|
checker = function(element) {
|
|
|
- /*if (element instanceof Array) {
|
|
|
- for (var i = 0; i < element.length; i++) {
|
|
|
- if(self.matchesSingleElement(element[i])) {
|
|
|
- if(details && details.needRecord()) {
|
|
|
- details.setElemMatchKey(i.toString());
|
|
|
- }
|
|
|
- return true;
|
|
|
- }
|
|
|
- }
|
|
|
- return false;
|
|
|
- }*/
|
|
|
if (!self.matchesSingleElement(element)) {
|
|
|
return false;
|
|
|
}
|
|
|
- /*
|
|
|
- if( details && details.needRecord() && (element instanceof Array)) {
|
|
|
- details.setElemMatchKey( docKeys[i+1] );
|
|
|
- }
|
|
|
- */
|
|
|
+
|
|
|
return true;
|
|
|
};
|
|
|
+
|
|
|
return this._elementPath._matches(doc, details, checker);
|
|
|
- /*
|
|
|
- var tDoc = ElementPath.objAtPath( doc, this._path );
|
|
|
- if(tDoc instanceof RegExp || typeof(tDoc) != 'object') {
|
|
|
- return this.matchesSingleElement(tDoc);
|
|
|
- }
|
|
|
- if(!this.matchesSingleElement( tDoc[docKeys[i]] ))
|
|
|
- continue;
|
|
|
- if( details && details.needRecord() && (tDoc instanceof Array) && i < docKeys.length-1 ) {
|
|
|
- console.log('test2');
|
|
|
- details.setElemMatchKey( docKeys[i+1] );
|
|
|
- }
|
|
|
- return true;
|
|
|
- }
|
|
|
- return false;
|
|
|
- */
|
|
|
};
|
|
|
|
|
|
-
|
|
|
-
|
|
|
+/**
|
|
|
+ *
|
|
|
+ * Overridable method for matching against a single element.
|
|
|
+ *
|
|
|
+ * @param e
|
|
|
+ * @returns {boolean}
|
|
|
+ */
|
|
|
+proto.matchesSingleElement = function matchesSingleElement(e) { return false; }; // The child class defines this method.
|
|
|
|
|
|
/**
|
|
|
*
|
|
|
- * Return the internal path
|
|
|
- * @method path
|
|
|
- * @param
|
|
|
+ * Return the internal path.
|
|
|
*
|
|
|
+ * @returns {undefined|*|klass._path}
|
|
|
*/
|
|
|
-proto.path = function path( /* */ ){
|
|
|
-// File: expression_leaf.h lines: 56-55
|
|
|
+proto.path = function path() {
|
|
|
return this._path;
|
|
|
};
|
|
|
|
|
|
+/**
|
|
|
+ *
|
|
|
+ * Initialize the ElementPath to the input path.
|
|
|
+ *
|
|
|
+ * @param path
|
|
|
+ * @returns {*}
|
|
|
+ */
|
|
|
+proto.initPath = function initPath(path) {
|
|
|
+ this._path = path;
|
|
|
+
|
|
|
+ if (this._elementPath === undefined) {
|
|
|
+ this._elementPath = new ElementPath();
|
|
|
+ }
|
|
|
+
|
|
|
+ return this._elementPath.init(this._path);
|
|
|
+};
|