Skip to content

Instantly share code, notes, and snippets.

@AustinBrunkhorst
Created March 25, 2018 00:00
Show Gist options
  • Select an option

  • Save AustinBrunkhorst/94973cf89c572f6b007a572253a49f70 to your computer and use it in GitHub Desktop.

Select an option

Save AustinBrunkhorst/94973cf89c572f6b007a572253a49f70 to your computer and use it in GitHub Desktop.
C++ Reflection | Complete Example
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