ModMatchExpression.js 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. "use strict";
  2. var LeafMatchExpression = require('./LeafMatchExpression');
  3. // Autogenerated by cport.py on 2013-09-17 14:37
  4. var ModMatchExpression = module.exports = function ModMatchExpression(){
  5. base.call(this);
  6. this._matchType = 'MOD';
  7. }, klass = ModMatchExpression, base = LeafMatchExpression, proto = klass.prototype = Object.create(base.prototype, {constructor:{value:klass}});
  8. // File: expression_leaf.h lines: 210-210
  9. proto._divisor = undefined;
  10. // File: expression_leaf.h lines: 211-211
  11. proto._remainder = undefined;
  12. /**
  13. *
  14. * Writes a debug string for this object
  15. * @method debugString
  16. * @param level
  17. *
  18. */
  19. proto.debugString = function debugString(level) {
  20. // File: expression_leaf.cpp lines: 253-261
  21. return this._debugAddSpace( level ) + this.path() + " mod " + this._divisor + " % x == " + this._remainder + (this.getTag() ? " " + this.getTag().debugString() : '') + "\n";
  22. };
  23. /**
  24. *
  25. * checks if this expression is == to the other
  26. * @method equivalent
  27. * @param other
  28. *
  29. */
  30. proto.equivalent = function equivalent(other) {
  31. // File: expression_leaf.cpp lines: 264-272
  32. if(other._matchType != 'MOD')
  33. return false;
  34. return this.path() == other.path() && this._divisor == other._divisor && this._remainder == other._remainder;
  35. };
  36. /**
  37. *
  38. * Return the _divisor property
  39. * @method getDivisor
  40. *
  41. */
  42. proto.getDivisor = function getDivisor(){
  43. // File: expression_leaf.h lines: 206-205
  44. return this._divisor;
  45. };
  46. /**
  47. *
  48. * Return the _remainder property
  49. * @method getRemainder
  50. *
  51. */
  52. proto.getRemainder = function getRemainder( /* */ ){
  53. // File: expression_leaf.h lines: 207-206
  54. return this._remainder;
  55. };
  56. /**
  57. *
  58. * Initialize the necessary items
  59. * @method init
  60. * @param path
  61. * @param type
  62. *
  63. */
  64. proto.init = function init(path,divisor,remainder) {
  65. // File: expression_leaf.cpp lines: 239-244
  66. if (divisor === 0 ){
  67. return {'code':'BAD_VALUE', 'desc':'Divisor cannot be 0'};
  68. }
  69. this._divisor = divisor;
  70. this._remainder = remainder;
  71. return this.initPath( path );
  72. };
  73. /**
  74. *
  75. * Check if the input element matches
  76. * @method matchesSingleElement
  77. * @param e
  78. *
  79. */
  80. proto.matchesSingleElement = function matchesSingleElement(e) {
  81. // File: expression_leaf.cpp lines: 247-250
  82. if(typeof(e) != 'number') {
  83. return false;
  84. }
  85. return (e % this._divisor) == this._remainder;
  86. };
  87. /**
  88. *
  89. * clone this instance to a new one
  90. * @method shallowClone
  91. *
  92. */
  93. proto.shallowClone = function shallowClone(){
  94. // File: expression_leaf.h lines: 194-197
  95. var e = new ModMatchExpression();
  96. e.init(this.path(),this._divisor, this._remainder);
  97. return e;
  98. };