]>
git.proxmox.com Git - ceph.git/blob - ceph/src/boost/tools/quickbook/src/tree.cpp
1 /*=============================================================================
2 Copyright (c) 2017 Daniel James
4 Use, modification and distribution is subject to the Boost Software
5 License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
6 http://www.boost.org/LICENSE_1_0.txt)
7 =============================================================================*/
16 void tree_node_base::add_before(tree_base
* t
)
19 t
->root_
&& !t
->root_
->parent_
&& !t
->root_
->prev_
&&
21 t
->root_
->parent_
= this->parent_
;
22 t
->root_
->next_
= this;
24 t
->root_
->prev_
= this->prev_
;
25 this->prev_
->next_
= t
->root_
;
28 this->parent_
->children_
= t
->root_
;
30 this->prev_
= t
->root_
;
34 void tree_node_base::add_after(tree_base
* t
)
37 t
->root_
&& !t
->root_
->parent_
&& !t
->root_
->prev_
&&
39 t
->root_
->parent_
= this->parent_
;
40 t
->root_
->prev_
= this;
41 t
->root_
->next_
= this->next_
;
42 if (this->next_
) this->next_
->prev_
= t
->root_
;
43 this->next_
= t
->root_
;
47 void tree_node_base::add_first_child(tree_base
* t
)
50 t
->root_
&& !t
->root_
->parent_
&& !t
->root_
->prev_
&&
52 t
->root_
->parent_
= this;
53 t
->root_
->next_
= this->children_
;
54 if (this->children_
) {
55 this->children_
->prev_
= t
->root_
;
57 this->children_
= t
->root_
;
61 void tree_node_base::add_last_child(tree_base
* t
)
64 t
->root_
&& !t
->root_
->parent_
&& !t
->root_
->prev_
&&
66 t
->root_
->parent_
= this;
67 if (!this->children_
) {
68 this->children_
= t
->root_
;
71 auto it
= this->children_
;
81 tree_base::tree_base() : root_(0) {}
82 tree_base::tree_base(tree_node_base
* r
) : root_(r
) {}
83 tree_base::~tree_base() {}
85 tree_base::tree_base(tree_base
&& x
) : root_(x
.root_
) { x
.root_
= 0; }
87 tree_base
& tree_base::operator=(tree_base
&& x
)
94 tree_node_base
* tree_base::extract(tree_node_base
* x
)
98 x
->parent_
->children_
= x
->next_
;
106 x
->prev_
->next_
= x
->next_
;
109 x
->next_
->prev_
= x
->prev_
;
117 tree_builder_base::tree_builder_base()
118 : tree_base(), current_(0), parent_(0)
122 tree_builder_base::tree_builder_base(tree_builder_base
&& x
)
123 : tree_base(std::move(x
)), current_(x
.current_
), parent_(x
.parent_
)
129 tree_builder_base
& tree_builder_base::operator=(tree_builder_base
&& x
)
132 current_
= x
.current_
;
140 // Nodes are deleted in the subclass, which knows their type.
141 tree_builder_base::~tree_builder_base() {}
143 tree_node_base
* tree_builder_base::extract(tree_node_base
* x
)
147 x
->parent_
->children_
= x
->next_
;
157 x
->prev_
->next_
= x
->next_
;
160 x
->next_
->prev_
= x
->prev_
;
168 tree_node_base
* tree_builder_base::release()
170 tree_node_base
* n
= root_
;
177 void tree_builder_base::add_element(tree_node_base
* n
)
179 n
->parent_
= parent_
;
185 parent_
->children_
= n
;
193 void tree_builder_base::start_children()
199 void tree_builder_base::end_children()
202 parent_
= current_
->parent_
;