ArrayFilterEntries.js 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203
  1. "use strict";
  2. var Value = require('../Value');
  3. // Autogenerated by cport.py on 2013-09-17 14:37
  4. var ArrayFilterEntries = module.exports = function ArrayFilterEntries(){
  5. this._hasNull = false;
  6. this._hasEmptyArray = false;
  7. this._equalities = [];
  8. this._regexes = [];
  9. }, klass = ArrayFilterEntries, base = Object, proto = klass.prototype = Object.create(base.prototype, {constructor:{value:klass}});
  10. // File: expression_leaf.h lines: 266-266
  11. proto._equalities = undefined;
  12. // File: expression_leaf.h lines: 265-265
  13. proto._hasEmptyArray = undefined;
  14. // File: expression_leaf.h lines: 264-264
  15. proto._hasNull = undefined;
  16. // File: expression_leaf.h lines: 267-267
  17. proto._regexes = undefined;
  18. /**
  19. *
  20. * Push the input expression onto the _equalities array
  21. * @method addEquality
  22. * @param e
  23. *
  24. */
  25. proto.addEquality = function addEquality(e) {
  26. //File expression_leaf.cpp lines 369-387
  27. if(e instanceof Object && Object.keys(e)[0][0] === '$'){
  28. return {'code':'BAD_VALUE', 'desc':'cannot next $ under $in'};
  29. }
  30. if( e instanceof RegExp ) {
  31. return {'code': 'BAD_VALUE', 'desc':'ArrayFilterEntries equality cannot be a regex'};
  32. }
  33. if( e === null ) {
  34. this._hasNull = true;
  35. }
  36. if (e instanceof Array && e.length === 0) {
  37. this._hasEmptyArray = true;
  38. }
  39. this._equalities.push( e );
  40. return {'code':'OK'};
  41. };
  42. /**
  43. *
  44. * Push the input regex onto the _regexes array
  45. * @method addRegex
  46. * @param expr
  47. *
  48. */
  49. proto.addRegex = function addRegex(expr) {
  50. // File: expression_leaf.cpp lines: 389-391
  51. this._regexes.push( expr );
  52. return {'code':'OK'};
  53. };
  54. /**
  55. *
  56. * Check if the input element is contained inside of _equalities
  57. * @method contains
  58. * @param elem
  59. *
  60. */
  61. proto.contains = function contains(elem) {
  62. // File: expression_leaf.h lines: 249-248
  63. for (var i = 0; i < this._equalities.length; i++) {
  64. if(typeof(elem) == typeof(this._equalities[i])){
  65. if(Value.compare(elem, this._equalities[i]) === 0) {
  66. return true;
  67. }
  68. }
  69. }
  70. return false;
  71. };
  72. /**
  73. *
  74. * Copy our internal fields to the input
  75. * @method copyTo
  76. * @param toFillIn
  77. *
  78. */
  79. proto.copyTo = function copyTo(toFillIn) {
  80. // File: expression_leaf.cpp lines: 407-412
  81. toFillIn._hasNull = this._hasNull;
  82. toFillIn._hasEmptyArray = this._hasEmptyArray;
  83. toFillIn._equalities = this._equalities.slice(0); // Copy array
  84. toFillIn._regexes = this._regexes.slice(0); // Copy array
  85. };
  86. /**
  87. *
  88. * Return the _equalities property
  89. * @method equalities
  90. *
  91. */
  92. proto.equalities = function equalities(){
  93. // File: expression_leaf.h lines: 248-247
  94. return this._equalities;
  95. };
  96. /**
  97. *
  98. * checks if this expression is == to the other
  99. * @method equivalent
  100. * @param other
  101. *
  102. */
  103. proto.equivalent = function equivalent(other) {
  104. // File: expression_leaf.cpp lines: 394-404
  105. if (this._hasNull != other._hasNull) {return false;}
  106. if (this._regexes.length != other._regexes.length) {return false;}
  107. for (var i = 0; i < this._regexes.length; i++) {
  108. if ( !this._regexes[i].equivalent( other._regexes[i] ) ) {
  109. return false;
  110. }
  111. }
  112. return Value.compare(this._equalities, other._equalities);
  113. };
  114. /**
  115. *
  116. * Return the _hasEmptyArray property
  117. * @method hasEmptyArray
  118. *
  119. */
  120. proto.hasEmptyArray = function hasEmptyArray(){
  121. // File: expression_leaf.h lines: 256-255
  122. return this._hasEmptyArray;
  123. };
  124. /**
  125. *
  126. * Return the _hasNull property
  127. * @method hasNull
  128. *
  129. */
  130. proto.hasNull = function hasNull(){
  131. // File: expression_leaf.h lines: 254-253
  132. return this._hasNull;
  133. };
  134. /**
  135. *
  136. * Return the length of the _regexes property
  137. * @method numRegexes
  138. *
  139. */
  140. proto.numRegexes = function numRegexes(){
  141. // File: expression_leaf.h lines: 251-250
  142. return this._regexes.length;
  143. };
  144. /**
  145. *
  146. * Return the regex at the given index
  147. * @method regex
  148. * @param idx
  149. *
  150. */
  151. proto.regex = function regex(idx) {
  152. // File: expression_leaf.h lines: 252-251
  153. return this._regexes[idx];
  154. };
  155. /**
  156. *
  157. * Return whether we have a single item and it is null
  158. * @method singleNull
  159. *
  160. */
  161. proto.singleNull = function singleNull(){
  162. // File: expression_leaf.h lines: 255-254
  163. return this.size() == 1 && this._hasNull;
  164. };
  165. /**
  166. *
  167. * Return the length of both _regexes and _equalities
  168. * @method size
  169. *
  170. */
  171. proto.size = function size(){
  172. // File: expression_leaf.h lines: 257-256
  173. return this._equalities.length + this._regexes.length;
  174. };