62 lines
1.5 KiB
C++
62 lines
1.5 KiB
C++
#pragma once
|
|
#ifndef META_RUNTIME_REFLECTION_H
|
|
#define META_RUNTIME_REFLECTION_H
|
|
#include <atomic>
|
|
#include <functional>
|
|
#include <sled/any.h>
|
|
#include <string>
|
|
#include <typeindex>
|
|
#include <vector>
|
|
|
|
namespace meta {
|
|
#define __REFLECTION_PARSER_
|
|
#if defined(__REFLECTION_PARSER_)
|
|
#define CLASS(class_name, ...) \
|
|
class __attribute__((annotate(#__VA_ARGS__))) class_name
|
|
#define STRUCT(struct_name, ...) \
|
|
struct __attribute__((annotate(#__VA_ARGS__))) struct_name
|
|
#else
|
|
#define META(...)
|
|
#define CLASS(class_name, ...) class class_name
|
|
#define STRUCT(struct_name, ...) struct struct_name
|
|
#endif// __REFLECTION_PARSER_
|
|
|
|
#define REFLECTION_BODY(class_name)
|
|
|
|
#define REFLECT_TYPE(class_name)
|
|
|
|
class TypeInterface {
|
|
public:
|
|
virtual std::string name() const = 0;
|
|
};
|
|
|
|
class Class;
|
|
|
|
class Method : public TypeInterface {
|
|
public:
|
|
virtual std::string name() = 0;
|
|
|
|
template<typename ReturnT, typename... Args>
|
|
ReturnT Invoke(void *instance, Args... args) const
|
|
{
|
|
std::vector<sled::any> arguments = {args...};
|
|
return sled::any_cast<ReturnT>(
|
|
std::forward<sled::any>(Invoke(instance, arguments)));
|
|
}
|
|
|
|
sled::any Invoke(void *instance, std::vector<sled::any> &args) const
|
|
{
|
|
return InvokeImpl(instance, args);
|
|
}
|
|
|
|
protected:
|
|
virtual sled::any InvokeImpl(void *instance,
|
|
std::vector<sled::any> &args) const = 0;
|
|
};
|
|
|
|
class Field;
|
|
|
|
}// namespace meta
|
|
|
|
#endif// META_RUNTIME_REFLECTION_H
|