TypeMatchExpression.js 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189
  1. "use strict";
  2. var MatchExpression = require('./MatchExpression');
  3. var ElementPath = require('./ElementPath');
  4. // Autogenerated by cport.py on 2013-09-17 14:37
  5. var TypeMatchExpression = module.exports = function TypeMatchExpression(){
  6. this._matchType = 'TYPE_OPERATOR';
  7. }, klass = TypeMatchExpression, base = Object , proto = klass.prototype = Object.create(base.prototype, {constructor:{value:klass}});
  8. // File: expression_leaf.h lines: 338-338
  9. // ElementPath _elementPath;
  10. proto._elementPath = undefined;
  11. // File: expression_leaf.h lines: 337-337
  12. // StringData _path;
  13. proto._path = undefined;
  14. // File: expression_leaf.h lines: 339-339
  15. // int _type;
  16. proto._type = undefined;
  17. /**
  18. *
  19. * This documentation was automatically generated. Please update when you touch this function.
  20. * @method debugString
  21. * @param
  22. *
  23. */
  24. proto.debugString = function debugString( level ) { // StringBuilder& debug, int level
  25. // File: expression_leaf.cpp lines: 335-343
  26. return this._debugAddSapce( level ) + this.path() + " type: " + this._type + (this.getTag() ? this.getTag().debugString() : '' ) + "\n";
  27. };
  28. /**
  29. *
  30. * This documentation was automatically generated. Please update when you touch this function.
  31. * @method equivalent
  32. * @param
  33. *
  34. */
  35. proto.equivalent = function equivalent( other ) { // const MatchExpression* other
  36. // File: expression_leaf.cpp lines: 347-352
  37. if( other._matchType != 'TYPE_OPERATOR' ) {
  38. return false;
  39. }
  40. return this._path == other._path && this._type == other._type;
  41. };
  42. /**
  43. *
  44. * This documentation was automatically generated. Please update when you touch this function.
  45. * @method getData
  46. * @param
  47. *
  48. */
  49. proto.getData = function getData( /* */ ){
  50. // File: expression_leaf.h lines: 328-327
  51. return this._type;
  52. };
  53. /**
  54. *
  55. * This documentation was automatically generated. Please update when you touch this function.
  56. * @method init
  57. * @param
  58. *
  59. */
  60. proto.init = function init( path,type ) { // const StringData& path, int type
  61. // File: expression_leaf.cpp lines: 308-311
  62. this._path = path;
  63. this._type = type;
  64. return this._elementPath.init( path );
  65. };
  66. /**
  67. *
  68. * This documentation was automatically generated. Please update when you touch this function.
  69. * @method matches
  70. * @param
  71. *
  72. */
  73. /*
  74. proto.matches = function matches( doc,details ) { // const MatchableDocument* doc, MatchDetails* details
  75. // File: expression_leaf.cpp lines: 318-332
  76. // bool TypeMatchExpression::matches( const MatchableDocument* doc, MatchDetails* details ) const {
  77. // boost::scoped_ptr<ElementIterator> cursor( doc->getIterator( _elementPath ) );
  78. // while ( cursor->more() ) {
  79. // ElementIterator::Context e = cursor->next();
  80. // if ( e.outerArray() )
  81. // continue;
  82. //
  83. // if ( !matchesSingleElement( e.element() ) )
  84. // continue;
  85. // if ( details && details->needRecord() && !e.arrayOffset().eoo() ) {
  86. // details->setElemMatchKey( e.arrayOffset().fieldName() );
  87. // }
  88. // return true;
  89. // }
  90. // return false;
  91. // }
  92. var tDoc = ElementPath.objAtPath( doc, this._path );
  93. };*/
  94. klass.typeNumber = function typeNumber( e ){
  95. if(e === undefined)
  96. return 6;
  97. if(e === null)
  98. return 10;
  99. if(typeof(e) == 'number')
  100. return 1;
  101. if(typeof(e) == 'string')
  102. return 2;
  103. if(typeof(e) == 'boolean')
  104. return 8;
  105. if(typeof(e) == 'object') {
  106. if(e instanceof Array)
  107. return 4;
  108. if(e instanceof Regexp)
  109. return 11;
  110. if(e instanceof Date)
  111. return 9;
  112. if(e.constructor.name == 'MinKey')
  113. return -1;
  114. if(e.construcor.name == 'MAxKey')
  115. return 127;
  116. }
  117. return 42; // Can't tell
  118. };
  119. /**
  120. *
  121. * This documentation was automatically generated. Please update when you touch this function.
  122. * @method matchesSingleElement
  123. * @param
  124. *
  125. */
  126. proto.matchesSingleElement = function matchesSingleElement( e ) { // const BSONElement& e
  127. // File: expression_leaf.cpp lines: 314-315
  128. return klass.typeNumber( e ) == this._type;
  129. };
  130. /**
  131. *
  132. * This documentation was automatically generated. Please update when you touch this function.
  133. * @method path
  134. * @param
  135. *
  136. */
  137. proto.path = function path( /* */ ){
  138. // File: expression_leaf.h lines: 330-329
  139. return this._path();
  140. };
  141. /**
  142. *
  143. * This documentation was automatically generated. Please update when you touch this function.
  144. * @method shallowClone
  145. * @param
  146. *
  147. */
  148. proto.shallowClone = function shallowClone( /* */ ){
  149. // File: expression_leaf.h lines: 311-314
  150. // virtual MatchExpression* shallowClone() const {
  151. // TypeMatchExpression* e = new TypeMatchExpression();
  152. // e->init(_path, _type);
  153. // return e;
  154. // }
  155. var e = new TypeMatchExpression();
  156. e.init( this._path,this._type );
  157. return e;
  158. };