User friendly cpp rtti engine. Actually work in progress.
classAATest
{
public:AATest() : intValue( 1337 ) {}
AATest( int value ) : intValue( value ) {}
~AATest() {}
intgetInteger() const { return intValue; }
protected:int intValue;
};
REGISTER_TYPE( AATest );
REGISTER_CONSTRUCTOR( AATest, int );
intmain()
{
auto aaTestObj = typeof( AATest ).create();
auto aaTestValue = aaTestObj.getValue<AATest>();
auto value = aaTestValue->getInteger();
// snd wayauto aaTestObj = Type::createObj<AATest>();
auto value = aaTestObj->getInteger();
// non-default constructorauto aaTestObj = Type::createObj<AATest>( 1337 );
auto value = aaTestObj->getInteger();
}
classABTest
{
public:ABTest() {}
intsquare( int x ) const { return x*x; }
voidfoo() const { std::cout << "ABTest::foo()" << std::endl; }
};
intmain()
{
REGISTER_METOD( ABTest, "square", square );
REGISTER_METOD( ABTest, "foo", foo );
auto abType = typeof( ABTest );
auto obj = abType.create( 1.f );
auto method = abType.getMethod( "foo" );
method.invoke( obj, Arguments{} );
method = abType.getMethod( "square" );
auto ret = method.invoke( obj, Arguments{ 5 } );
}classAATest
{
public:AATest() : intValue( 1337 ), floatValue( 1337 ) {}
~AATest() {}
intgetInteger() const { return intValue; }
floatgetFloat() const { return floatValue; }
voidsetInteger(int value) { intValue = value; }
protected:int intValue;
float floatValue;
};
intmain()
{
REGISTER_PROPERTY( AATest, "integer", getInteger, setInteger );
REGISTER_READONLY_PROPERTY( AATest, "float", getFloat );
auto obj = typeof( AATest ).create();
auto aaType = typeof( AATest );
auto field = aaType.getField( "integer" );
auto integerValue = field.getValue( obj );
auto readOnlyField = aaType.getField( "float" );
auto floatValue = readOnlyField.getValue( obj );
}