mirror of
https://github.com/BlackMATov/meta.hpp.git
synced 2025-12-16 14:09:02 +07:00
metadata for infos
This commit is contained in:
@@ -13,6 +13,9 @@
|
|||||||
#include "meta_class.hpp"
|
#include "meta_class.hpp"
|
||||||
#include "meta_class_info.hpp"
|
#include "meta_class_info.hpp"
|
||||||
|
|
||||||
|
#include "meta_data.hpp"
|
||||||
|
#include "meta_data_info.hpp"
|
||||||
|
|
||||||
#include "meta_field.hpp"
|
#include "meta_field.hpp"
|
||||||
#include "meta_field_info.hpp"
|
#include "meta_field_info.hpp"
|
||||||
|
|
||||||
|
|||||||
@@ -8,6 +8,12 @@
|
|||||||
|
|
||||||
#include "meta_fwd.hpp"
|
#include "meta_fwd.hpp"
|
||||||
|
|
||||||
|
#include "meta_data.hpp"
|
||||||
|
#include "meta_field.hpp"
|
||||||
|
#include "meta_function.hpp"
|
||||||
|
#include "meta_method.hpp"
|
||||||
|
#include "meta_variable.hpp"
|
||||||
|
|
||||||
#include "meta_class_info.hpp"
|
#include "meta_class_info.hpp"
|
||||||
|
|
||||||
namespace meta_hpp
|
namespace meta_hpp
|
||||||
@@ -37,6 +43,14 @@ namespace meta_hpp
|
|||||||
&class_info::merge_with_);
|
&class_info::merge_with_);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void add_(const data_& internal) {
|
||||||
|
detail::merge_with(
|
||||||
|
info_.datas_,
|
||||||
|
internal.info().id(),
|
||||||
|
internal.info(),
|
||||||
|
&data_info::merge_with_);
|
||||||
|
}
|
||||||
|
|
||||||
template < auto InternalField >
|
template < auto InternalField >
|
||||||
void add_(const field_<InternalField>& internal) {
|
void add_(const field_<InternalField>& internal) {
|
||||||
detail::merge_with(
|
detail::merge_with(
|
||||||
|
|||||||
@@ -7,7 +7,9 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "meta_fwd.hpp"
|
#include "meta_fwd.hpp"
|
||||||
|
#include "meta_value.hpp"
|
||||||
|
|
||||||
|
#include "meta_data_info.hpp"
|
||||||
#include "meta_field_info.hpp"
|
#include "meta_field_info.hpp"
|
||||||
#include "meta_function_info.hpp"
|
#include "meta_function_info.hpp"
|
||||||
#include "meta_method_info.hpp"
|
#include "meta_method_info.hpp"
|
||||||
@@ -27,7 +29,7 @@ namespace meta_hpp
|
|||||||
|
|
||||||
class_info(std::string id)
|
class_info(std::string id)
|
||||||
: id_(std::move(id)) {}
|
: id_(std::move(id)) {}
|
||||||
|
public:
|
||||||
const std::string& id() const noexcept {
|
const std::string& id() const noexcept {
|
||||||
return id_;
|
return id_;
|
||||||
}
|
}
|
||||||
@@ -36,6 +38,10 @@ namespace meta_hpp
|
|||||||
return detail::find_opt(classes_, id);
|
return detail::find_opt(classes_, id);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::optional<data_info> get_data(std::string_view id) const {
|
||||||
|
return detail::find_opt(datas_, id);
|
||||||
|
}
|
||||||
|
|
||||||
std::optional<field_info> get_field(std::string_view id) const {
|
std::optional<field_info> get_field(std::string_view id) const {
|
||||||
return detail::find_opt(fields_, id);
|
return detail::find_opt(fields_, id);
|
||||||
}
|
}
|
||||||
@@ -53,11 +59,13 @@ namespace meta_hpp
|
|||||||
}
|
}
|
||||||
private:
|
private:
|
||||||
friend class namespace_info;
|
friend class namespace_info;
|
||||||
|
|
||||||
template < typename Class > friend class class_;
|
template < typename Class > friend class class_;
|
||||||
friend class namespace_;
|
friend class namespace_;
|
||||||
private:
|
private:
|
||||||
void merge_with_(const class_info& other) {
|
void merge_with_(const class_info& other) {
|
||||||
detail::merge_with(classes_, other.classes_, &class_info::merge_with_);
|
detail::merge_with(classes_, other.classes_, &class_info::merge_with_);
|
||||||
|
detail::merge_with(datas_, other.datas_, &data_info::merge_with_);
|
||||||
detail::merge_with(fields_, other.fields_, &field_info::merge_with_);
|
detail::merge_with(fields_, other.fields_, &field_info::merge_with_);
|
||||||
detail::merge_with(functions_, other.functions_, &function_info::merge_with_);
|
detail::merge_with(functions_, other.functions_, &function_info::merge_with_);
|
||||||
detail::merge_with(methods_, other.methods_, &method_info::merge_with_);
|
detail::merge_with(methods_, other.methods_, &method_info::merge_with_);
|
||||||
@@ -66,6 +74,7 @@ namespace meta_hpp
|
|||||||
private:
|
private:
|
||||||
std::string id_;
|
std::string id_;
|
||||||
std::map<std::string, class_info, std::less<>> classes_;
|
std::map<std::string, class_info, std::less<>> classes_;
|
||||||
|
std::map<std::string, data_info, std::less<>> datas_;
|
||||||
std::map<std::string, field_info, std::less<>> fields_;
|
std::map<std::string, field_info, std::less<>> fields_;
|
||||||
std::map<std::string, function_info, std::less<>> functions_;
|
std::map<std::string, function_info, std::less<>> functions_;
|
||||||
std::map<std::string, method_info, std::less<>> methods_;
|
std::map<std::string, method_info, std::less<>> methods_;
|
||||||
|
|||||||
40
headers/meta.hpp/meta_data.hpp
Normal file
40
headers/meta.hpp/meta_data.hpp
Normal file
@@ -0,0 +1,40 @@
|
|||||||
|
/*******************************************************************************
|
||||||
|
* 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_data_info.hpp"
|
||||||
|
|
||||||
|
namespace meta_hpp
|
||||||
|
{
|
||||||
|
class data_ {
|
||||||
|
public:
|
||||||
|
explicit data_(std::string id, value value)
|
||||||
|
: info_(std::move(id), std::move(value)) {}
|
||||||
|
|
||||||
|
const data_info& info() const noexcept {
|
||||||
|
return info_;
|
||||||
|
}
|
||||||
|
|
||||||
|
template < typename... Internals >
|
||||||
|
data_& operator()(Internals&&...internals) {
|
||||||
|
(add_(std::forward<Internals>(internals)), ...);
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
private:
|
||||||
|
void add_(const data_& internal) {
|
||||||
|
detail::merge_with(
|
||||||
|
info_.datas_,
|
||||||
|
internal.info().id(),
|
||||||
|
internal.info(),
|
||||||
|
&data_info::merge_with_);
|
||||||
|
}
|
||||||
|
private:
|
||||||
|
data_info info_;
|
||||||
|
};
|
||||||
|
}
|
||||||
65
headers/meta.hpp/meta_data_info.hpp
Normal file
65
headers/meta.hpp/meta_data_info.hpp
Normal file
@@ -0,0 +1,65 @@
|
|||||||
|
/*******************************************************************************
|
||||||
|
* 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 data_info {
|
||||||
|
public:
|
||||||
|
data_info() = delete;
|
||||||
|
|
||||||
|
data_info(data_info&&) = default;
|
||||||
|
data_info(const data_info&) = default;
|
||||||
|
|
||||||
|
data_info& operator=(data_info&&) = default;
|
||||||
|
data_info& operator=(const data_info&) = default;
|
||||||
|
|
||||||
|
data_info(std::string id, value value)
|
||||||
|
: id_(std::move(id))
|
||||||
|
, value_(std::move(value)) {}
|
||||||
|
public:
|
||||||
|
const std::string& id() const noexcept {
|
||||||
|
return id_;
|
||||||
|
}
|
||||||
|
|
||||||
|
const value& get() const noexcept {
|
||||||
|
return value_;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::optional<data_info> get_data(std::string_view id) const {
|
||||||
|
return detail::find_opt(datas_, id);
|
||||||
|
}
|
||||||
|
private:
|
||||||
|
friend class class_info;
|
||||||
|
friend class field_info;
|
||||||
|
friend class function_info;
|
||||||
|
friend class method_info;
|
||||||
|
friend class namespace_info;
|
||||||
|
friend class variable_info;
|
||||||
|
|
||||||
|
template < typename Class > friend class class_;
|
||||||
|
template < auto Field > friend class field_;
|
||||||
|
template < auto Function > friend class function_;
|
||||||
|
template < auto Method > friend class method_;
|
||||||
|
friend class namespace_;
|
||||||
|
template < auto Variable > friend class variable_;
|
||||||
|
|
||||||
|
friend class data_;
|
||||||
|
private:
|
||||||
|
void merge_with_(const data_info& other) {
|
||||||
|
value_ = other.value_;
|
||||||
|
detail::merge_with(datas_, other.datas_, &data_info::merge_with_);
|
||||||
|
}
|
||||||
|
private:
|
||||||
|
std::string id_;
|
||||||
|
value value_;
|
||||||
|
std::map<std::string, data_info, std::less<>> datas_;
|
||||||
|
};
|
||||||
|
}
|
||||||
@@ -8,6 +8,8 @@
|
|||||||
|
|
||||||
#include "meta_fwd.hpp"
|
#include "meta_fwd.hpp"
|
||||||
|
|
||||||
|
#include "meta_data.hpp"
|
||||||
|
|
||||||
#include "meta_field_info.hpp"
|
#include "meta_field_info.hpp"
|
||||||
|
|
||||||
namespace meta_hpp
|
namespace meta_hpp
|
||||||
@@ -26,6 +28,20 @@ namespace meta_hpp
|
|||||||
const field_info& info() const noexcept {
|
const field_info& info() const noexcept {
|
||||||
return info_;
|
return info_;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template < typename... Internals >
|
||||||
|
field_& operator()(Internals&&...internals) {
|
||||||
|
(add_(std::forward<Internals>(internals)), ...);
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
private:
|
||||||
|
void add_(const data_& internal) {
|
||||||
|
detail::merge_with(
|
||||||
|
info_.datas_,
|
||||||
|
internal.info().id(),
|
||||||
|
internal.info(),
|
||||||
|
&data_info::merge_with_);
|
||||||
|
}
|
||||||
private:
|
private:
|
||||||
field_info info_;
|
field_info info_;
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -7,9 +7,10 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "meta_fwd.hpp"
|
#include "meta_fwd.hpp"
|
||||||
|
|
||||||
#include "meta_value.hpp"
|
#include "meta_value.hpp"
|
||||||
|
|
||||||
|
#include "meta_data_info.hpp"
|
||||||
|
|
||||||
namespace meta_hpp::field_detail
|
namespace meta_hpp::field_detail
|
||||||
{
|
{
|
||||||
template < typename Field >
|
template < typename Field >
|
||||||
@@ -69,11 +70,10 @@ namespace meta_hpp
|
|||||||
|
|
||||||
field_info(std::string id)
|
field_info(std::string id)
|
||||||
: id_(std::move(id)) {}
|
: id_(std::move(id)) {}
|
||||||
|
public:
|
||||||
const std::string& id() const noexcept {
|
const std::string& id() const noexcept {
|
||||||
return id_;
|
return id_;
|
||||||
}
|
}
|
||||||
public:
|
|
||||||
value get(const void* instance) const {
|
value get(const void* instance) const {
|
||||||
return getter_(instance);
|
return getter_(instance);
|
||||||
}
|
}
|
||||||
@@ -82,17 +82,25 @@ namespace meta_hpp
|
|||||||
void set(void* instance, Value&& value) const {
|
void set(void* instance, Value&& value) const {
|
||||||
return setter_(instance, std::forward<Value>(value));
|
return setter_(instance, std::forward<Value>(value));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::optional<data_info> get_data(std::string_view id) const {
|
||||||
|
return detail::find_opt(datas_, id);
|
||||||
|
}
|
||||||
private:
|
private:
|
||||||
friend class class_info;
|
friend class class_info;
|
||||||
|
|
||||||
template < typename Class > friend class class_;
|
template < typename Class > friend class class_;
|
||||||
template < auto Field > friend class field_;
|
template < auto Field > friend class field_;
|
||||||
private:
|
private:
|
||||||
void merge_with_(const field_info& other) {
|
void merge_with_(const field_info& other) {
|
||||||
(void)other;
|
getter_ = other.getter_;
|
||||||
|
setter_ = other.setter_;
|
||||||
|
detail::merge_with(datas_, other.datas_, &data_info::merge_with_);
|
||||||
}
|
}
|
||||||
private:
|
private:
|
||||||
std::string id_;
|
std::string id_;
|
||||||
value(*getter_)(const void*);
|
value(*getter_)(const void*);
|
||||||
void(*setter_)(void*, value);
|
void(*setter_)(void*, value);
|
||||||
|
std::map<std::string, data_info, std::less<>> datas_;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,6 +8,8 @@
|
|||||||
|
|
||||||
#include "meta_fwd.hpp"
|
#include "meta_fwd.hpp"
|
||||||
|
|
||||||
|
#include "meta_data.hpp"
|
||||||
|
|
||||||
#include "meta_function_info.hpp"
|
#include "meta_function_info.hpp"
|
||||||
|
|
||||||
namespace meta_hpp
|
namespace meta_hpp
|
||||||
@@ -25,6 +27,20 @@ namespace meta_hpp
|
|||||||
const function_info& info() const noexcept {
|
const function_info& info() const noexcept {
|
||||||
return info_;
|
return info_;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template < typename... Internals >
|
||||||
|
function_& operator()(Internals&&...internals) {
|
||||||
|
(add_(std::forward<Internals>(internals)), ...);
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
private:
|
||||||
|
void add_(const data_& internal) {
|
||||||
|
detail::merge_with(
|
||||||
|
info_.datas_,
|
||||||
|
internal.info().id(),
|
||||||
|
internal.info(),
|
||||||
|
&data_info::merge_with_);
|
||||||
|
}
|
||||||
private:
|
private:
|
||||||
function_info info_;
|
function_info info_;
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -7,9 +7,10 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "meta_fwd.hpp"
|
#include "meta_fwd.hpp"
|
||||||
|
|
||||||
#include "meta_value.hpp"
|
#include "meta_value.hpp"
|
||||||
|
|
||||||
|
#include "meta_data_info.hpp"
|
||||||
|
|
||||||
namespace meta_hpp::function_detail
|
namespace meta_hpp::function_detail
|
||||||
{
|
{
|
||||||
template < typename Function >
|
template < typename Function >
|
||||||
@@ -76,16 +77,20 @@ namespace meta_hpp
|
|||||||
|
|
||||||
function_info(std::string id)
|
function_info(std::string id)
|
||||||
: id_(std::move(id)) {}
|
: id_(std::move(id)) {}
|
||||||
|
public:
|
||||||
const std::string& id() const noexcept {
|
const std::string& id() const noexcept {
|
||||||
return id_;
|
return id_;
|
||||||
}
|
}
|
||||||
public:
|
|
||||||
template < typename... Args >
|
template < typename... Args >
|
||||||
value invoke(Args&&... args) const {
|
value invoke(Args&&... args) const {
|
||||||
std::array<value, sizeof...(Args)> vargs{{std::forward<Args>(args)...}};
|
std::array<value, sizeof...(Args)> vargs{{std::forward<Args>(args)...}};
|
||||||
return invoke_(vargs.data(), vargs.size());
|
return invoke_(vargs.data(), vargs.size());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::optional<data_info> get_data(std::string_view id) const {
|
||||||
|
return detail::find_opt(datas_, id);
|
||||||
|
}
|
||||||
private:
|
private:
|
||||||
friend class class_info;
|
friend class class_info;
|
||||||
friend class namespace_info;
|
friend class namespace_info;
|
||||||
@@ -96,10 +101,12 @@ namespace meta_hpp
|
|||||||
template < auto Function > friend class function_;
|
template < auto Function > friend class function_;
|
||||||
private:
|
private:
|
||||||
void merge_with_(const function_info& other) {
|
void merge_with_(const function_info& other) {
|
||||||
(void)other;
|
invoke_ = other.invoke_;
|
||||||
|
detail::merge_with(datas_, other.datas_, &data_info::merge_with_);
|
||||||
}
|
}
|
||||||
private:
|
private:
|
||||||
std::string id_;
|
std::string id_;
|
||||||
value(*invoke_)(value*, std::size_t);
|
value(*invoke_)(value*, std::size_t);
|
||||||
|
std::map<std::string, data_info, std::less<>> datas_;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -23,28 +23,20 @@ namespace meta_hpp
|
|||||||
class value;
|
class value;
|
||||||
|
|
||||||
class class_info;
|
class class_info;
|
||||||
|
class data_info;
|
||||||
class field_info;
|
class field_info;
|
||||||
class function_info;
|
class function_info;
|
||||||
class method_info;
|
class method_info;
|
||||||
class namespace_info;
|
class namespace_info;
|
||||||
class variable_info;
|
class variable_info;
|
||||||
|
|
||||||
template < typename Class >
|
template < typename Class > class class_;
|
||||||
class class_;
|
class data_;
|
||||||
|
template < auto Field > class field_;
|
||||||
template < auto Field >
|
template < auto Function > class function_;
|
||||||
class field_;
|
template < auto Method > class method_;
|
||||||
|
|
||||||
template < auto Function >
|
|
||||||
class function_;
|
|
||||||
|
|
||||||
template < auto Method >
|
|
||||||
class method_;
|
|
||||||
|
|
||||||
class namespace_;
|
class namespace_;
|
||||||
|
template < auto Variable > class variable_;
|
||||||
template < auto Variable >
|
|
||||||
class variable_;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
namespace meta_hpp
|
namespace meta_hpp
|
||||||
|
|||||||
@@ -8,6 +8,8 @@
|
|||||||
|
|
||||||
#include "meta_fwd.hpp"
|
#include "meta_fwd.hpp"
|
||||||
|
|
||||||
|
#include "meta_data.hpp"
|
||||||
|
|
||||||
#include "meta_method_info.hpp"
|
#include "meta_method_info.hpp"
|
||||||
|
|
||||||
namespace meta_hpp
|
namespace meta_hpp
|
||||||
@@ -26,6 +28,20 @@ namespace meta_hpp
|
|||||||
const method_info& info() const noexcept {
|
const method_info& info() const noexcept {
|
||||||
return info_;
|
return info_;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template < typename... Internals >
|
||||||
|
method_& operator()(Internals&&...internals) {
|
||||||
|
(add_(std::forward<Internals>(internals)), ...);
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
private:
|
||||||
|
void add_(const data_& internal) {
|
||||||
|
detail::merge_with(
|
||||||
|
info_.datas_,
|
||||||
|
internal.info().id(),
|
||||||
|
internal.info(),
|
||||||
|
&data_info::merge_with_);
|
||||||
|
}
|
||||||
private:
|
private:
|
||||||
method_info info_;
|
method_info info_;
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -7,9 +7,10 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "meta_fwd.hpp"
|
#include "meta_fwd.hpp"
|
||||||
|
|
||||||
#include "meta_value.hpp"
|
#include "meta_value.hpp"
|
||||||
|
|
||||||
|
#include "meta_data_info.hpp"
|
||||||
|
|
||||||
namespace meta_hpp::method_detail
|
namespace meta_hpp::method_detail
|
||||||
{
|
{
|
||||||
template < typename Method >
|
template < typename Method >
|
||||||
@@ -133,11 +134,10 @@ namespace meta_hpp
|
|||||||
|
|
||||||
method_info(std::string id)
|
method_info(std::string id)
|
||||||
: id_(std::move(id)) {}
|
: id_(std::move(id)) {}
|
||||||
|
public:
|
||||||
const std::string& id() const noexcept {
|
const std::string& id() const noexcept {
|
||||||
return id_;
|
return id_;
|
||||||
}
|
}
|
||||||
public:
|
|
||||||
template < typename... Args >
|
template < typename... Args >
|
||||||
value invoke(void* instance, Args&&... args) const {
|
value invoke(void* instance, Args&&... args) const {
|
||||||
std::array<value, sizeof...(Args)> vargs{{std::forward<Args>(args)...}};
|
std::array<value, sizeof...(Args)> vargs{{std::forward<Args>(args)...}};
|
||||||
@@ -149,17 +149,24 @@ namespace meta_hpp
|
|||||||
std::array<value, sizeof...(Args)> vargs{{std::forward<Args>(args)...}};
|
std::array<value, sizeof...(Args)> vargs{{std::forward<Args>(args)...}};
|
||||||
return cinvoke_(instance, vargs.data(), vargs.size());
|
return cinvoke_(instance, vargs.data(), vargs.size());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::optional<data_info> get_data(std::string_view id) const {
|
||||||
|
return detail::find_opt(datas_, id);
|
||||||
|
}
|
||||||
private:
|
private:
|
||||||
friend class class_info;
|
friend class class_info;
|
||||||
template < typename Class > friend class class_;
|
template < typename Class > friend class class_;
|
||||||
template < auto Method > friend class method_;
|
template < auto Method > friend class method_;
|
||||||
private:
|
private:
|
||||||
void merge_with_(const method_info& other) {
|
void merge_with_(const method_info& other) {
|
||||||
(void)other;
|
invoke_ = other.invoke_;
|
||||||
|
cinvoke_ = other.cinvoke_;
|
||||||
|
detail::merge_with(datas_, other.datas_, &data_info::merge_with_);
|
||||||
}
|
}
|
||||||
private:
|
private:
|
||||||
std::string id_;
|
std::string id_;
|
||||||
value(*invoke_)(void*, value*, std::size_t);
|
value(*invoke_)(void*, value*, std::size_t);
|
||||||
value(*cinvoke_)(const void*, value*, std::size_t);
|
value(*cinvoke_)(const void*, value*, std::size_t);
|
||||||
|
std::map<std::string, data_info, std::less<>> datas_;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,6 +8,11 @@
|
|||||||
|
|
||||||
#include "meta_fwd.hpp"
|
#include "meta_fwd.hpp"
|
||||||
|
|
||||||
|
#include "meta_class.hpp"
|
||||||
|
#include "meta_data.hpp"
|
||||||
|
#include "meta_function.hpp"
|
||||||
|
#include "meta_variable.hpp"
|
||||||
|
|
||||||
#include "meta_namespace_info.hpp"
|
#include "meta_namespace_info.hpp"
|
||||||
|
|
||||||
namespace meta_hpp
|
namespace meta_hpp
|
||||||
@@ -36,6 +41,14 @@ namespace meta_hpp
|
|||||||
&class_info::merge_with_);
|
&class_info::merge_with_);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void add_(const data_& internal) {
|
||||||
|
detail::merge_with(
|
||||||
|
info_.datas_,
|
||||||
|
internal.info().id(),
|
||||||
|
internal.info(),
|
||||||
|
&data_info::merge_with_);
|
||||||
|
}
|
||||||
|
|
||||||
template < auto InternalFunction >
|
template < auto InternalFunction >
|
||||||
void add_(const function_<InternalFunction>& internal) {
|
void add_(const function_<InternalFunction>& internal) {
|
||||||
detail::merge_with(
|
detail::merge_with(
|
||||||
@@ -53,8 +66,8 @@ namespace meta_hpp
|
|||||||
&namespace_info::merge_with_);
|
&namespace_info::merge_with_);
|
||||||
}
|
}
|
||||||
|
|
||||||
template < auto Internalvariable >
|
template < auto InternalVariable >
|
||||||
void add_(const variable_<Internalvariable>& internal) {
|
void add_(const variable_<InternalVariable>& internal) {
|
||||||
detail::merge_with(
|
detail::merge_with(
|
||||||
info_.variables_,
|
info_.variables_,
|
||||||
internal.info().id(),
|
internal.info().id(),
|
||||||
|
|||||||
@@ -7,8 +7,10 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "meta_fwd.hpp"
|
#include "meta_fwd.hpp"
|
||||||
|
#include "meta_value.hpp"
|
||||||
|
|
||||||
#include "meta_class_info.hpp"
|
#include "meta_class_info.hpp"
|
||||||
|
#include "meta_data_info.hpp"
|
||||||
#include "meta_function_info.hpp"
|
#include "meta_function_info.hpp"
|
||||||
#include "meta_variable_info.hpp"
|
#include "meta_variable_info.hpp"
|
||||||
|
|
||||||
@@ -26,15 +28,18 @@ namespace meta_hpp
|
|||||||
|
|
||||||
namespace_info(std::string id)
|
namespace_info(std::string id)
|
||||||
: id_(std::move(id)) {}
|
: id_(std::move(id)) {}
|
||||||
|
public:
|
||||||
const std::string& id() const noexcept {
|
const std::string& id() const noexcept {
|
||||||
return id_;
|
return id_;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::optional<class_info> get_class(std::string_view id) const {
|
std::optional<class_info> get_class(std::string_view id) const {
|
||||||
return detail::find_opt(classes_, id);
|
return detail::find_opt(classes_, id);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::optional<data_info> get_data(std::string_view id) const {
|
||||||
|
return detail::find_opt(datas_, id);
|
||||||
|
}
|
||||||
|
|
||||||
std::optional<function_info> get_function(std::string_view id) const {
|
std::optional<function_info> get_function(std::string_view id) const {
|
||||||
return detail::find_opt(functions_, id);
|
return detail::find_opt(functions_, id);
|
||||||
}
|
}
|
||||||
@@ -51,6 +56,7 @@ namespace meta_hpp
|
|||||||
private:
|
private:
|
||||||
void merge_with_(const namespace_info& other) {
|
void merge_with_(const namespace_info& other) {
|
||||||
detail::merge_with(classes_, other.classes_, &class_info::merge_with_);
|
detail::merge_with(classes_, other.classes_, &class_info::merge_with_);
|
||||||
|
detail::merge_with(datas_, other.datas_, &data_info::merge_with_);
|
||||||
detail::merge_with(functions_, other.functions_, &function_info::merge_with_);
|
detail::merge_with(functions_, other.functions_, &function_info::merge_with_);
|
||||||
detail::merge_with(namespaces_, other.namespaces_, &namespace_info::merge_with_);
|
detail::merge_with(namespaces_, other.namespaces_, &namespace_info::merge_with_);
|
||||||
detail::merge_with(variables_, other.variables_, &variable_info::merge_with_);
|
detail::merge_with(variables_, other.variables_, &variable_info::merge_with_);
|
||||||
@@ -58,6 +64,7 @@ namespace meta_hpp
|
|||||||
private:
|
private:
|
||||||
std::string id_;
|
std::string id_;
|
||||||
std::map<std::string, class_info, std::less<>> classes_;
|
std::map<std::string, class_info, std::less<>> classes_;
|
||||||
|
std::map<std::string, data_info, std::less<>> datas_;
|
||||||
std::map<std::string, function_info, std::less<>> functions_;
|
std::map<std::string, function_info, std::less<>> functions_;
|
||||||
std::map<std::string, namespace_info, std::less<>> namespaces_;
|
std::map<std::string, namespace_info, std::less<>> namespaces_;
|
||||||
std::map<std::string, variable_info, std::less<>> variables_;
|
std::map<std::string, variable_info, std::less<>> variables_;
|
||||||
|
|||||||
@@ -8,6 +8,8 @@
|
|||||||
|
|
||||||
#include "meta_fwd.hpp"
|
#include "meta_fwd.hpp"
|
||||||
|
|
||||||
|
#include "meta_data.hpp"
|
||||||
|
|
||||||
#include "meta_variable_info.hpp"
|
#include "meta_variable_info.hpp"
|
||||||
|
|
||||||
namespace meta_hpp
|
namespace meta_hpp
|
||||||
@@ -24,6 +26,20 @@ namespace meta_hpp
|
|||||||
const variable_info& info() const noexcept {
|
const variable_info& info() const noexcept {
|
||||||
return info_;
|
return info_;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template < typename... Internals >
|
||||||
|
variable_& operator()(Internals&&...internals) {
|
||||||
|
(add_(std::forward<Internals>(internals)), ...);
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
private:
|
||||||
|
void add_(const data_& internal) {
|
||||||
|
detail::merge_with(
|
||||||
|
info_.datas_,
|
||||||
|
internal.info().id(),
|
||||||
|
internal.info(),
|
||||||
|
&data_info::merge_with_);
|
||||||
|
}
|
||||||
private:
|
private:
|
||||||
variable_info info_;
|
variable_info info_;
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -7,9 +7,10 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "meta_fwd.hpp"
|
#include "meta_fwd.hpp"
|
||||||
|
|
||||||
#include "meta_value.hpp"
|
#include "meta_value.hpp"
|
||||||
|
|
||||||
|
#include "meta_data_info.hpp"
|
||||||
|
|
||||||
namespace meta_hpp::variable_detail
|
namespace meta_hpp::variable_detail
|
||||||
{
|
{
|
||||||
template < typename Variable >
|
template < typename Variable >
|
||||||
@@ -64,11 +65,10 @@ namespace meta_hpp
|
|||||||
|
|
||||||
variable_info(std::string id)
|
variable_info(std::string id)
|
||||||
: id_(std::move(id)) {}
|
: id_(std::move(id)) {}
|
||||||
|
public:
|
||||||
const std::string& id() const noexcept {
|
const std::string& id() const noexcept {
|
||||||
return id_;
|
return id_;
|
||||||
}
|
}
|
||||||
public:
|
|
||||||
value get() const {
|
value get() const {
|
||||||
return getter_();
|
return getter_();
|
||||||
}
|
}
|
||||||
@@ -77,19 +77,28 @@ namespace meta_hpp
|
|||||||
void set(Value&& value) const {
|
void set(Value&& value) const {
|
||||||
return setter_(std::forward<Value>(value));
|
return setter_(std::forward<Value>(value));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::optional<data_info> get_data(std::string_view id) const {
|
||||||
|
return detail::find_opt(datas_, id);
|
||||||
|
}
|
||||||
private:
|
private:
|
||||||
friend class class_info;
|
friend class class_info;
|
||||||
friend class namespace_info;
|
friend class namespace_info;
|
||||||
|
|
||||||
template < typename Class > friend class class_;
|
template < typename Class > friend class class_;
|
||||||
friend class namespace_;
|
friend class namespace_;
|
||||||
|
|
||||||
template < auto Variable > friend class variable_;
|
template < auto Variable > friend class variable_;
|
||||||
private:
|
private:
|
||||||
void merge_with_(const variable_info& other) {
|
void merge_with_(const variable_info& other) {
|
||||||
(void)other;
|
getter_ = other.getter_;
|
||||||
|
setter_ = other.setter_;
|
||||||
|
detail::merge_with(datas_, other.datas_, &data_info::merge_with_);
|
||||||
}
|
}
|
||||||
private:
|
private:
|
||||||
std::string id_;
|
std::string id_;
|
||||||
value(*getter_)();
|
value(*getter_)();
|
||||||
void(*setter_)(value);
|
void(*setter_)(value);
|
||||||
|
std::map<std::string, data_info, std::less<>> datas_;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -85,35 +85,49 @@ TEST_CASE("meta/examples/ivec3") {
|
|||||||
}
|
}
|
||||||
|
|
||||||
TEST_CASE("meta/examples/simple") {
|
TEST_CASE("meta/examples/simple") {
|
||||||
namespace meta = meta_hpp;
|
using namespace meta_hpp;
|
||||||
|
|
||||||
meta::namespace_info vmath_info = meta::namespace_("vmath")(
|
namespace_info vmath_info = namespace_("vmath")(
|
||||||
meta::class_<ivec2>("ivec2")(
|
class_<ivec2>("ivec2")(
|
||||||
meta::field_<&ivec2::x>("x"),
|
field_<&ivec2::x>("x")(
|
||||||
meta::field_<&ivec2::y>("y"),
|
data_("tooltip", "x-coordinate field")
|
||||||
meta::method_<&ivec2::dot>("dot"),
|
|
||||||
meta::method_<&ivec2::length2>("length2")
|
|
||||||
),
|
),
|
||||||
meta::class_<ivec3>("ivec3")(
|
field_<&ivec2::y>("y")(
|
||||||
meta::field_<&ivec3::x>("x"),
|
data_("tooltip", "y-coordinate field")
|
||||||
meta::field_<&ivec3::y>("y"),
|
|
||||||
meta::field_<&ivec3::z>("z"),
|
|
||||||
meta::method_<&ivec3::dot>("dot"),
|
|
||||||
meta::method_<&ivec3::length2>("length2")
|
|
||||||
),
|
),
|
||||||
meta::function_<meta::select<ivec2(ivec2,ivec2)>(&add)>("iadd2"),
|
method_<&ivec2::dot>("dot"),
|
||||||
meta::function_<meta::select<ivec3(ivec3,ivec3)>(&add)>("iadd3")
|
method_<&ivec2::length2>("length2")
|
||||||
|
),
|
||||||
|
class_<ivec3>("ivec3")(
|
||||||
|
field_<&ivec3::x>("x")(
|
||||||
|
data_("tooltip", "x-coordinate field")
|
||||||
|
),
|
||||||
|
field_<&ivec3::y>("y")(
|
||||||
|
data_("tooltip", "y-coordinate field")
|
||||||
|
),
|
||||||
|
field_<&ivec3::z>("z")(
|
||||||
|
data_("tooltip", "z-coordinate field")
|
||||||
|
),
|
||||||
|
method_<&ivec3::dot>("dot"),
|
||||||
|
method_<&ivec3::length2>("length2")
|
||||||
|
),
|
||||||
|
function_<select<ivec2(ivec2,ivec2)>(&add)>("iadd2"),
|
||||||
|
function_<select<ivec3(ivec3,ivec3)>(&add)>("iadd3")
|
||||||
).info();
|
).info();
|
||||||
|
|
||||||
meta::class_info ivec2_info = vmath_info.get_class("ivec2").value();
|
class_info ivec2_info = vmath_info.get_class("ivec2").value();
|
||||||
meta::field_info ivec2_x_info = ivec2_info.get_field("x").value();
|
|
||||||
meta::field_info ivec2_y_info = ivec2_info.get_field("y").value();
|
|
||||||
|
|
||||||
meta::method_info ivec2_dot_info = ivec2_info.get_method("dot").value();
|
field_info ivec2_x_info = ivec2_info.get_field("x").value();
|
||||||
meta::method_info ivec2_length2_info = ivec2_info.get_method("length2").value();
|
field_info ivec2_y_info = ivec2_info.get_field("y").value();
|
||||||
|
|
||||||
meta::function_info iadd2_info = vmath_info.get_function("iadd2").value();
|
data_info ivec2_x_tooltip_info = ivec2_x_info.get_data("tooltip").value();
|
||||||
meta::function_info iadd3_info = vmath_info.get_function("iadd3").value();
|
data_info ivec2_y_tooltip_info = ivec2_y_info.get_data("tooltip").value();
|
||||||
|
|
||||||
|
method_info ivec2_dot_info = ivec2_info.get_method("dot").value();
|
||||||
|
method_info ivec2_length2_info = ivec2_info.get_method("length2").value();
|
||||||
|
|
||||||
|
function_info iadd2_info = vmath_info.get_function("iadd2").value();
|
||||||
|
function_info iadd3_info = vmath_info.get_function("iadd3").value();
|
||||||
|
|
||||||
{
|
{
|
||||||
ivec2 v2{1,2};
|
ivec2 v2{1,2};
|
||||||
|
|||||||
Reference in New Issue
Block a user