Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Update README.md
  • Loading branch information
Zal0 committed Jan 2, 2020
1 parent f0c3f8f commit 584fafd
Showing 1 changed file with 30 additions and 0 deletions.
30 changes: 30 additions & 0 deletions README.md
Expand Up @@ -38,3 +38,33 @@ public:
#include "ReflectDecl.h"
};
```

##Acccessing fields using reflection
Given the class A initialized like this
```cpp
A a;
a.a_int = 1;
```
Use the ReflectField class to access fields using reflection
```cpp
ReflectField a_field = a.Get("a_int");
```
You can then get or set the values using the methods Get and Set
```cpp
int a_int = a_field.Get< int >(); //a_int == 1
a_field.Set(2); //a.aint == 2
```
Some extra info from the field can be extracted using the Reflectfield class like the field name
```cpp
const char* id = a_field.infos->id; //id == "a_int"
```
the field type
```cpp
Reflectpp::Type type = a_field.GetTypeReflectInfo()->reflect_type; //type == REFLECT_TYPE_INT
```
or the field size
```cpp
unsigned int size = a_field.GetTypeReflectInfo()->size; //size == sizeof(int)
```
There are also some helper functions that makes it easier to retrieve the data depending on the field type

0 comments on commit 584fafd

Please sign in to comment.