InMatchExpression.js 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  1. "use strict";
  2. var LeafMatchExpression = require('./LeafMatchExpression');
  3. // Autogenerated by cport.py on 2013-09-17 14:37
  4. var InMatchExpression = module.exports = function InMatchExpression(){
  5. base.call(this);
  6. this._matchType = 'MATCH_IN';
  7. this._arrayEntries = new ArrayFilterEntries();
  8. }, klass = InMatchExpression, base = LeafMatchExpression, proto = klass.prototype = Object.create(base.prototype, {constructor:{value:klass}});
  9. // DEPENDENCIES
  10. var errors = require("../../Errors.js"),
  11. ErrorCodes = errors.ErrorCodes,
  12. ArrayFilterEntries = require("./ArrayFilterEntries.js");
  13. // File: expression_leaf.h lines: 294-294
  14. proto._arrayEntries = null;
  15. /**
  16. *
  17. * Check if the input element matches a real element
  18. * @method _matchesRealElement
  19. * @param e
  20. *
  21. */
  22. proto._matchesRealElement = function _matchesRealElement(e) {
  23. // File: expression_leaf.cpp lines: 422-431
  24. if(this._arrayEntries.contains(e)) { // array wrapper.... so no e "in" array
  25. return true;
  26. }
  27. for (var i = 0; i < this._arrayEntries.numRegexes(); i++) {
  28. if(e.match && e.match(this._arrayEntries.regex(i)._regex)) {
  29. return true;
  30. } else if (e instanceof RegExp) {
  31. if(e.toString() == this._arrayEntries.regex(i)._regex.toString()) {
  32. return true;
  33. }
  34. }
  35. }
  36. if(typeof(e) == 'undefined') {
  37. return true; // Every Set contains the Null Set, man.
  38. }
  39. return false;
  40. };
  41. /**
  42. *
  43. * Copy our array to the input array
  44. * @method copyTo
  45. * @param toFillIn
  46. *
  47. */
  48. proto.copyTo = function copyTo(toFillIn) {
  49. // File: expression_leaf.cpp lines: 481-483
  50. toFillIn.init(this.path());
  51. this._arrayEntries.copyTo( toFillIn._arrayEntries );
  52. };
  53. /**
  54. *
  55. * Writes a debug string for this object
  56. * @method debugString
  57. * @param level
  58. *
  59. */
  60. proto.debugString = function debugString(level) {
  61. // File: expression_leaf.cpp lines: 455-463
  62. return this._debugAddSpace( level ) + this.path() + ";$in: TODO " + (this.getTag() ? this.getTag().debugString() : '') + "\n";
  63. };
  64. /**
  65. *
  66. * checks if this expression is == to the other
  67. * @method equivalent
  68. * @param other
  69. *
  70. */
  71. proto.equivalent = function equivalent(other) {
  72. // File: expression_leaf.cpp lines: 466-472
  73. if ( other._matchType != 'MATCH_IN' ) {
  74. return false;
  75. }
  76. return this.path() == other.path() && this._arrayEntries.equivalent( other._arrayEntries );
  77. };
  78. /**
  79. *
  80. * Return the _arrayEntries property
  81. * @method getArrayFilterEntries
  82. *
  83. */
  84. proto.getArrayFilterEntries = function getArrayFilterEntries(){
  85. // File: expression_leaf.h lines: 280-279
  86. return this._arrayEntries;
  87. };
  88. /**
  89. *
  90. * Return the _arrayEntries property
  91. * @method getData
  92. *
  93. */
  94. proto.getData = function getData(){
  95. // File: expression_leaf.h lines: 290-289
  96. return this._arrayEntries;
  97. };
  98. /**
  99. *
  100. * Initialize the necessary items
  101. * @method init
  102. * @param path
  103. *
  104. */
  105. proto.init = function init(path) {
  106. // File: expression_leaf.cpp lines: 418-419
  107. return this.initPath( path );
  108. };
  109. /**
  110. *
  111. * Check if the input element matches
  112. * @method matchesSingleElement
  113. * @param e
  114. *
  115. */
  116. proto.matchesSingleElement = function matchesSingleElement(e) {
  117. // File: expression_leaf.cpp lines: 434-452
  118. if( this._arrayEntries === null && typeof(e) == 'object' && Object.keys(e).length === 0) {
  119. return true;
  120. }
  121. if (this._matchesRealElement( e )) {
  122. return true;
  123. }
  124. /*if (e instanceof Array){
  125. for (var i = 0; i < e.length; i++) {
  126. if(this._matchesRealElement( e[i] )) {
  127. return true;
  128. }
  129. }
  130. }*/
  131. return false;
  132. };
  133. /**
  134. *
  135. * clone this instance to a new one
  136. * @method shallowClone
  137. *
  138. */
  139. proto.shallowClone = function shallowClone(){
  140. // File: expression_leaf.cpp lines: 475-478
  141. var e = new InMatchExpression();
  142. this.copyTo( e );
  143. return e;
  144. };