ソースを参照

Refs #3300. Ported IndexKeyMatchableDocument. May need to adjust if Iterator classes do not exist.

Spencer Rathbun 12 年 前
コミット
78bdef2f69
1 ファイル変更39 行追加92 行削除
  1. 39 92
      lib/pipeline/matcher/IndexKeyMatchableDocument.js

+ 39 - 92
lib/pipeline/matcher/IndexKeyMatchableDocument.js

@@ -1,130 +1,77 @@
-"use strict"
-
-
+"use strict";
 
 // Autogenerated by cport.py on 2013-09-17 14:37
-var IndexKeyMatchableDocument = module.exports = function (){
-
+var IndexKeyMatchableDocument = module.exports = function (pattern, doc){
+	this._pattern = pattern;
+	this._doc = doc;
 }, klass = IndexKeyMatchableDocument, base =  Object  , proto = klass.prototype = Object.create(base.prototype, {constructor:{value:klass}});
 
+// DEPENDENCIES
+var SimpleArrayElementIterator = require('./SimpleArrayElementIterator.js'),
+	SingleElementElementIterator = require('./SingleElementElementIterator.js');
 
 // File: matcher.cpp lines: 52-52
-//         BSONObj _doc;
-
 proto._doc = undefined;
 
-
 // File: matcher.cpp lines: 51-51
-//         BSONObj _pattern;
-
 proto._pattern = undefined;
 
-
 // File: matcher.cpp lines: 52-52
-//         BSONObj _doc;
-
 proto._doc = undefined;
 
-
 // File: matcher.cpp lines: 51-51
-//         BSONObj _pattern;
-
 proto._pattern = undefined;
 
-
-
-
-
 /**
- * 
- * This documentation was automatically generated. Please update when you touch this function.
- * @method IndexKeyMatchableDocument
- * @param
  *
- */
-proto.IndexKeyMatchableDocument = function IndexKeyMatchableDocument( /*  const BSONObj& pattern,$/;" */ ){
-
-// File: matcher.cpp lines: 34-36
-//         IndexKeyMatchableDocument( const BSONObj& pattern,
-//                                    const BSONObj& doc )
-//             : _pattern( pattern ), _doc( doc ) {
-//         }
-
-
-
-}
-
-
-/**
- * 
  * This documentation was automatically generated. Please update when you touch this function.
  * @method _getElement
- * @param
+ * @param path
  *
  */
-proto._getElement = function _getElement( /*  const FieldRef& path  */ ){
+proto._getElement = function _getElement(path){
+	// File: matcher.cpp lines: 63-77
+	var patternElement, docElement;
 
-// File: matcher.cpp lines: 63-77
-//     BSONElement IndexKeyMatchableDocument::_getElement( const FieldRef& path ) const {
-//         BSONObjIterator patternIterator( _pattern );
-//         BSONObjIterator docIterator( _doc );
-// 
-//         while ( patternIterator.more() ) {
-//             BSONElement patternElement = patternIterator.next();
-//             verify( docIterator.more() );
-//             BSONElement docElement = docIterator.next();
-// 
-//             if ( path.equalsDottedField( patternElement.fieldName() ) ) {
-//                 return docElement;
-//             }
-//         }
-// 
-//         return BSONElement();
-//     }
+	for (var i in this._pattern) {
+		patternElement = this._pattern[i];
+		//verify( docIterator.more() );
+		if(i >= this._doc.length) throw new Error("Ran out of docs in IndexKeyMatchableDocument:35");
+		docElement = this._doc[i];
 
+		if (path.equalsDottedField(patternElement.fieldName())) {
+			return docElement;
+		}
+	}
 
-
-}
-
+	return {};
+};
 
 /**
- * 
+ *
  * This documentation was automatically generated. Please update when you touch this function.
  * @method getIterator
- * @param
+ * @param path
  *
  */
-proto.getIterator = function getIterator( /*  const ElementPath& path  */ ){
-
-// File: matcher.cpp lines: 55-59
-//     ElementIterator* IndexKeyMatchableDocument::getIterator( const ElementPath& path ) const {
-//         BSONElement e = _getElement( path.fieldRef() );
-//         if ( e.type() == Array )
-//             return new SimpleArrayElementIterator( e, true );
-//         return new SingleElementElementIterator( e );
-//     }
-
-
-
-}
-
+proto.getIterator = function getIterator(path){
+	// File: matcher.cpp lines: 55-59
+	var e = this._getElement(path.fieldRef());
+	if (e instanceof Array)
+		return new SimpleArrayElementIterator( e, true );
+	return new SingleElementElementIterator( e );
+};
 
 /**
- * 
- * This documentation was automatically generated. Please update when you touch this function.
+ *
+ * This method returns a JSON representation of the Document
  * @method toBSON
  * @param
  *
  */
-proto.toBSON = function toBSON( /*  */ ){
-
-// File: matcher.cpp lines: 39-42
-//         BSONObj toBSON() const {
-//             // TODO: this isn't quite correct because of dots
-//             // don't think it'll ever be called though
-//             return _doc.replaceFieldNames( _pattern );
-//         }
-
-
-
-}
+proto.toJSON = function toJSON(){
+	// File: matcher.cpp lines: 39-42
+	// TODO: this isn't quite correct because of dots
+	// don't think it'll ever be called though
+	return this._doc.replaceFieldNames(this._pattern);
+};