ArrayMatchingMatchExpression.js 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. "use strict";
  2. var MatchExpression = require('./MatchExpression');
  3. // Autogenerated by cport.py on 2013-09-17 14:37
  4. var ArrayMatchingMatchExpression = module.exports = function ArrayMatchingMatchExpression(matchType){
  5. base.call(this);
  6. this._matchType = matchType;
  7. // File: expression_array.h lines: 55-55
  8. this._elementPath = new ElementPath();
  9. }, klass = ArrayMatchingMatchExpression, base = MatchExpression, proto = klass.prototype = Object.create(base.prototype, {constructor:{value:klass}});
  10. // DEPENDENCIES
  11. var errors = require("../../Errors.js"),
  12. ErrorCodes = errors.ErrorCodes,
  13. ElementPath = require('./ElementPath.js');
  14. // File: expression_array.h lines: 54-54
  15. proto._path = undefined;
  16. /**
  17. *
  18. * Check if the input element is equivalent to us
  19. * @method equivalent
  20. * @param
  21. *
  22. */
  23. proto.equivalent = function equivalent(other){
  24. // File: expression_array.cpp lines: 63-79
  25. if ( this._matchType != other._matchType)
  26. return false;
  27. var realOther = new ArrayMatchingMatchExpression(other);
  28. if (this._path != realOther._path)
  29. return false;
  30. if (this.numChildren() != realOther.numChildren())
  31. return false;
  32. for (var i = 0; i < this.numChildren(); i++)
  33. if (!this.getChild(i).equivalent(realOther.getChild(i)))
  34. return false;
  35. return true;
  36. };
  37. /**
  38. *
  39. * Initialize the input path as our element path
  40. * @method initPath
  41. * @param path
  42. *
  43. */
  44. proto.initPath = function initPath(path){
  45. // File: expression_array.cpp lines: 27-31
  46. this._path = path;
  47. var status = this._elementPath.init(this._path);
  48. this._elementPath.setTraverseLeafArray(false);
  49. return status;
  50. };
  51. /**
  52. *
  53. * matches checks the input doc against the internal path to see if it is a match
  54. * @method matches
  55. * @param doc
  56. * @param details
  57. *
  58. */
  59. proto.matches = function matches(doc, details){
  60. var self = this,
  61. checker = function(element) {
  62. // we got the whole path, now check it
  63. if (!(element instanceof Array))
  64. return false;
  65. //var amIRoot = (element.length === 0);
  66. if (!self.matchesArray(element, details))
  67. return false;
  68. /*
  69. if (!amIRoot && details && details.needRecord() {
  70. details.setElemMatchKey(element);
  71. }
  72. */
  73. return true;
  74. };
  75. return this._elementPath._matches(doc, details, checker);
  76. };
  77. /**
  78. *
  79. * Check if the input element matches
  80. * @method matchesSingleElement
  81. * @param
  82. *
  83. */
  84. proto.matchesSingleElement = function matchesSingleElement(element){
  85. // File: expression_array.cpp lines: 56-59
  86. if (!(element instanceof Array))
  87. return false;
  88. return this.matchesArray(element, null);
  89. };
  90. /**
  91. *
  92. * return the internal path
  93. * @method path
  94. * @param
  95. *
  96. */
  97. proto.path = function path(){
  98. // File: expression_array.h lines: 52-51
  99. return this._path;
  100. };
  101. /**
  102. *
  103. * Check if the input array matches
  104. * @method path
  105. * @param anArray
  106. * @param details
  107. *
  108. */
  109. proto.matchesArray = function matchesArray(anArray, details){
  110. throw new Error("not implemented");
  111. };