libcruft-vk/object.hpp

57 lines
1.1 KiB
C++
Raw Normal View History

2016-02-24 11:11:41 +11:00
#ifndef __VK_OBJECT_HPP
#define __VK_OBJECT_HPP
#include "./traits.hpp"
#include "./except.hpp"
#include <utility>
namespace vk {
template <typename T>
struct object {
using id_t = typename id_traits<T>::id_t;
object (id_t);
id_t& id (void) const&;
private:
id_t m_id;
};
template <typename T>
struct instantiated : public object<T> {
using id_t = typename object<T>::id_t;
template <typename ...Args>
instantiated (Args &&...args):
object<T> (make (std::forward<Args> (args)...))
{ ; }
~instantiated ()
{
life_traits<T>::destroy (this->id (), nullptr);
}
private:
template <typename ...Args>
static
id_t make (Args &&...args)
{
id_t id;
auto res = life_traits<T>::create (std::forward<Args> (args)..., &id);
error::try_code (res);
return id;
}
};
template <typename T>
struct enumerated : public object<T> { };
template <typename T, typename O>
struct owned : public object<T> { };
}
#endif