-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
#128 Extract context related definitions in context.inl
- Loading branch information
Showing
3 changed files
with
96 additions
and
49 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
// | ||
// 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_CONTEXT_INL | ||
#define UREACT_DETAIL_CONTEXT_INL | ||
|
||
#include <memory> | ||
|
||
#include <ureact/detail/defines.hpp> | ||
#include <ureact/detail/graph_impl.hpp> | ||
|
||
UREACT_BEGIN_NAMESPACE | ||
|
||
namespace detail | ||
{ | ||
|
||
UREACT_FUNC context_internals::context_internals( std::shared_ptr<react_graph> graph ) | ||
: m_graph_ptr( std::move( graph ) ) | ||
{} | ||
|
||
UREACT_FUNC react_graph& context_internals::get_graph() | ||
{ | ||
return *m_graph_ptr; | ||
} | ||
|
||
UREACT_FUNC const react_graph& context_internals::get_graph() const | ||
{ | ||
return *m_graph_ptr; | ||
} | ||
|
||
} // namespace detail | ||
|
||
UREACT_FUNC context::context( std::shared_ptr<detail::react_graph> graph ) | ||
: detail::context_internals( std::move( graph ) ) | ||
{} | ||
|
||
namespace default_context | ||
{ | ||
|
||
UREACT_FUNC context get() | ||
{ | ||
thread_local static std::weak_ptr<detail::react_graph> s_instance; | ||
|
||
auto graphPtr = s_instance.lock(); | ||
|
||
if( !graphPtr ) | ||
{ | ||
s_instance = graphPtr = std::make_shared<detail::react_graph>(); | ||
} | ||
|
||
return context{ std::move( graphPtr ) }; | ||
} | ||
|
||
} // namespace default_context | ||
|
||
UREACT_END_NAMESPACE | ||
|
||
#endif //UREACT_DETAIL_CONTEXT_INL |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters