logo

libbulletml

Library of Bullet Markup Language (forked from https://shinh.skr.jp/libbulletml/index_en.html )git clone https://anongit.hacktivis.me/git/libbulletml.git/

formula-variables.h (1010B)


  1. #ifndef FORMULA_VARIABLE_H_
  2. #define FORMULA_VARIABLE_H_
  3. #include "formula.h"
  4. #include "bulletmlrunner.h"
  5. #include "bulletmlcommon.h"
  6. #include <cstdlib>
  7. #include <vector>
  8. namespace Variables {
  9. DECLSPEC extern double rank;
  10. DECLSPEC extern std::vector<double>* parameters;
  11. DECLSPEC extern BulletMLRunner* runner;
  12. }
  13. template <typename Val_>
  14. class Random : public AbstractNumber<Val_> {
  15. public:
  16. DECLSPEC virtual Val_ value() const {
  17. return Variables::runner->getRand();
  18. }
  19. };
  20. template <typename Val_>
  21. class Rank : public AbstractNumber<Val_> {
  22. public:
  23. DECLSPEC virtual Val_ value() const {
  24. return Variables::rank;
  25. }
  26. };
  27. template <typename Val_>
  28. class Param : public AbstractNumber<Val_> {
  29. public:
  30. DECLSPEC explicit Param(unsigned int id) : id_(id) {}
  31. DECLSPEC virtual Val_ value() const {
  32. if (Variables::parameters && id_ < Variables::parameters->size()) {
  33. return (*Variables::parameters)[id_];
  34. }
  35. else {
  36. return 1;
  37. }
  38. }
  39. private:
  40. unsigned int id_;
  41. };
  42. #endif // ! FORMULA_VARIABLE_H_