libcruft-vk/object.hpp

82 lines
2.0 KiB
C++
Raw Normal View History

2016-02-26 13:39:01 +11:00
/*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* Copyright:
* 2016, Danny Robson <danny@nerdcruft.net>
*/
#ifndef CRUFT_VK_OBJECT_HPP
#define CRUFT_VK_OBJECT_HPP
2016-02-24 11:11:41 +11:00
#include "./traits.hpp"
#include "./except.hpp"
#include <utility>
#include <vector>
2016-02-24 11:11:41 +11:00
namespace cruft::vk {
2016-02-24 11:11:41 +11:00
template <typename T>
struct object {
using id_t = typename id_traits<T>::id_t;
object (id_t);
object (object&&);
object (const object&) = delete;
2016-02-24 11:11:41 +11:00
const id_t& id (void) const&;
id_t& id (void) &;
2016-02-24 11:11:41 +11:00
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> {
using object<T>::object;
static std::vector<T> find (const instance&);
};
2016-02-24 11:11:41 +11:00
template <typename T, typename O>
struct owned : public object<T> { };
}
#endif