AllElemMatchOp.js 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241
  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 documentation was automatically generated. Please update when you touch this function.
  26. * @method _allMatch
  27. * @param
  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 documentation was automatically generated. Please update when you touch this function.
  41. * @method add
  42. * @param
  43. *
  44. */
  45. proto.add = function add( expr ){// const ArrayMatchingMatchExpression* expr
  46. // File: expression_array.cpp lines: 184-186
  47. // void AllElemMatchOp::add( const ArrayMatchingMatchExpression* expr ) {
  48. // verify( expr );
  49. // _list.push_back( expr );
  50. // }
  51. if (!expr) throw new Error("AllElemMatchOp:add#68 failed to verify expr");
  52. this._list.push(expr);
  53. };
  54. /**
  55. *
  56. * This documentation was automatically generated. Please update when you touch this function.
  57. * @method debugString
  58. * @param
  59. *
  60. */
  61. proto.debugString = function debugString( level ){ // StringBuilder& debug, int level
  62. // File: expression_array.cpp lines: 219-224
  63. // void AllElemMatchOp::debugString( StringBuilder& debug, int level ) const {
  64. // _debugAddSpace( debug, level );
  65. // debug << _path << " AllElemMatchOp: " << _path << "\n";
  66. // for ( size_t i = 0; i < _list.size(); i++ ) {
  67. // _list[i]->debugString( debug, level + 1);
  68. // }
  69. // }
  70. console.debug(this._debugAddSpace(level) + this._path + " AllElemMatchOp: " + this._path + '\n');
  71. for (var i = 0; i < this._list.length; i++) {
  72. this._list[i].debugString(level +1);
  73. }
  74. };
  75. /**
  76. *
  77. * This documentation was automatically generated. Please update when you touch this function.
  78. * @method equivalent
  79. * @param
  80. *
  81. */
  82. proto.equivalent = function equivalent( other ){// const MatchExpression* other
  83. // File: expression_array.cpp lines: 227-242
  84. if (this.matchType() != other.matchType()) {
  85. return false;
  86. }
  87. if( this._path != other._path ) {
  88. return false;
  89. }
  90. if( this._list.length != other._list.length ) {
  91. return false;
  92. }
  93. for (var i = 0; i < this._list.length; i++) {
  94. if ( !this._list[i].equivalent( other._list[i] ) ) {
  95. return false;
  96. }
  97. }
  98. return true;
  99. };
  100. /**
  101. *
  102. * This documentation was automatically generated. Please update when you touch this function.
  103. * @method getChild
  104. * @param
  105. *
  106. */
  107. proto.getChild = function getChild( i ){ // size_t i
  108. // File: expression_array.h lines: 167-166
  109. return this._list[i];
  110. };
  111. /**
  112. *
  113. * This documentation was automatically generated. Please update when you touch this function.
  114. * @method init
  115. * @param
  116. *
  117. */
  118. proto.init = function init( path ){ // const StringData& path
  119. // File: expression_array.cpp lines: 177-181
  120. this._path = path;
  121. var s = this._elementPath.init( this._path );
  122. this._elementPath.setTraverseLeafArray( false );
  123. return s;
  124. };
  125. /**
  126. *
  127. * matches checks the input doc against the internal path to see if it is a match
  128. * @method matches
  129. * @param doc
  130. * @param details
  131. *
  132. */
  133. proto.matches = function matches(doc, details){
  134. // File: expression_array.cpp lines: 189-198
  135. var self = this,
  136. checker = function(element) {
  137. if (!(element instanceof Array))
  138. return false;
  139. //var amIRoot = (element.length === 0);
  140. if (self._allMatch(element))
  141. return true;
  142. /*
  143. if (!amIRoot && details && details.needRecord() {
  144. details.setElemMatchKey(element);
  145. }
  146. */
  147. return false;
  148. };
  149. return this._elementPath._matches(doc, details, checker);
  150. };
  151. /**
  152. *
  153. * This documentation was automatically generated. Please update when you touch this function.
  154. * @method matchesSingleElement
  155. * @param
  156. *
  157. */
  158. proto.matchesSingleElement = function matchesSingleElement( e ){ // const BSONElement& e
  159. // File: expression_array.cpp lines: 201-205
  160. if (!(e instanceof Array)) {
  161. return false;
  162. }
  163. return this._allMatch(e);
  164. };
  165. /**
  166. *
  167. * This documentation was automatically generated. Please update when you touch this function.
  168. * @method numChildren
  169. * @param
  170. *
  171. */
  172. proto.numChildren = function numChildren( /* */ ){
  173. // File: expression_array.h lines: 166-165
  174. return this._list.length;
  175. };
  176. /**
  177. *
  178. * This documentation was automatically generated. Please update when you touch this function.
  179. * @method path
  180. * @param
  181. *
  182. */
  183. proto.path = function path( /* */ ){
  184. // File: expression_array.h lines: 169-168
  185. return this._path;
  186. };
  187. /**
  188. *
  189. * This documentation was automatically generated. Please update when you touch this function.
  190. * @method shallowClone
  191. * @param
  192. *
  193. */
  194. proto.shallowClone = function shallowClone( /* */ ){
  195. // File: expression_array.h lines: 145-152
  196. var e = new AllElemMatchOp();
  197. e.init( this._path );
  198. e._list = this._list.slice(0);
  199. return e;
  200. };