metaforce/Runtime/IVParamObj.hpp

48 lines
1.2 KiB
C++
Raw Normal View History

2018-10-07 03:42:33 +00:00
#pragma once
2015-08-22 01:58:41 +00:00
2015-08-22 02:59:57 +00:00
#include <memory>
#include "Runtime/IObj.hpp"
2015-08-22 01:58:41 +00:00
2018-12-08 05:30:43 +00:00
namespace urde {
2015-08-22 01:58:41 +00:00
2018-12-08 05:30:43 +00:00
class IVParamObj : public IObj {
2015-08-22 01:58:41 +00:00
public:
~IVParamObj() override = default;
2015-08-22 01:58:41 +00:00
};
2018-12-08 05:30:43 +00:00
template <class T>
class TObjOwnerParam : public IVParamObj {
T m_param;
2016-12-23 06:41:39 +00:00
2015-08-22 01:58:41 +00:00
public:
2018-12-08 05:30:43 +00:00
TObjOwnerParam(T&& obj) : m_param(std::move(obj)) {}
T& GetParam() noexcept { return m_param; }
const T& GetParam() const noexcept { return m_param; }
2018-12-08 05:30:43 +00:00
};
2015-08-26 01:34:56 +00:00
2018-12-08 05:30:43 +00:00
class CVParamTransfer {
std::shared_ptr<IVParamObj> m_ref;
2015-08-22 01:58:41 +00:00
2018-12-08 05:30:43 +00:00
public:
constexpr CVParamTransfer() noexcept = default;
2018-12-08 05:30:43 +00:00
CVParamTransfer(IVParamObj* obj) : m_ref(obj) {}
CVParamTransfer(const CVParamTransfer& other) noexcept = default;
CVParamTransfer& operator=(const CVParamTransfer&) noexcept = default;
CVParamTransfer(CVParamTransfer&&) noexcept = default;
CVParamTransfer& operator=(CVParamTransfer&&) noexcept = default;
IVParamObj* GetObj() const noexcept { return m_ref.get(); }
CVParamTransfer ShareTransferRef() const noexcept { return CVParamTransfer(*this); }
2018-12-08 05:30:43 +00:00
template <class T>
T& GetOwnedObj() const noexcept {
2018-12-08 05:30:43 +00:00
return static_cast<TObjOwnerParam<T>*>(GetObj())->GetParam();
}
static CVParamTransfer Null() noexcept { return CVParamTransfer(); }
2015-08-22 01:58:41 +00:00
};
2018-12-08 05:30:43 +00:00
} // namespace urde