Advertisement
Guest User

Untitled

a guest
Mar 10th, 2015
205
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.52 KB | None | 0 0
  1. #include "integral_adapters.h"
  2. #include <iostream>
  3. #include <cassert>
  4.  
  5. struct sample_struct
  6. {
  7. short get_short() const {
  8. return short_;
  9. }
  10.  
  11. void set_short(short value) {
  12. short_ = value;
  13. }
  14.  
  15. float get_float() const {
  16. return float_;
  17. }
  18.  
  19. void set_float(float value) {
  20. float_ = value;
  21. }
  22.  
  23. short short_;
  24. float float_;
  25. };
  26.  
  27. extern const char short_id[] = "short_val";
  28. extern const char float_id[] = "float_val";
  29. extern const char sample_class_name[] = "up.sample_struct";
  30.  
  31. using sample_struct_meta = up::class_t< sample_struct, sample_class_name,
  32. up::member< short_id, up::adapters::method_integer<sample_struct, short, &sample_struct::get_short, &sample_struct::set_short > >,
  33. up::member< float_id, up::adapters::method_real <sample_struct, float, &sample_struct::get_float, &sample_struct::set_float > >
  34. >;
  35.  
  36. namespace up {
  37.  
  38. template<>
  39. struct lookup_meta_class_type<sample_struct> {
  40. using type = sample_struct_meta;
  41. };
  42.  
  43. }
  44.  
  45. void user_func(up::mutable_object_ref& ref)
  46. {
  47. auto num_members = ref.num_members();
  48. for (size_t i = 0; i < num_members; ++i) {
  49. std::cout << "member \"" << ref.member_id(i) << "\"\n";
  50. }
  51.  
  52. up::mutable_object_ref member_ref = ref.get_member(0);
  53. auto typed_ref = member_ref.cast<const up::integer>();
  54. assert(typed_ref);
  55. std::cout << "limits: {" << typed_ref->limits().first << "," << typed_ref->limits().second << "}\n";
  56. }
  57.  
  58. int main(int argc, char* argv[])
  59. {
  60. sample_struct sample;
  61. user_func(sample_struct_meta::make_ref(sample));
  62.  
  63. return 0;
  64. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement