📄 test_reflection.cpp
字号:
#include "reflection.hpp"
/*****************************************************************************
MAIN
*****************************************************************************/
#include <list>
#include <string>
#include <iostream>
using namespace std;
using namespace agm::reflection;
void print_class(const Class &pclass)
{
cout << "class name = " << pclass.getName() << endl;
cout << "superclass = ";
if (pclass.hasSuper()) cout << pclass.getSuper().getName();
else cout << "none";
cout << endl;
cout << "fields:\n";
for(Class::FieldList::const_iterator itField = pclass.getFields().begin();
itField != pclass.getFields().end();
++itField)
{
const Field &field = *itField;
cout << " " << field.getAccess() << " " << field.getType() << " " << field.getName() << endl;
}
cout << "static fields:\n";
for(Class::StaticFieldList::const_iterator itStaticField = pclass.getStaticFields().begin();
itStaticField != pclass.getStaticFields().end();
++itStaticField)
{
const StaticField &field = *itStaticField;
cout << " " << field.getAccess() << " " << field.getType() << " " << field.getName() << endl;
}
cout << "methods:\n";
for(Class::MethodList::const_iterator itMethod = pclass.getMethods().begin();
itMethod != pclass.getMethods().end();
++itMethod)
{
const Method &method = *itMethod;
cout << " " << method.getAccess();
if (method.isVirtual()) cout << " " << "virtual";
cout << " " << method.getType() << " " << method.getName() << method.getArgs() << endl;
}
cout << "properties:\n";
for(Class::PropertyList::const_iterator itProperty = pclass.getProperties().begin();
itProperty != pclass.getProperties().end();
++itProperty)
{
const Property &property = *itProperty;
cout << " " << property.getType() << " " << property.getName() << endl;
}
cout << "\n-----------------------------------------------------------\n";
}
class Foo {
public:
CLASS(Foo, NullClass);
PROPERTY(int, length);
METHOD(public, void, action, ()) {
cout << "Foo::action();\n";
}
METHOD(public, void, action1, (int i)) {
cout << "Foo::action1(" << i << ");\n";
}
STATIC_METHOD(public, int, get_code, ()) {
cout << "Foo::get_code();\n";
return 1;
}
STATIC_METHOD(public, int, get_code1, (int i)) {
cout << "Foo::get_code1(" << i << ");\n";
return i + 1;
}
STATIC_METHOD(public, void, print_code, ()) {
cout << "Foo::print_code();\n";
}
STATIC_METHOD(public, void, print_code1, (int i)) {
cout << "Foo::print_code1(" << i << ");\n";
}
Foo() {
m_length = 0;
}
private:
int m_length;
int get_length() const {
cout << "get_length();\n";
return m_length;
}
void set_length(int l) {
cout << "set_length(" << l << ");\n";
m_length = l;
}
};
class Bar {
public:
CLASS(Bar, NullClass);
};
void test_reflection()
{
cout<<"\n反射测试实验......"<<endl;
Foo foo1;
const Class &foo_class = foo1.getClass();
print_class(foo_class);
cout<<endl;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -