mirror of
https://github.com/BlackMATov/meta.hpp.git
synced 2025-12-16 14:09:02 +07:00
100 lines
2.5 KiB
C++
100 lines
2.5 KiB
C++
/*******************************************************************************
|
|
* This file is part of the "https://github.com/blackmatov/meta.hpp"
|
|
* For conditions of distribution and use, see copyright notice in LICENSE.md
|
|
* Copyright (C) 2021, by Matvey Cherevko (blackmatov@gmail.com)
|
|
******************************************************************************/
|
|
|
|
#pragma once
|
|
|
|
#include "meta_fwd.hpp"
|
|
|
|
#include "meta_value.hpp"
|
|
|
|
namespace meta_hpp
|
|
{
|
|
class instance;
|
|
class cinstance;
|
|
}
|
|
|
|
namespace meta_hpp
|
|
{
|
|
class instance {
|
|
public:
|
|
instance() = delete;
|
|
|
|
instance(instance&&) = default;
|
|
instance(const instance&) = default;
|
|
|
|
instance& operator=(instance&&) = default;
|
|
instance& operator=(const instance&) = default;
|
|
|
|
template < typename T
|
|
, typename = std::enable_if_t<!std::is_same_v<T, value>>
|
|
, typename = std::enable_if_t<!std::is_same_v<T, instance>>
|
|
, typename = std::enable_if_t<!std::is_same_v<T, cinstance>> >
|
|
instance(T& v)
|
|
: data_{std::addressof(v)}
|
|
, fid_{get_type_family_id<T>()} {}
|
|
|
|
instance(value& v)
|
|
: data_{v.data()}
|
|
, fid_{v.fid()} {}
|
|
|
|
void* data() noexcept {
|
|
return data_;
|
|
}
|
|
|
|
const void* data() const noexcept {
|
|
return data_;
|
|
}
|
|
|
|
family_id fid() const noexcept {
|
|
return fid_;
|
|
}
|
|
private:
|
|
void* data_{};
|
|
family_id fid_{};
|
|
};
|
|
}
|
|
|
|
namespace meta_hpp
|
|
{
|
|
class cinstance {
|
|
public:
|
|
cinstance() = delete;
|
|
|
|
cinstance(cinstance&&) = default;
|
|
cinstance(const cinstance&) = default;
|
|
|
|
cinstance& operator=(cinstance&&) = default;
|
|
cinstance& operator=(const cinstance&) = default;
|
|
|
|
template < typename T
|
|
, typename = std::enable_if_t<!std::is_same_v<T, value>>
|
|
, typename = std::enable_if_t<!std::is_same_v<T, instance>>
|
|
, typename = std::enable_if_t<!std::is_same_v<T, cinstance>> >
|
|
cinstance(const T& data)
|
|
: data_{std::addressof(data)}
|
|
, fid_{get_type_family_id<T>()} {}
|
|
|
|
cinstance(const value& v)
|
|
: data_{v.data()}
|
|
, fid_{v.fid()} {}
|
|
|
|
cinstance(const instance& v)
|
|
: data_{v.data()}
|
|
, fid_{v.fid()} {}
|
|
|
|
const void* data() const noexcept {
|
|
return data_;
|
|
}
|
|
|
|
family_id fid() const noexcept {
|
|
return fid_;
|
|
}
|
|
private:
|
|
const void* data_{};
|
|
family_id fid_{};
|
|
};
|
|
}
|