Guest User

Untitled

a guest
Jul 20th, 2016
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.22 KB | None | 0 0
  1. #ifndef VARIABLE_H
  2. #define VARIABLE_H
  3.  
  4. #include "reflection.h"
  5. #include "meta_generated.h"
  6.  
  7. #define MEMBER_VARIABLE( variable, member ) Variable( MemberType( member ), PTR_ADD( variable->data, member->offset ) )
  8.  
  9. //--------------------------------------------------------------------------------------------------
  10. struct variable
  11. {
  12.     TypeInfo* type;
  13.     void* data;
  14. };
  15.  
  16. //--------------------------------------------------------------------------------------------------
  17. inline variable Variable( TypeInfo* type, void* data )
  18. {
  19.     variable v;
  20.     v.type = type;
  21.     v.data = data;
  22.     return v;
  23. }
  24.  
  25. //--------------------------------------------------------------------------------------------------
  26. template < typename T >
  27. inline variable Variable( T& data )
  28. {
  29.     variable v;
  30.     v.type = TypeOf( data );
  31.     v.data = &data;
  32.     return v;
  33. }
  34.  
  35. //--------------------------------------------------------------------------------------------------
  36. template < typename T >
  37. inline T& Value( variable& v )
  38. {
  39.     return *(T*)v.data;
  40. }
  41.  
  42. //--------------------------------------------------------------------------------------------------
  43. template < typename T >
  44. inline T& Value( variable* v )
  45. {
  46.     return *(T*)v->data;
  47. }
  48.  
  49. #endif // VARIABLE_H
Advertisement
Add Comment
Please, Sign In to add comment