LeafMatchExpression.js 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. "use strict";
  2. var MatchExpression = require('./MatchExpression');
  3. var ElementPath = require('./ElementPath');
  4. // Autogenerated by cport.py on 2013-09-17 14:37
  5. var LeafMatchExpression = module.exports = function LeafMatchExpression( type ){
  6. base.call(this);
  7. this._matchType = type;
  8. this._elementPath = new ElementPath();
  9. }, klass = LeafMatchExpression, base = MatchExpression, proto = klass.prototype = Object.create(base.prototype, {constructor:{value:klass}});
  10. // File: expression_leaf.h lines: 63-63
  11. // ElementPath _elementPath;
  12. proto._elementPath = undefined;
  13. // File: expression_leaf.h lines: 62-62
  14. // StringData _path;
  15. proto._path = undefined;
  16. /**
  17. *
  18. * Initialize the ElementPath to the input path
  19. * @method initPath
  20. * @param path
  21. *
  22. */
  23. proto.initPath = function initPath( path ) { // const StringData& path
  24. // File: expression_leaf.cpp lines: 31-33
  25. this._path = path;
  26. if(this._elementPath === undefined){
  27. this._elementPath = new ElementPath();
  28. }
  29. return this._elementPath.init( this._path );
  30. };
  31. /**
  32. *
  33. * Check whether the input doc matches
  34. * @method matches
  35. * @param doc
  36. *
  37. */
  38. proto.matches = function matches( doc, details ) { // const MatchableDocument* doc, MatchDetails* details
  39. // File: expression_leaf.cpp lines: 37-48
  40. var self = this,
  41. checker = function(element) {
  42. /*if (element instanceof Array) {
  43. for (var i = 0; i < element.length; i++) {
  44. if(self.matchesSingleElement(element[i])) {
  45. if(details && details.needRecord()) {
  46. details.setElemMatchKey(i.toString());
  47. }
  48. return true;
  49. }
  50. }
  51. return false;
  52. }*/
  53. if (!self.matchesSingleElement(element)) {
  54. return false;
  55. }
  56. /*
  57. if( details && details.needRecord() && (element instanceof Array)) {
  58. details.setElemMatchKey( docKeys[i+1] );
  59. }
  60. */
  61. return true;
  62. };
  63. return this._elementPath._matches(doc, details, checker);
  64. /*
  65. var tDoc = ElementPath.objAtPath( doc, this._path );
  66. if(tDoc instanceof RegExp || typeof(tDoc) != 'object') {
  67. return this.matchesSingleElement(tDoc);
  68. }
  69. if(!this.matchesSingleElement( tDoc[docKeys[i]] ))
  70. continue;
  71. if( details && details.needRecord() && (tDoc instanceof Array) && i < docKeys.length-1 ) {
  72. console.log('test2');
  73. details.setElemMatchKey( docKeys[i+1] );
  74. }
  75. return true;
  76. }
  77. return false;
  78. */
  79. };
  80. /**
  81. *
  82. * Return the internal path
  83. * @method path
  84. * @param
  85. *
  86. */
  87. proto.path = function path( /* */ ){
  88. // File: expression_leaf.h lines: 56-55
  89. return this._path;
  90. };