AllElemMatchOp.js 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229
  1. "use strict";
  2. var MatchExpression = require('./MatchExpression');
  3. // Autogenerated by cport.py on 2013-09-17 14:37
  4. var AllElemMatchOp = module.exports = function AllElemMatchOp(){
  5. base.call(this);
  6. this._matchType = 'ALL';
  7. this._elementPath = new ElementPath();
  8. this._list = [];
  9. }, klass = AllElemMatchOp, 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: 175-175
  15. // ElementPath _elementPath;
  16. proto._elementPath = undefined;
  17. // File: expression_array.h lines: 176-176
  18. // std::vector< const ArrayMatchingMatchExpression* > _list;
  19. proto._list = undefined;
  20. // File: expression_array.h lines: 174-174
  21. // StringData _path;
  22. proto._path = undefined;
  23. /**
  24. *
  25. * This method checks the input array and determines if each item inside matches
  26. * @method _allMatch
  27. * @param anArray
  28. *
  29. */
  30. proto._allMatch = function _allMatch( anArray ){ // const BSONObj& anArray
  31. // File: expression_array.cpp lines: 208-215
  32. if(this._list.length === 0) { return false; }
  33. for (var i = 0; i < this._list.length; i++) {
  34. if( ! this._list[i].matchesArray( anArray, null ) ) { return false; }
  35. }
  36. return true;
  37. };
  38. /**
  39. *
  40. * This method adds a new expression to the internal array of expression
  41. * @method add
  42. * @param expr
  43. *
  44. */
  45. proto.add = function add( expr ){// const ArrayMatchingMatchExpression* expr
  46. // File: expression_array.cpp lines: 184-186
  47. if (!expr) throw new Error("AllElemMatchOp:add#68 failed to verify expr");
  48. this._list.push(expr);
  49. };
  50. /**
  51. *
  52. * Writes a debug string for this object
  53. * @method debugString
  54. * @param level
  55. *
  56. */
  57. proto.debugString = function debugString( level ){ // StringBuilder& debug, int level
  58. // File: expression_array.cpp lines: 219-224
  59. console.debug(this._debugAddSpace(level) + this._path + " AllElemMatchOp: " + this._path + '\n');
  60. for (var i = 0; i < this._list.length; i++) {
  61. this._list[i].debugString(level +1);
  62. }
  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 ){// const MatchExpression* other
  72. // File: expression_array.cpp lines: 227-242
  73. if (this.matchType() != other.matchType()) {
  74. return false;
  75. }
  76. if( this._path != other._path ) {
  77. return false;
  78. }
  79. if( this._list.length != other._list.length ) {
  80. return false;
  81. }
  82. for (var i = 0; i < this._list.length; i++) {
  83. if ( !this._list[i].equivalent( other._list[i] ) ) {
  84. return false;
  85. }
  86. }
  87. return true;
  88. };
  89. /**
  90. *
  91. * gets the specified item from the list
  92. * @method getChild
  93. * @param i
  94. *
  95. */
  96. proto.getChild = function getChild( i ){ // size_t i
  97. // File: expression_array.h lines: 167-166
  98. return this._list[i];
  99. };
  100. /**
  101. *
  102. * Initialize the necessary items
  103. * @method init
  104. * @param path
  105. *
  106. */
  107. proto.init = function init( path ){ // const StringData& path
  108. // File: expression_array.cpp lines: 177-181
  109. this._path = path;
  110. var s = this._elementPath.init( this._path );
  111. this._elementPath.setTraverseLeafArray( false );
  112. return s;
  113. };
  114. /**
  115. *
  116. * matches checks the input doc against the internal path to see if it is a match
  117. * @method matches
  118. * @param doc
  119. * @param details
  120. *
  121. */
  122. proto.matches = function matches(doc, details){
  123. // File: expression_array.cpp lines: 189-198
  124. var self = this,
  125. checker = function(element) {
  126. if (!(element instanceof Array))
  127. return false;
  128. //var amIRoot = (element.length === 0);
  129. if (self._allMatch(element))
  130. return true;
  131. /*
  132. if (!amIRoot && details && details.needRecord() {
  133. details.setElemMatchKey(element);
  134. }
  135. */
  136. return false;
  137. };
  138. return this._elementPath._matches(doc, details, checker);
  139. };
  140. /**
  141. *
  142. * Check if the input element matches
  143. * @method matchesSingleElement
  144. * @param e
  145. *
  146. */
  147. proto.matchesSingleElement = function matchesSingleElement( e ){ // const BSONElement& e
  148. // File: expression_array.cpp lines: 201-205
  149. if (!(e instanceof Array)) {
  150. return false;
  151. }
  152. return this._allMatch(e);
  153. };
  154. /**
  155. *
  156. * return the length of the internal array
  157. * @method numChildren
  158. * @param
  159. *
  160. */
  161. proto.numChildren = function numChildren( /* */ ){
  162. // File: expression_array.h lines: 166-165
  163. return this._list.length;
  164. };
  165. /**
  166. *
  167. * return the internal path
  168. * @method path
  169. * @param
  170. *
  171. */
  172. proto.path = function path( /* */ ){
  173. // File: expression_array.h lines: 169-168
  174. return this._path;
  175. };
  176. /**
  177. *
  178. * clone this instance to a new one
  179. * @method shallowClone
  180. * @param
  181. *
  182. */
  183. proto.shallowClone = function shallowClone( /* */ ){
  184. // File: expression_array.h lines: 145-152
  185. var e = new AllElemMatchOp();
  186. e.init( this._path );
  187. e._list = this._list.slice(0);
  188. return e;
  189. };