#include "{{to_lower(class_name)}}.gen.h" #include /** * Class **/ {{class_namespace}}::{{class_name}}::{{class_name}}_Class::{{class_name}}_Class() : ::meta::reflection::Class("{{class_namespace}}::{{class_name}}", nullptr) { } void {{class_namespace}}::{{class_name}}::{{class_name}}_Class::Register() { auto self = new {{class_namespace}}::{{class_name}}::{{class_name}}_Class(); auto clz = std::shared_ptr<::meta::reflection::Class>(self); // self->AddBaseClassProxy(); {% for method in class_methods %} self->AddMethod(std::make_shared<{{class_namespace}}::{{class_name}}::{{class_name}}_Method>("{{method.name}}", clz)); {% endfor %} {% for field in class_fields %} self->AddField(std::make_shared<{{class_namespace}}::{{class_name}}::{{class_name}}_Field>("{{field.name}}", clz)); {% endfor %} ::meta::reflection::Registry::Instance()->RegisterClass(clz); } void {{class_namespace}}::{{class_name}}::{{class_name}}_Class::AddBaseClassProxy(std::shared_ptr<::meta::reflection::Class> base) { AddBaseClass(base); } void {{class_namespace}}::{{class_name}}::{{class_name}}_Class::AddMethodProxy(std::shared_ptr<::meta::reflection::Method> method) { AddMethod(method); } void {{class_namespace}}::{{class_name}}::{{class_name}}_Class::AddFieldProxy(std::shared_ptr<::meta::reflection::Field> field) { AddField(field); } /** * Field **/ {{class_namespace}}::{{class_name}}::{{class_name}}_Field::{{class_name}}_Field( const std::string& name, std::shared_ptr<::meta::reflection::Class> parent) : ::meta::reflection::Field(name, parent) {} ::meta::reflection::any {{class_namespace}}::{{class_name}}::{{class_name}}_Field::GetImpl(void* instance) const { ::{{class_namespace}}::{{class_name}}* obj = (::{{class_namespace}}::{{class_name}}*)instance; {% for field in class_fields %} if (strcmp(Name().c_str(), "{{field.name}}") == 0) { {% if field.is_static %} return ::{{class_namespace}}::{{class_name}}::{{field.name}}; {% else %} return obj->{{field.name}}; {% endif %} } {% endfor %} return ::meta::reflection::any{}; } void {{class_namespace}}::{{class_name}}::{{class_name}}_Field::SetImpl(void* instance, const ::meta::reflection::any& value) const { ::{{class_namespace}}::{{class_name}}* obj = (::{{class_namespace}}::{{class_name}}*)instance; {% for field in class_fields %} {% if not field.is_const %} if(strcmp(Name().c_str(), "{{field.name}}") == 0) { obj->{{field.name}} = ::meta::reflection::any_cast<{{field.type}}>(value);} {% endif %} {% endfor %} } /** * Method **/ {{class_namespace}}::{{class_name}}::{{class_name}}_Method::{{class_name}}_Method( const std::string& name, std::shared_ptr<::meta::reflection::Class> parent) : ::meta::reflection::Method(name, parent) {} ::meta::reflection::any {{class_namespace}}::{{class_name}}::{{class_name}}_Method::InvokeImpl(void* instance, const std::vector<::meta::reflection::any> ¶ms) const { ::{{class_namespace}}::{{class_name}}* obj = (::{{class_namespace}}::{{class_name}}*)instance; {% for method in class_methods %} if (strcmp(Name().c_str(), "{{method.name}}") == 0) { {% if method.return_type != "void" %} return {% if method.is_static %} ::{{class_namespace}}::{{class_name}}:: {% else %} obj-> {% endif %}{{method.name}}( {% for param in method.params%} ::meta::reflection::any_cast<{{param.type}}>(params[{{loop.index}}]){% if not loop.is_last %}, {% endif %} {% endfor %} ); {% else %} {% if method.is_static %} ::{{class_namespace}}::{{class_name}}:: {% else %} obj-> {%endif%}} {{method.name}}( {% for param in method.params%} ::meta::reflection::any_cast<{{param.type}}>(params[{{loop.index}}]){% if not loop.last %}, {% endif %} {% endfor %} ); return ::meta::reflection::any{}; {% endif %} } {% endfor %} return ::meta::reflection::any{}; }