Skip to content

Commit

Permalink
Merge pull request #211 from SylvainCorlay/generator-boolean
Browse files Browse the repository at this point in the history
Add m_generator boolean so that xmaterialize destructor does not clos…
  • Loading branch information
SylvainCorlay committed Nov 5, 2020
2 parents 298bbda + acd461a commit 0d2a942
Showing 1 changed file with 12 additions and 7 deletions.
19 changes: 12 additions & 7 deletions include/xwidgets/xmaterialize.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ namespace xw

template <class... A>
xmaterialize(bool open, A&&...);

bool m_generator;
};

/*******************************
Expand All @@ -60,17 +62,17 @@ namespace xw
template <template <class> class B, class... P>
template <class... A>
inline xmaterialize<B, P...>::xmaterialize(A&&... args)
: xmaterialize(true, std::forward<A>(args)...)
: xmaterialize(false, std::forward<A>(args)...)
{
}

// private constructor determining whether the comm should be open
template <template <class> class B, class... P>
template <class... A>
inline xmaterialize<B, P...>::xmaterialize(bool op, A&&... args)
: base_type(std::forward<A>(args)...)
inline xmaterialize<B, P...>::xmaterialize(bool generator, A&&... args)
: base_type(std::forward<A>(args)...), m_generator(generator)
{
if (op)
if (!m_generator)
{
this->open();
}
Expand All @@ -80,13 +82,13 @@ namespace xw
template <class... A>
inline auto xmaterialize<B, P...>::initialize(A&&... args) -> xmaterialize
{
return xmaterialize(false, std::forward<A>(args)...);
return xmaterialize(true, std::forward<A>(args)...);
}

template <template <class> class B, class... P>
inline xmaterialize<B, P...>::~xmaterialize()
{
if (!this->moved_from())
if (!m_generator && !this->moved_from())
{
this->close();
}
Expand All @@ -102,7 +104,10 @@ namespace xw
template <template <class> class B, class... P>
inline xmaterialize<B, P...>& xmaterialize<B, P...>::operator=(const xmaterialize& rhs)
{
this->close();
if (!m_generator)
{
this->close();
}
base_type::operator=(rhs);
this->open();
return *this;
Expand Down

0 comments on commit 0d2a942

Please sign in to comment.