condition.h 949 B

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. //
  2. // condition.hpp
  3. // pokemon-engine
  4. //
  5. // Created by Sam Jaffe on 7/6/22.
  6. // Copyright © 2022 Sam Jaffe. All rights reserved.
  7. //
  8. #pragma once
  9. #include <functional>
  10. #include <string>
  11. #include <vector>
  12. #include <reflection/forward.h>
  13. #include <reflection/property.h>
  14. #include <engine/forwards.h>
  15. namespace engine {
  16. class Condition {
  17. public:
  18. using Predicate = std::function<bool(engine::Event const &)>;
  19. enum class Comparator { NOT_EQUAL = 0, EQUAL = 1, LESS = 2, GREATER = 4 };
  20. private:
  21. std::string event_type_;
  22. std::vector<Predicate> predicates_;
  23. public:
  24. Condition() = default;
  25. Condition(std::string event_type, std::vector<Predicate> predicates);
  26. std::string_view event_type() const { return event_type_; }
  27. bool operator()(Event const & on) const;
  28. template <typename T>
  29. static Predicate make_predicate(reflection::Property const & scope,
  30. Comparator cmp, T const & value);
  31. };
  32. }