42 lines
1.3 KiB
C++
42 lines
1.3 KiB
C++
#ifndef CREATURELIB_HISTORYHOLDER_HPP
|
|
#define CREATURELIB_HISTORYHOLDER_HPP
|
|
|
|
#include "../../Library/Exceptions/CreatureException.hpp"
|
|
#include "HistoryElements/HistoryElement.hpp"
|
|
|
|
template <class T>
|
|
concept HistoryElementType = std::is_base_of<CreatureLib::Battling::HistoryElement, T>::value;
|
|
|
|
namespace CreatureLib::Battling {
|
|
class HistoryHolder {
|
|
HistoryElement* _top = nullptr;
|
|
|
|
public:
|
|
HistoryHolder() {}
|
|
HistoryHolder(const HistoryHolder&) = delete;
|
|
HistoryHolder& operator=(const HistoryHolder&) = delete;
|
|
|
|
virtual ~HistoryHolder() { delete _top; }
|
|
|
|
template <HistoryElementType T, class... parameters> void Register(parameters... args) {
|
|
auto* prev = _top;
|
|
_top = new T(args...);
|
|
_top->SetPrevious(prev);
|
|
}
|
|
|
|
[[nodiscard]] ArbUt::OptionalBorrowedPtr<const HistoryElement> GetTopElement() const noexcept { return _top; }
|
|
|
|
ArbUt::OptionalBorrowedPtr<const HistoryElement> GetLastUsedAttack() const noexcept {
|
|
const auto* c = _top;
|
|
while (c != nullptr) {
|
|
if (c->GetKind() == HistoryElementKind::AttackUse)
|
|
return c;
|
|
c = c->GetPrevious();
|
|
}
|
|
return {};
|
|
}
|
|
};
|
|
}
|
|
|
|
#endif // CREATURELIB_HISTORYHOLDER_HPP
|