CreatureLib/src/Battling/ScriptHandling/ScriptWrapper.hpp

40 lines
1.3 KiB
C++

#ifndef CREATURELIB_SCRIPTWRAPPER_HPP
#define CREATURELIB_SCRIPTWRAPPER_HPP
#include "BattleScript.hpp"
#include "ScriptSet.hpp"
namespace CreatureLib::Battling {
class ScriptWrapper {
bool _isSet;
union {
ArbUt::OptionalUniquePtr<BattleScript> const* nullable _script;
const ScriptSet* nullable _scriptSet;
};
ScriptWrapper(ArbUt::OptionalUniquePtr<BattleScript>* nullable s, bool isSet) : _isSet(isSet), _script(s){};
ScriptWrapper(ScriptSet* nullable s, bool isSet) : _isSet(isSet), _scriptSet(s){};
public:
static inline ScriptWrapper FromScript(ArbUt::OptionalUniquePtr<BattleScript>* nullable s) {
return ScriptWrapper(s, false);
}
static inline ScriptWrapper FromSet(ScriptSet* nullable s) { return ScriptWrapper(s, true); }
inline bool IsSet() const noexcept { return _isSet; }
inline const ArbUt::OptionalUniquePtr<BattleScript>* nullable GetScript() const noexcept { return _script; }
inline const ScriptSet* nullable GetScriptSet() const noexcept { return _scriptSet; }
inline bool HasValue() const noexcept {
if (_isSet)
return _scriptSet->Count() > 0;
else
return *_script != nullptr;
}
};
}
#endif // CREATURELIB_SCRIPTWRAPPER_HPP