basic type_id

This commit is contained in:
BlackMATov
2021-08-03 10:56:32 +07:00
parent 481a5d5531
commit adb8141d14
13 changed files with 159 additions and 23 deletions

View File

@@ -55,6 +55,9 @@ namespace meta_hpp
namespace meta_hpp
{
class type_id;
class base_type;
class arithmetic_type;
class array_type;
class class_type;
@@ -74,7 +77,7 @@ namespace meta_hpp
using info_map = std::map<K, V, std::less<>>;
using class_info_map = info_map<std::string, class_info>;
using ctor_info_map = info_map<std::string, ctor_info>;
using ctor_info_map = info_map<type_id, ctor_info>;
using data_info_map = info_map<std::string, data_info>;
using enum_info_map = info_map<std::string, enum_info>;
using evalue_info_map = info_map<std::string, evalue_info>;

View File

@@ -0,0 +1,89 @@
/*******************************************************************************
* 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"
namespace meta_hpp
{
class type_id final {
public:
type_id() = delete;
type_id(type_id&&) = default;
type_id& operator=(type_id&&) = default;
type_id(const type_id&) = default;
type_id& operator=(const type_id&) = default;
std::size_t hash() const noexcept {
return std::hash<underlying_type>{}(id_);
}
friend bool operator<(type_id l, type_id r) noexcept {
return l.id_ < r.id_;
}
friend bool operator==(type_id l, type_id r) noexcept {
return l.id_ == r.id_;
}
friend bool operator!=(type_id l, type_id r) noexcept {
return l.id_ != r.id_;
}
private:
using underlying_type = std::size_t;
underlying_type id_{0u};
private:
template < typename T >
friend type_id make_type_id() noexcept;
template < typename T >
explicit type_id(typename_arg_t<T>) noexcept
: id_{next()} {}
static underlying_type next() noexcept {
static std::atomic<underlying_type> id{};
return ++id;
}
};
template < typename T >
type_id make_type_id() noexcept {
static const type_id id = type_id{typename_arg<T>};
return id;
}
}
namespace std
{
template <>
struct hash<meta_hpp::type_id> {
size_t operator()(meta_hpp::type_id id) const noexcept {
return id.hash();
}
};
}
namespace meta_hpp
{
class base_type {
public:
template < typename... Ts >
struct tag {};
public:
template < typename... Ts >
explicit base_type(typename_arg_t<Ts...>)
: id_{make_type_id<tag<Ts...>>()} {}
type_id id() const noexcept {
return id_;
}
private:
type_id id_;
};
}

View File

@@ -6,10 +6,14 @@
#pragma once
#include "../meta_fwd.hpp"
#include "_types_fwd.hpp"
namespace meta_hpp
{
class arithmetic_type final {
class arithmetic_type final : public base_type {
public:
template < typename T >
explicit arithmetic_type(typename_arg_t<T>)
: base_type{typename_arg<T>} {}
};
}

View File

@@ -6,10 +6,14 @@
#pragma once
#include "../meta_fwd.hpp"
#include "_types_fwd.hpp"
namespace meta_hpp
{
class array_type final {
class array_type final : public base_type {
public:
template < typename T >
explicit array_type(typename_arg_t<T>)
: base_type{typename_arg<T>} {}
};
}

View File

@@ -6,10 +6,14 @@
#pragma once
#include "../meta_fwd.hpp"
#include "_types_fwd.hpp"
namespace meta_hpp
{
class class_type final {
class class_type final : public base_type {
public:
template < typename T >
explicit class_type(typename_arg_t<T>)
: base_type{typename_arg<T>} {}
};
}

View File

@@ -6,10 +6,14 @@
#pragma once
#include "../meta_fwd.hpp"
#include "_types_fwd.hpp"
namespace meta_hpp
{
class ctor_type final {
class ctor_type final : public base_type {
public:
template < typename Class, typename... Args >
explicit ctor_type(typename_arg_t<Class>, typename_arg_t<Args...>)
: base_type{typename_arg<Class, Args...>} {}
};
}

View File

@@ -6,10 +6,14 @@
#pragma once
#include "../meta_fwd.hpp"
#include "_types_fwd.hpp"
namespace meta_hpp
{
class enum_type final {
class enum_type final : public base_type {
public:
template < typename T >
explicit enum_type(typename_arg_t<T>)
: base_type{typename_arg<T>} {}
};
}

View File

@@ -6,10 +6,14 @@
#pragma once
#include "../meta_fwd.hpp"
#include "_types_fwd.hpp"
namespace meta_hpp
{
class function_type final {
class function_type final : public base_type {
public:
template < typename T >
explicit function_type(typename_arg_t<T>)
: base_type{typename_arg<T>} {}
};
}

View File

@@ -6,10 +6,14 @@
#pragma once
#include "../meta_fwd.hpp"
#include "_types_fwd.hpp"
namespace meta_hpp
{
class member_type final {
class member_type final : public base_type {
public:
template < typename T >
explicit member_type(typename_arg_t<T>)
: base_type{typename_arg<T>} {}
};
}

View File

@@ -6,10 +6,14 @@
#pragma once
#include "../meta_fwd.hpp"
#include "_types_fwd.hpp"
namespace meta_hpp
{
class method_type final {
class method_type final : public base_type {
public:
template < typename T >
explicit method_type(typename_arg_t<T>)
: base_type{typename_arg<T>} {}
};
}

View File

@@ -6,10 +6,14 @@
#pragma once
#include "../meta_fwd.hpp"
#include "_types_fwd.hpp"
namespace meta_hpp
{
class pointer_type final {
class pointer_type final : public base_type {
public:
template < typename T >
explicit pointer_type(typename_arg_t<T>)
: base_type{typename_arg<T>} {}
};
}

View File

@@ -6,10 +6,14 @@
#pragma once
#include "../meta_fwd.hpp"
#include "_types_fwd.hpp"
namespace meta_hpp
{
class reference_type final {
class reference_type final : public base_type {
public:
template < typename T >
explicit reference_type(typename_arg_t<T>)
: base_type{typename_arg<T>} {}
};
}

View File

@@ -6,10 +6,14 @@
#pragma once
#include "../meta_fwd.hpp"
#include "_types_fwd.hpp"
namespace meta_hpp
{
class void_type final {
class void_type final : public base_type {
public:
template < typename T >
explicit void_type(typename_arg_t<T>)
: base_type{typename_arg<T>} {}
};
}