2022-08-14 18:38:41 +00:00
|
|
|
#ifndef _RSTL_CONSTRUCTION_DEFERRED_HPP
|
|
|
|
#define _RSTL_CONSTRUCTION_DEFERRED_HPP
|
|
|
|
|
|
|
|
#include "types.h"
|
|
|
|
|
|
|
|
#include "rstl/construct.hpp"
|
|
|
|
|
|
|
|
namespace rstl {
|
|
|
|
template < typename T >
|
|
|
|
class construction_deferred {
|
|
|
|
public:
|
|
|
|
construction_deferred() : m_valid(false) {}
|
|
|
|
|
|
|
|
template < typename A >
|
|
|
|
void build(const A& arg) {
|
|
|
|
rstl::construct(get_ptr(), arg);
|
|
|
|
makeValid();
|
|
|
|
}
|
|
|
|
void clear(); // TODO
|
|
|
|
bool valid() const { return m_valid; }
|
|
|
|
|
|
|
|
T* get_ptr() { return reinterpret_cast< T* >(x0_data); }
|
|
|
|
T& data() {
|
|
|
|
// TODO ensureIsValid
|
|
|
|
return *get_ptr();
|
|
|
|
}
|
|
|
|
T& operator*() { return data(); }
|
|
|
|
|
|
|
|
private:
|
|
|
|
u8 x0_data[sizeof(T)];
|
|
|
|
bool m_valid __attribute__((aligned(4)));
|
|
|
|
|
|
|
|
void makeValid() { m_valid = true; }
|
|
|
|
};
|
|
|
|
} // namespace rstl
|
|
|
|
|
2022-09-18 06:05:46 +00:00
|
|
|
#endif
|