VariablesIdGenerator.js 813 B

12345678910111213141516171819202122232425262728293031
  1. "use strict";
  2. /**
  3. * Generates Variables::Ids and keeps track of the number of Ids handed out.
  4. * @class VariablesIdGenerator
  5. * @namespace mungedb-aggregate.pipeline.expressions
  6. * @module mungedb-aggregate
  7. * @constructor
  8. */
  9. var VariablesIdGenerator = module.exports = function VariablesIdGenerator(){
  10. this._nextId = 0;
  11. }, klass = VariablesIdGenerator, proto = klass.prototype;
  12. /**
  13. * Gets the next unused id
  14. * @method generateId
  15. * @return {Number} The unused id
  16. */
  17. proto.generateId = function generateId() {
  18. return this._nextId++;
  19. };
  20. /**
  21. * Returns the number of Ids handed out by this Generator.
  22. * Return value is intended to be passed to Variables constructor.
  23. * @method getIdCount
  24. * @return {Number} The number of used ids
  25. */
  26. proto.getIdCount = function getIdCount() {
  27. return this._nextId;
  28. };