forked from snakster/cpp.react
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnode_base.h
More file actions
103 lines (77 loc) · 2.93 KB
/
node_base.h
File metadata and controls
103 lines (77 loc) · 2.93 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
// Copyright Sebastian Jeckel 2017.
// 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 REACT_DETAIL_NODE_BASE_H_INCLUDED
#define REACT_DETAIL_NODE_BASE_H_INCLUDED
#pragma once
#include "react/detail/defs.h"
#include <iterator>
#include <memory>
#include <utility>
#include "react/common/utility.h"
#include "react/detail/graph_interface.h"
/***************************************/ REACT_IMPL_BEGIN /**************************************/
class ReactGraph;
///////////////////////////////////////////////////////////////////////////////////////////////////
/// CreateWrappedNode
///////////////////////////////////////////////////////////////////////////////////////////////////
template <typename RET, typename NODE, typename ... ARGS>
static RET CreateWrappedNode(ARGS&& ... args)
{
auto node = std::make_shared<NODE>(std::forward<ARGS>(args) ...);
return RET(std::move(node));
}
///////////////////////////////////////////////////////////////////////////////////////////////////
/// NodeBase
///////////////////////////////////////////////////////////////////////////////////////////////////
class NodeBase : public IReactNode
{
public:
NodeBase(const Group& group) :
group_( group )
{ }
NodeBase(const NodeBase&) = delete;
NodeBase& operator=(const NodeBase&) = delete;
NodeBase(NodeBase&&) = delete;
NodeBase& operator=(NodeBase&&) = delete;
/*void SetWeightHint(WeightHint weight)
{
switch (weight)
{
case WeightHint::heavy :
this->ForceUpdateThresholdExceeded(true);
break;
case WeightHint::light :
this->ForceUpdateThresholdExceeded(false);
break;
case WeightHint::automatic :
this->ResetUpdateThreshold();
break;
}
}*/
NodeId GetNodeId() const
{ return nodeId_; }
auto GetGroup() const -> const Group&
{ return group_; }
auto GetGroup() -> Group&
{ return group_; }
protected:
auto GetGraphPtr() const -> const std::shared_ptr<ReactGraph>&
{ return GetInternals(group_).GetGraphPtr(); }
auto GetGraphPtr() -> std::shared_ptr<ReactGraph>&
{ return GetInternals(group_).GetGraphPtr(); }
void RegisterMe(NodeCategory category = NodeCategory::normal)
{ nodeId_ = GetGraphPtr()->RegisterNode(this, category); }
void UnregisterMe()
{ GetGraphPtr()->UnregisterNode(nodeId_); }
void AttachToMe(NodeId otherNodeId)
{ GetGraphPtr()->AttachNode(nodeId_, otherNodeId); }
void DetachFromMe(NodeId otherNodeId)
{ GetGraphPtr()->DetachNode(nodeId_, otherNodeId); }
private:
NodeId nodeId_;
Group group_;
};
/****************************************/ REACT_IMPL_END /***************************************/
#endif // REACT_DETAIL_NODE_BASE_H_INCLUDED