Skip to content

Commit

Permalink
removed if expression during invoke of "destructor"
Browse files Browse the repository at this point in the history
same procedure like for the properties.
  • Loading branch information
acki-m committed May 26, 2016
1 parent 924a018 commit bc14da0
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 14 deletions.
18 changes: 7 additions & 11 deletions src/rttr/destructor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,12 @@ namespace rttr
namespace detail
{

static const destructor_wrapper_base invalid_wrapper;

template<>
destructor create_item(const destructor_wrapper_base* wrapper)
{
return destructor(wrapper);
return destructor(wrapper ? wrapper : &invalid_wrapper);
}

} // end namespace detail
Expand All @@ -56,34 +58,28 @@ destructor::destructor(const detail::destructor_wrapper_base* wrapper)

bool destructor::is_valid() const
{
return (m_wrapper ? true : false);
return m_wrapper->is_valid();
}

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

destructor::operator bool() const
{
return (m_wrapper ? true : false);
return m_wrapper->is_valid();
}

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

type destructor::get_destructed_type() const
{
if (is_valid())
return m_wrapper->get_destructed_type();
else
return detail::get_invalid_type();
return m_wrapper->get_destructed_type();
}

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

bool destructor::invoke(variant& obj) const
{
if (is_valid())
return m_wrapper->invoke(obj);
else
return false;
return m_wrapper->invoke(obj);
}

/////////////////////////////////////////////////////////////////////////////////////////
Expand Down
2 changes: 2 additions & 0 deletions src/rttr/detail/destructor/destructor_wrapper.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ class destructor_wrapper : public destructor_wrapper_base
public:
type get_destructed_type() const { return type::get<ClassType*>(); }

bool is_valid() const { return true; }

bool invoke(variant& obj) const
{
if (obj.is_type<ClassType*>())
Expand Down
23 changes: 22 additions & 1 deletion src/rttr/detail/destructor/destructor_wrapper_base.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,5 +40,26 @@ destructor_wrapper_base::~destructor_wrapper_base()

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

bool destructor_wrapper_base::is_valid() const
{
return false;
}

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

type destructor_wrapper_base::get_destructed_type() const
{
return get_invalid_type();
}

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

bool destructor_wrapper_base::invoke(variant& obj) const
{
return false;
}

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

} // end namespace detail
} // end namespace RTR
} // end namespace rttr
5 changes: 3 additions & 2 deletions src/rttr/detail/destructor/destructor_wrapper_base.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,9 @@ class RTTR_API destructor_wrapper_base
public:
virtual ~destructor_wrapper_base();

virtual type get_destructed_type() const = 0;
virtual bool invoke(variant& obj) const = 0;
virtual bool is_valid() const;
virtual type get_destructed_type() const;
virtual bool invoke(variant& obj) const;
};

} // end namespace detail
Expand Down

0 comments on commit bc14da0

Please sign in to comment.