Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "integral_adapters.h"
- #include <iostream>
- #include <cassert>
- struct sample_struct
- {
- short get_short() const {
- return short_;
- }
- void set_short(short value) {
- short_ = value;
- }
- float get_float() const {
- return float_;
- }
- void set_float(float value) {
- float_ = value;
- }
- short short_;
- float float_;
- };
- extern const char short_id[] = "short_val";
- extern const char float_id[] = "float_val";
- extern const char sample_class_name[] = "up.sample_struct";
- using sample_struct_meta = up::class_t< sample_struct, sample_class_name,
- up::member< short_id, up::adapters::method_integer<sample_struct, short, &sample_struct::get_short, &sample_struct::set_short > >,
- up::member< float_id, up::adapters::method_real <sample_struct, float, &sample_struct::get_float, &sample_struct::set_float > >
- >;
- namespace up {
- template<>
- struct lookup_meta_class_type<sample_struct> {
- using type = sample_struct_meta;
- };
- }
- void user_func(up::mutable_object_ref& ref)
- {
- auto num_members = ref.num_members();
- for (size_t i = 0; i < num_members; ++i) {
- std::cout << "member \"" << ref.member_id(i) << "\"\n";
- }
- up::mutable_object_ref member_ref = ref.get_member(0);
- auto typed_ref = member_ref.cast<const up::integer>();
- assert(typed_ref);
- std::cout << "limits: {" << typed_ref->limits().first << "," << typed_ref->limits().second << "}\n";
- }
- int main(int argc, char* argv[])
- {
- sample_struct sample;
- user_func(sample_struct_meta::make_ref(sample));
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement