forked from duilib/duilib
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathUIListCommonDefine.cpp
96 lines (78 loc) · 1.28 KB
/
UIListCommonDefine.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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
#include "stdafx.h"
#include "UIListCommonDefine.hpp"
namespace DuiLib
{
double CalculateDelay(double state)
{
return pow(state, 2);
}
void Node::set_parent(Node* parent)
{
parent_ = parent;
}
Node::Node()
: parent_(NULL)
{}
Node::Node(NodeData t)
: data_(t)
, parent_(NULL)
{}
Node::Node(NodeData t, Node* parent)
: data_ (t)
, parent_ (parent)
{}
Node::~Node()
{
for (int i = 0; i < num_children(); ++i)
delete children_[i];
}
NodeData& Node::data()
{
return data_;
}
int Node::num_children() const
{
return static_cast<int>(children_.size());
}
Node* Node::child(int i)
{
return children_[i];
}
Node* Node::parent()
{
return ( parent_);
}
bool Node::has_children() const
{
return num_children() > 0;
}
bool Node::folder() const
{
return data_.folder_;
}
void Node::add_child(Node* child)
{
child->set_parent(this);
children_.push_back(child);
}
void Node::remove_child(Node* child)
{
Children::iterator iter = children_.begin();
for (; iter < children_.end(); ++iter)
{
if (*iter == child)
{
children_.erase(iter);
return;
}
}
}
Node* Node::get_last_child()
{
if (has_children())
{
return child(num_children() - 1)->get_last_child();
}
return this;
}
}