Skip to content

Commit 462d19b

Browse files
committed
#128 Extract node_base definition in node_base.inl
1 parent 2e2fba3 commit 462d19b

File tree

2 files changed

+81
-38
lines changed

2 files changed

+81
-38
lines changed

include/ureact/detail/node_base.hpp

Lines changed: 12 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
#define UREACT_DETAIL_NODE_BASE_HPP
1212

1313
#include <memory>
14+
#include <tuple>
1415
#include <utility>
1516

1617
#include <ureact/context.hpp>
@@ -41,18 +42,9 @@ Ret create_wrapped_node( Args&&... args )
4142
class node_base : public reactive_node_interface
4243
{
4344
public:
44-
explicit node_base( context context )
45-
: m_context( std::move( context ) )
46-
{
47-
assert( !get_graph().is_locked() && "Can't create node from callback" );
48-
m_id = get_graph().register_node();
49-
}
45+
explicit node_base( context context );
5046

51-
~node_base() override
52-
{
53-
detach_from_all();
54-
get_graph().unregister_node( m_id );
55-
}
47+
~node_base() override;
5648

5749
UREACT_WARN_UNUSED_RESULT node_id get_node_id() const
5850
{
@@ -70,36 +62,14 @@ class node_base : public reactive_node_interface
7062
}
7163

7264
protected:
73-
UREACT_WARN_UNUSED_RESULT react_graph& get_graph()
74-
{
75-
return get_internals( m_context ).get_graph();
76-
}
77-
78-
UREACT_WARN_UNUSED_RESULT const react_graph& get_graph() const
79-
{
80-
return get_internals( m_context ).get_graph();
81-
}
65+
UREACT_WARN_UNUSED_RESULT react_graph& get_graph();
66+
UREACT_WARN_UNUSED_RESULT const react_graph& get_graph() const;
8267

83-
void attach_to( node_id parentId )
84-
{
85-
m_parents.add( parentId );
86-
get_graph().attach_node( m_id, parentId );
87-
}
68+
void attach_to( node_id parentId );
8869

89-
void detach_from( node_id parentId )
90-
{
91-
get_graph().detach_node( m_id, parentId );
92-
m_parents.remove( parentId );
93-
}
70+
void detach_from( node_id parentId );
9471

95-
void detach_from_all()
96-
{
97-
for( node_id parentId : m_parents )
98-
{
99-
get_graph().detach_node( m_id, parentId );
100-
}
101-
m_parents.clear();
102-
}
72+
void detach_from_all();
10373

10474
template <class... Deps>
10575
void attach_to( const Deps&... deps )
@@ -137,4 +107,8 @@ class node_base : public reactive_node_interface
137107

138108
UREACT_END_NAMESPACE
139109

110+
#if UREACT_HEADER_ONLY
111+
# include <ureact/detail/node_base.inl>
112+
#endif
113+
140114
#endif // UREACT_DETAIL_NODE_BASE_HPP

include/ureact/detail/node_base.inl

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
//
2+
// Copyright (C) 2014-2017 Sebastian Jeckel.
3+
// Copyright (C) 2020-2023 Krylov Yaroslav.
4+
//
5+
// Distributed under the Boost Software License, Version 1.0.
6+
// (See accompanying file LICENSE_1_0.txt or copy at
7+
// http://www.boost.org/LICENSE_1_0.txt)
8+
//
9+
10+
#ifndef UREACT_DETAIL_NODE_BASE_INL
11+
#define UREACT_DETAIL_NODE_BASE_INL
12+
13+
#include <cassert>
14+
15+
#include <ureact/detail/defines.hpp>
16+
#include <ureact/detail/node_base.hpp>
17+
18+
UREACT_BEGIN_NAMESPACE
19+
20+
namespace detail
21+
{
22+
23+
UREACT_FUNC node_base::node_base( context context )
24+
: m_context( std::move( context ) )
25+
{
26+
assert( !get_graph().is_locked() && "Can't create node from callback" );
27+
m_id = get_graph().register_node();
28+
}
29+
30+
UREACT_FUNC node_base::~node_base()
31+
{
32+
detach_from_all();
33+
get_graph().unregister_node( m_id );
34+
}
35+
36+
UREACT_FUNC react_graph& node_base::get_graph()
37+
{
38+
return get_internals( m_context ).get_graph();
39+
}
40+
41+
UREACT_FUNC const react_graph& node_base::get_graph() const
42+
{
43+
return get_internals( m_context ).get_graph();
44+
}
45+
46+
UREACT_FUNC void node_base::attach_to( node_id parentId )
47+
{
48+
m_parents.add( parentId );
49+
get_graph().attach_node( m_id, parentId );
50+
}
51+
52+
UREACT_FUNC void node_base::detach_from( node_id parentId )
53+
{
54+
get_graph().detach_node( m_id, parentId );
55+
m_parents.remove( parentId );
56+
}
57+
58+
UREACT_FUNC void node_base::detach_from_all()
59+
{
60+
for( node_id parentId : m_parents )
61+
get_graph().detach_node( m_id, parentId );
62+
m_parents.clear();
63+
}
64+
65+
} // namespace detail
66+
67+
UREACT_END_NAMESPACE
68+
69+
#endif //UREACT_DETAIL_NODE_BASE_INL

0 commit comments

Comments
 (0)