|
|
@@ -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
|
|
|
-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
|
|
|
@@ -20,40 +22,6 @@ proto._elementPath = 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.
|
|
|
@@ -61,17 +29,14 @@ proto.LeafMatchExpression = function LeafMatchExpression( /* MatchType matchTyp
|
|
|
* @param
|
|
|
*
|
|
|
*/
|
|
|
-proto.initPath = function initPath( /* const StringData& path */ ){
|
|
|
-
|
|
|
+proto.initPath = function initPath( path ) { // const StringData& path
|
|
|
// 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 */ ){
|
|
|
-
|
|
|
// 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( /* */ ){
|
|
|
// 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;
|
|
|
+};
|
|
|
|
|
|
-}
|