diff --git a/include/ureact/detail/transaction.inl b/include/ureact/detail/transaction.inl new file mode 100644 index 0000000..5f530e0 --- /dev/null +++ b/include/ureact/detail/transaction.inl @@ -0,0 +1,60 @@ +// +// Copyright (C) 2014-2017 Sebastian Jeckel. +// Copyright (C) 2020-2023 Krylov Yaroslav. +// +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt) +// + +#ifndef UREACT_DETAIL_TRANSACTION_INL +#define UREACT_DETAIL_TRANSACTION_INL + +#include + +#include +#include +#include + +UREACT_BEGIN_NAMESPACE + +UREACT_FUNC transaction::transaction( context ctx ) + : m_context( std::move( ctx ) ) +{ + auto& graph = get_internals( m_context ).get_graph(); + assert( !graph.is_propagation_in_progress() + && "Can't start transaction in the middle of the change propagation process" ); + graph.start_transaction(); +} + +UREACT_FUNC transaction::~transaction() +{ + finish_impl(); +} + +UREACT_FUNC void transaction::finish() +{ + finish_impl(); +} + +UREACT_FUNC void transaction::finish_impl() +{ + if( !m_finished ) + { + get_internals( m_context ).get_graph().finish_transaction(); + m_finished = true; + } +} + +namespace default_context +{ + +UREACT_FUNC default_transaction::default_transaction() + : transaction( default_context::get() ) +{} + +} // namespace default_context + +UREACT_END_NAMESPACE + +#endif //UREACT_DETAIL_TRANSACTION_INL diff --git a/include/ureact/transaction.hpp b/include/ureact/transaction.hpp index 93290a3..6cacd6d 100644 --- a/include/ureact/transaction.hpp +++ b/include/ureact/transaction.hpp @@ -12,48 +12,25 @@ #include #include -#include UREACT_BEGIN_NAMESPACE /*! * @brief Guard class to perform several changes atomically - * */ class UREACT_WARN_UNUSED_RESULT transaction { public: - explicit transaction( context ctx ) - : m_context( std::move( ctx ) ) - { - auto& graph = get_internals( m_context ).get_graph(); - assert( !graph.is_propagation_in_progress() - && "Can't start transaction in the middle of the change propagation process" ); - graph.start_transaction(); - } - - ~transaction() - { - finish_impl(); - } + explicit transaction( context ctx ); + ~transaction(); /*! * @brief Finish transaction before code scope is ended */ - void finish() - { - finish_impl(); - } + void finish(); private: - void finish_impl() - { - if( !m_finished ) - { - get_internals( m_context ).get_graph().finish_transaction(); - m_finished = true; - } - } + void finish_impl(); UREACT_MAKE_NONCOPYABLE( transaction ); UREACT_MAKE_NONMOVABLE( transaction ); @@ -71,15 +48,17 @@ namespace default_context * Named differently from "transaction", so it is possible to use them both, * where both ureact and ureact::default_context namespaces are used */ -struct UREACT_WARN_UNUSED_RESULT default_transaction : ureact::transaction +struct UREACT_WARN_UNUSED_RESULT default_transaction : public transaction { - default_transaction() - : ureact::transaction( default_context::get() ) - {} + default_transaction(); }; } // namespace default_context UREACT_END_NAMESPACE +#if UREACT_HEADER_ONLY +# include +#endif + #endif // UREACT_TRANSACTION_HPP