ElemMatchValueMatchExpression.js 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. "use strict";
  2. var ArrayMatchingMatchExpression = require('./ArrayMatchingMatchExpression.js');
  3. // Autogenerated by cport.py on 2013-09-17 14:37
  4. var ElemMatchValueMatchExpression = module.exports = function ElemMatchValueMatchExpression(){
  5. base.call(this);
  6. this._matchType = 'ELEM_MATCH_VALUE';
  7. this._subs = [];
  8. }, klass = ElemMatchValueMatchExpression, base = ArrayMatchingMatchExpression, proto = klass.prototype = Object.create(base.prototype, {constructor:{value:klass}});
  9. // DEPENDENCIES
  10. var errors = require("../../Errors.js"),
  11. ErrorCodes = errors.ErrorCodes;
  12. // File: expression_array.h lines: 108-108
  13. proto._subs = undefined;
  14. /**
  15. *
  16. * Check if the input element matches all items in the array
  17. * @method _arrayElementMatchesAll
  18. * @param element
  19. *
  20. */
  21. proto._arrayElementMatchesAll = function _arrayElementMatchesAll(element){
  22. // File: expression_array.cpp lines: 152-157
  23. for (var i = 0; i < this._subs.length; i++ ) {
  24. if (!this._subs[i].matchesSingleElement(element))
  25. return false;
  26. }
  27. return true;
  28. };
  29. /**
  30. *
  31. * push an item onto the internal array
  32. * @method add
  33. * @param sub
  34. *
  35. */
  36. proto.add = function add(sub){
  37. // File: expression_array.cpp lines: 132-134
  38. if (!sub) throw new Error(sub + " ElemMatchValueMatchExpression:36");
  39. this._subs.push(sub);
  40. };
  41. /**
  42. *
  43. * Writes a debug string for this object
  44. * @method debugString
  45. * @param level
  46. *
  47. */
  48. proto.debugString = function debugString(level){
  49. // File: expression_array.cpp lines: 160-165
  50. var debug = this._debugAddSpace(level);
  51. debug = debug + this.path() + " $elemMatch\n";
  52. for (var i = 0; i < this._subs.length; i++) {
  53. debug = debug + this._subs[i].debugString(level + 1);
  54. }
  55. return debug;
  56. };
  57. /**
  58. *
  59. * Get the given child in the internal array
  60. * @method getChild
  61. * @param i
  62. *
  63. */
  64. proto.getChild = function getChild(i){
  65. // File: expression_array.h lines: 103-102
  66. return this._subs[i];
  67. };
  68. /**
  69. *
  70. * Initialize the necessary items
  71. * @method init
  72. * @param path
  73. * @param sub
  74. *
  75. */
  76. proto.init = function init(path, sub){
  77. // File: expression_array.cpp lines: 121-124
  78. this.initPath(path);
  79. if (sub)
  80. this.add(sub);
  81. return {code:ErrorCodes.OK};
  82. };
  83. /**
  84. *
  85. * Check if one of the items in the input array matches everything in the internal array
  86. * @method matchesArray
  87. * @param anArray
  88. * @param details
  89. *
  90. */
  91. proto.matchesArray = function matchesArray(anArray, details){
  92. // File: expression_array.cpp lines: 137-149
  93. for (var i in anArray) {
  94. var inner = anArray[i];
  95. if (this._arrayElementMatchesAll(inner)) {
  96. if (details && details.needRecord()) {
  97. details.setElemMatchKey(i);
  98. }
  99. return true;
  100. }
  101. }
  102. return false;
  103. };
  104. /**
  105. *
  106. * Return the number of items in the internal array
  107. * @method numChildren
  108. *
  109. */
  110. proto.numChildren = function numChildren(){
  111. // File: expression_array.h lines: 102-101
  112. return this._subs.length;
  113. };
  114. /**
  115. *
  116. * clone this instance to a new one
  117. * @method shallowClone
  118. *
  119. */
  120. proto.shallowClone = function shallowClone(){
  121. // File: expression_array.h lines: 91-97
  122. var element = new ElemMatchValueMatchExpression();
  123. element.init(this.path());
  124. for (var i = 0; i < this._subs.length; ++i) {
  125. element.add(this._subs[i].shallowClone());
  126. }
  127. return element;
  128. };