TypeMatchExpression.js 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  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. base.call(this);
  7. this._elementPath = new ElementPath();
  8. this._matchType = 'TYPE_OPERATOR';
  9. }, klass = TypeMatchExpression, base = MatchExpression, proto = klass.prototype = Object.create(base.prototype, {constructor:{value:klass}});
  10. // File: expression_leaf.h lines: 338-338
  11. proto._elementPath = undefined;
  12. // File: expression_leaf.h lines: 337-337
  13. proto._path = undefined;
  14. // File: expression_leaf.h lines: 339-339
  15. proto._type = undefined;
  16. /**
  17. *
  18. * Writes a debug string for this object
  19. * @method debugString
  20. * @param level
  21. *
  22. */
  23. proto.debugString = function debugString(level) {
  24. // File: expression_leaf.cpp lines: 335-343
  25. return this._debugAddSapce( level ) + this.path() + " type: " + this._type + (this.getTag() ? this.getTag().debugString() : '' ) + "\n";
  26. };
  27. /**
  28. *
  29. * checks if this expression is == to the other
  30. * @method equivalent
  31. * @param other
  32. *
  33. */
  34. proto.equivalent = function equivalent(other) {
  35. // File: expression_leaf.cpp lines: 347-352
  36. if( other._matchType != 'TYPE_OPERATOR' ) {
  37. return false;
  38. }
  39. return this._path == other._path && this._type == other._type;
  40. };
  41. /**
  42. *
  43. * Return the _type property
  44. * @method getData
  45. *
  46. */
  47. proto.getData = function getData(){
  48. // File: expression_leaf.h lines: 328-327
  49. return this._type;
  50. };
  51. /**
  52. *
  53. * Initialize the necessary items
  54. * @method init
  55. * @param path
  56. * @param type
  57. *
  58. */
  59. proto.init = function init(path,type) {
  60. // File: expression_leaf.cpp lines: 308-311
  61. this._path = path;
  62. this._type = type;
  63. return this._elementPath.init( path );
  64. };
  65. /**
  66. *
  67. * matches checks the input doc against the internal element path to see if it is a match
  68. * @method matches
  69. * @param doc
  70. * @param details
  71. *
  72. */
  73. proto.matches = function matches(doc,details) {
  74. // File: expression_leaf.cpp lines: 318-332
  75. var self = this,
  76. checker = function(element) {
  77. if (!self.matchesSingleElement(element, details))
  78. return false;
  79. //var amIRoot = (element.length === 0);
  80. return true;
  81. };
  82. return this._elementPath._matches(doc, details, checker);
  83. };
  84. /**
  85. * Return a number indicating the type of the input element
  86. * @method typeNumber
  87. * @param e
  88. *
  89. */
  90. klass.typeNumber = function typeNumber(e){
  91. if(e === undefined)
  92. return 6;
  93. if(e === null)
  94. return 10;
  95. if(typeof(e) == 'number')
  96. return 1;
  97. if(typeof(e) == 'string')
  98. return 2;
  99. if(typeof(e) == 'boolean')
  100. return 8;
  101. if(typeof(e) == 'object') {
  102. if(e instanceof Array)
  103. return 4;
  104. if(e instanceof RegExp)
  105. return 11;
  106. if(e instanceof Date)
  107. return 9;
  108. if(e.constructor.name == 'MinKey')
  109. return -1;
  110. if(e.constructor.name == 'MAxKey')
  111. return 127;
  112. }
  113. return 42; // Can't tell
  114. };
  115. /**
  116. *
  117. * Check if the input element matches
  118. * @method matchesSingleElement
  119. * @param e
  120. *
  121. */
  122. proto.matchesSingleElement = function matchesSingleElement(e) {
  123. // File: expression_leaf.cpp lines: 314-315
  124. return klass.typeNumber( e ) == this._type;
  125. };
  126. /**
  127. *
  128. * return the internal path
  129. * @method path
  130. *
  131. */
  132. proto.path = function path(){
  133. // File: expression_leaf.h lines: 330-329
  134. return this._path;
  135. };
  136. /**
  137. *
  138. * clone this instance to a new one
  139. * @method shallowClone
  140. *
  141. */
  142. proto.shallowClone = function shallowClone(){
  143. // File: expression_leaf.h lines: 311-314
  144. var e = new TypeMatchExpression();
  145. e.init( this._path,this._type );
  146. return e;
  147. };