logo

libbulletml

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

bulletmlrunner.cpp (1454B)


  1. #include "bulletmlrunner.h"
  2. #include "bulletmlparser.h"
  3. #include "bulletmlerror.h"
  4. #include "formula-variables.h"
  5. #include "bulletmlrunnerimpl.h"
  6. BulletMLRunner::BulletMLRunner(BulletMLParser* bulletml) {
  7. const std::vector<BulletMLNode*>& acts = bulletml->getTopActions();
  8. for (size_t i = 0; i < acts.size(); i++) {
  9. std::vector<BulletMLNode*> act;
  10. act.push_back(acts[i]);
  11. BulletMLState* state =
  12. new BulletMLState(bulletml, act,
  13. std::shared_ptr<BulletMLParameter>());
  14. impl_.push_back(makeImpl(state));
  15. }
  16. }
  17. BulletMLRunner::BulletMLRunner(BulletMLState* state) {
  18. impl_.push_back(makeImpl(state));
  19. }
  20. BulletMLRunner::~BulletMLRunner() {
  21. for (size_t i = 0; i < impl_.size(); i++) {
  22. delete impl_[i];
  23. }
  24. }
  25. void BulletMLRunner::run() {
  26. /*
  27. std::for_each(impl_.begin(), impl_.end(),
  28. std::mem_fun(&BulletMLRunnerImpl::run));
  29. */
  30. for (std::vector<BulletMLRunnerImpl*>::const_iterator ite = impl_.begin();
  31. ite != impl_.end(); ++ite)
  32. {
  33. (*ite)->run();
  34. }
  35. }
  36. bool BulletMLRunner::isEnd() const {
  37. /*
  38. return
  39. std::find_if(impl_.begin(), impl_.end(),
  40. std::not1(std::mem_fun(&BulletMLRunnerImpl::isEnd)))
  41. == impl_.end();
  42. */
  43. for (std::vector<BulletMLRunnerImpl*>::const_iterator ite = impl_.begin();
  44. ite != impl_.end(); ++ite)
  45. {
  46. if ((*ite)->isEnd()) return true;
  47. }
  48. return false;
  49. }
  50. BulletMLRunnerImpl* BulletMLRunner::makeImpl(BulletMLState* state) {
  51. return new BulletMLRunnerImpl(state, this);
  52. }