IndexKeyMatchableDocument.js 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. "use strict";
  2. // Autogenerated by cport.py on 2013-09-17 14:37
  3. var IndexKeyMatchableDocument = module.exports = function (pattern, doc){
  4. this._pattern = pattern;
  5. this._doc = doc;
  6. }, klass = IndexKeyMatchableDocument, base = Object , proto = klass.prototype = Object.create(base.prototype, {constructor:{value:klass}});
  7. // DEPENDENCIES
  8. var SimpleArrayElementIterator = require('./SimpleArrayElementIterator.js'),
  9. SingleElementElementIterator = require('./SingleElementElementIterator.js');
  10. // File: matcher.cpp lines: 52-52
  11. proto._doc = undefined;
  12. // File: matcher.cpp lines: 51-51
  13. proto._pattern = undefined;
  14. // File: matcher.cpp lines: 52-52
  15. proto._doc = undefined;
  16. // File: matcher.cpp lines: 51-51
  17. proto._pattern = undefined;
  18. /**
  19. *
  20. * This documentation was automatically generated. Please update when you touch this function.
  21. * @method _getElement
  22. * @param path
  23. *
  24. */
  25. proto._getElement = function _getElement(path){
  26. // File: matcher.cpp lines: 63-77
  27. var patternElement, docElement;
  28. for (var i in this._pattern) {
  29. patternElement = this._pattern[i];
  30. //verify( docIterator.more() );
  31. if(i >= this._doc.length) throw new Error("Ran out of docs in IndexKeyMatchableDocument:35");
  32. docElement = this._doc[i];
  33. if (path.equalsDottedField(patternElement.fieldName())) {
  34. return docElement;
  35. }
  36. }
  37. return {};
  38. };
  39. /**
  40. *
  41. * This documentation was automatically generated. Please update when you touch this function.
  42. * @method getIterator
  43. * @param path
  44. *
  45. */
  46. proto.getIterator = function getIterator(path){
  47. // File: matcher.cpp lines: 55-59
  48. var e = this._getElement(path.fieldRef());
  49. if (e instanceof Array)
  50. return new SimpleArrayElementIterator( e, true );
  51. return new SingleElementElementIterator( e );
  52. };
  53. /**
  54. *
  55. * This method returns a JSON representation of the Document
  56. * @method toBSON
  57. * @param
  58. *
  59. */
  60. proto.toJSON = function toJSON(){
  61. // File: matcher.cpp lines: 39-42
  62. // TODO: this isn't quite correct because of dots
  63. // don't think it'll ever be called though
  64. return this._doc.replaceFieldNames(this._pattern);
  65. };