prime/include/rstl/construction_deferred.hpp
Luke Street 7ca3a1c0bb Replace int types in Retro code
Retro seemingly avoided using the Dolphin
typedefs in most places, opting to use int/uint
instead. This likely means they didn't use
u8/s8/u16/s16/etc either.


Former-commit-id: 133326ae406a0ebc76f56f8bcb489fda280be2be
2022-10-09 01:37:23 -04:00

38 lines
775 B
C++

#ifndef _RSTL_CONSTRUCTION_DEFERRED
#define _RSTL_CONSTRUCTION_DEFERRED
#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:
uchar x0_data[sizeof(T)];
bool m_valid __attribute__((aligned(4)));
void makeValid() { m_valid = true; }
};
} // namespace rstl
#endif // _RSTL_CONSTRUCTION_DEFERRED