forked from jasp-stats/jasp-desktop
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdatasetbasenode.cpp
75 lines (59 loc) · 1.37 KB
/
datasetbasenode.cpp
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
#define ENUM_DECLARATION_CPP
#include "datasetbasenode.h"
DataSetBaseNode::DataSetBaseNode(dataSetBaseNodeType typeNode, DataSetBaseNode * parent)
: _type(typeNode), _parent(parent)
{
if(_parent)
_parent->registerChild(this);
}
DataSetBaseNode::~DataSetBaseNode()
{
if(_parent)
_parent->unregisterChild(this);
_parent = nullptr;
}
void DataSetBaseNode::registerChild(DataSetBaseNode *child)
{
_children.insert(child);
}
void DataSetBaseNode::unregisterChild(DataSetBaseNode *child)
{
_children.erase(child);
}
bool DataSetBaseNode::nodeStillExists(DataSetBaseNode *node) const
{
if(node == this)
return true;
for(DataSetBaseNode * child : _children)
if(child->nodeStillExists(node))
return true;
return false;
}
void DataSetBaseNode::incRevision()
{
_revision++;
checkForChanges();
}
int DataSetBaseNode::nestedRevision()
{
int rev = _revision;
for(DataSetBaseNode * child : _children)
rev *= child->nestedRevision();
return rev;
}
void DataSetBaseNode::setModifiedCallback(std::function<void ()> callback)
{
_somethingModifiedCallback = callback;
}
void DataSetBaseNode::checkForChanges()
{
if(_parent)
_parent->checkForChanges();
else if(_somethingModifiedCallback) //we have a callback so use it
{
int nested = nestedRevision();
if(nested != _previousNestedRevision)
_somethingModifiedCallback();
_previousNestedRevision = nested;
}
}