Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bugfix class items inheritance #89

Merged
merged 2 commits into from
Oct 26, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ install:
mkdir cmake && travis_retry wget --no-check-certificate --quiet -O - ${CMAKE_URL} | tar --strip-components=1 -xz -C cmake
export PATH=${DEPS_DIR}/cmake/bin:${PATH}
else
brew upgrade cmake || brew install cmake
brew upgrade cmake || brew install cmake || brew link --overwrite cmake
fi
- cmake --version
#######################################################################################
Expand Down
10 changes: 8 additions & 2 deletions src/rttr/detail/type/type_register.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -364,7 +364,13 @@ type type_register_private::register_type(type_data& info) RTTR_NOEXCEPT

update_custom_name(derive_template_instance_name(info), type(&info));

return type(type_data_container[id]);
// when a base class type has class items, but the derived one not,
// we update the derived class item list
const auto t = type(type_data_container[id]);
update_class_list(t, &detail::class_data::m_properties);
update_class_list(t, &detail::class_data::m_methods);

return t;
}

/////////////////////////////////////////////////////////////////////////////////////////
Expand Down Expand Up @@ -762,7 +768,7 @@ void type_register_private::update_class_list(const type& t, T item_ptr)
{
// update type "t" with all items from the base classes
auto& all_class_items = (t.m_type_data->get_class_data().*item_ptr);
auto item_range = get_items_for_type(t, t.m_type_data->get_class_data().*item_ptr);
auto item_range = get_items_for_type(t, all_class_items);
detail::remove_cv_ref_t<decltype(all_class_items)> item_vec(item_range.begin(), item_range.end());
all_class_items.reserve(all_class_items.size() + 1);
all_class_items.clear(); // this will not reduce the capacity, i.e. new memory allocation may not necessary
Expand Down
32 changes: 32 additions & 0 deletions src/unit_tests/method/method_misc_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,20 @@ struct method_misc_test
static void static_func() {}
};

/////////////////////////////////////////////////////////////////////////////////////////

struct base_class_with_methods
{
base_class_with_methods(){}
void some_method() {}

RTTR_ENABLE()
};

struct derived_class_without_registered_methods : base_class_with_methods
{
RTTR_ENABLE(base_class_with_methods)
};


/////////////////////////////////////////////////////////////////////////////////////////
Expand All @@ -72,6 +86,11 @@ RTTR_REGISTRATION
metadata("Text", "Some funky description")
)
;

registration::class_<base_class_with_methods>("base_class_with_methods")
.method("some_method", &base_class_with_methods::some_method);

registration::class_<derived_class_without_registered_methods>("derived_class_without_registered_methods");
}

/////////////////////////////////////////////////////////////////////////////////////////
Expand Down Expand Up @@ -225,3 +244,16 @@ TEST_CASE("method - default_func - NEGATIVE - get_metadata()", "[method]")
}

/////////////////////////////////////////////////////////////////////////////////////////

TEST_CASE("method - check inheritance of methods", "[method]")
{
// base class has registered methodes, the derived class not
type t = type::get<derived_class_without_registered_methods>();
auto meth_range = t.get_methods();
REQUIRE(meth_range.size() == 1);

CHECK((*meth_range.begin()).get_name() == "some_method");
}

/////////////////////////////////////////////////////////////////////////////////////////

37 changes: 37 additions & 0 deletions src/unit_tests/property/property_class_inheritance.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,8 @@ struct bottom : left, right, right_2

}

/////////////////////////////////////////////////////////////////////////////////////////

struct base_prop_not_registered
{
base_prop_not_registered() : value(100) {}
Expand All @@ -106,6 +108,23 @@ struct derived_registered_prop : base_prop_not_registered

};

/////////////////////////////////////////////////////////////////////////////////////////

struct base_class_with_props
{
base_class_with_props() : value(100) {}
int value;

RTTR_ENABLE()
};

struct derived_class_without_registered_props : base_class_with_props
{
RTTR_ENABLE(base_class_with_props)
};

/////////////////////////////////////////////////////////////////////////////////////////

static double g_name;

/////////////////////////////////////////////////////////////////////////////////////////
Expand Down Expand Up @@ -159,6 +178,12 @@ RTTR_REGISTRATION

registration::class_<derived_registered_prop>("derived_registered_prop")
.property("value", &derived_registered_prop::value);


registration::class_<base_class_with_props>("base_class_with_props")
.property("value", &base_class_with_props::value);

registration::class_<derived_class_without_registered_props>("derived_class_without_registered_props");
}

/////////////////////////////////////////////////////////////////////////////////////////
Expand Down Expand Up @@ -512,3 +537,15 @@ TEST_CASE("property - base class not registered", "[property]")
}

/////////////////////////////////////////////////////////////////////////////////////////

TEST_CASE("property - check inheritance of probs", "[property]")
{
// base class has registered properties, the derived class not
type t_prop = type::get<derived_class_without_registered_props>();
auto prop_range = t_prop.get_properties();
REQUIRE(prop_range.size() == 1);

CHECK((*prop_range.begin()).get_name() == "value");
}

/////////////////////////////////////////////////////////////////////////////////////////