Created
March 25, 2018 00:00
-
-
Save AustinBrunkhorst/94973cf89c572f6b007a572253a49f70 to your computer and use it in GitHub Desktop.
C++ Reflection | Complete Example
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| struct SoundEffect | |
| { | |
| Meta(Range(0.0f, 100.0f)) | |
| float volume; | |
| }; | |
| int main(void) | |
| { | |
| // you can also use type meta::Type::Get( "SoundEffect" ) based on a string name | |
| Type soundEffectType = typeof( SoundEffect ); | |
| // the volume field in the SoundEffect struct | |
| Field volumeField = soundEffectType.GetField( "volume" ); | |
| // meta data for the volume field | |
| MetaManager &volumeMeta = volumeField.GetMeta( ); | |
| // getting the "Range" property, then casting the variant as a range | |
| Range volumeRange = volumeMeta.GetProperty( typeof( Range ) ).GetValue( ); | |
| // 0.0f | |
| float min = volumeRange.min; | |
| // 100.0f | |
| float max = volumeRange.max; | |
| return 0; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment