lib/Bio/PhyloXS/Forest/Node.xs

filter: Statementstmt 0.0% 0 / 101 Branchbran 0.0% 0 / 26 Conditioncond n/a MC/DCmcdc n/a Subroutinesub n/a Podpod n/a totaltotal 0.0% 0 / 127 CC 0 SCAR 0
CC
0
Cov
0%
CRAP 0
« lib/Bio/PhyloXS.xs ↑ Summary lib/Bio/PhyloXS/Forest/Tree.xs »
1 #include "EXTERN.h"
2 #include "perl.h"
3 #include "XSUB.h"
4 #include "INLINE.h"
5 # include "src/types.h"
6 # include "src/Identifiable.h"
7 # include "src/Writable.h"
8 # include "src/Listable.h"
9 # include "src/Node.h"
10  
11 0 Node *create(const char *classname) {
12 Node *self;
13 0 Newx(self,1,Node);
14 0 initialize_node(self);
15 0 return self;
16 }
17  
18 0 void initialize_node(Node* self) {
19 0 initialize_listable((Listable*)self);
20 0 self->parent = NULL;
21 0 self->rank = NULL;
22 0 self->tree = NULL;
23 0 self->branch_length = 0.0;
24 0 ((Identifiable*)self)->_type = _NODE_;
25 0 ((Identifiable*)self)->_container = _TREE_;
26 0 ((Identifiable*)self)->_index = _NODE_IDX_;
27 0 }
28  
29 0 double get_branch_length(Node* self) {
30 0 return self->branch_length;
31 }
32  
33 0 Node* set_raw_branch_length(Node* self, ...) {
34 0 Inline_Stack_Vars; // handle variable argument list
35 0 ▶ if ( Inline_Stack_Items == 2 && Inline_Stack_Item(1) != NULL ) {
Branch: 2 branches
BranchTrueFalseTotal
if ( Inline_Stack_Items == 2 && Inline_Stack_Item(1) != NULL ) { 0 0 0
if ( Inline_Stack_Items == 2 && Inline_Stack_Item(1) != NULL ) { 0 0 0
36 0 SV* value = Inline_Stack_Item(1);
37 0 ▶ if ( looks_like_number(value) ) {
Branch: 1 branch
BranchTrueFalseTotal
if ( looks_like_number(value) ) { 0 0 0
38 0 self->branch_length = SvNV(value);
39 }
40 }
41 else {
42 0 self->branch_length = 0.0;
43 }
44 0 return self;
45 }
46  
47 0 Node* set_tree(Node* self, Tree* tree) {
48 0 self->tree = tree;
49 0 return self;
50 }
51  
52 0 Tree* get_tree(Node* self) {
53 0 return self->tree;
54 }
55  
56 0 char* get_rank(Node* self) {
57 0 return self->rank;
58 }
59  
60 0 Node* set_rank(Node* self, char * rank) {
61 0 self->rank = savepv(rank);
62 0 return self;
63 }
64  
65 0 Node* set_raw_parent( Node* self, ... ) {
66 0 Inline_Stack_Vars; // handle variable argument list
67 0 ▶ if ( Inline_Stack_Items == 2 && Inline_Stack_Item(1) != NULL ) {
Branch: 2 branches
BranchTrueFalseTotal
if ( Inline_Stack_Items == 2 && Inline_Stack_Item(1) != NULL ) { 0 0 0
if ( Inline_Stack_Items == 2 && Inline_Stack_Item(1) != NULL ) { 0 0 0
68 0 self->parent = (Node*)SvIV(SvRV(Inline_Stack_Item(1)));
69 }
70 else {
71 0 self->parent = NULL;
72 }
73 0 return self;
74 }
75  
76 0 Node* get_parent(Node* self) {
77 0 return self->parent;
78 }
79  
80 0 Node* set_raw_child( Node* self, Node* child, ... ) {
81 0 Inline_Stack_Vars; // handle variable argument list
82
83 // determine where to place the child,
84 // default -1 means at the end
85 0 signed int position = -1;
86 0 ▶ if ( Inline_Stack_Items > 2 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ( Inline_Stack_Items > 2 ) { 0 0 0
87 0 position = SvIV(Inline_Stack_Item(2));
88 }
89
90 0 ▶ if ( position == -1 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ( position == -1 ) { 0 0 0
91 0 insert((Listable*)self, (Identifiable*)child);
92 }
93 else {
94 0 insert_at_index((Listable*)self,(Identifiable*)child,position);
95 }
96 0 return self;
97 }
98  
99 0 AV* get_children( Node* self ) {
100 0 return ((Listable*)self)->entities;
101 }
102  
103 0 Node* get_first_daughter( Node* self ) {
104 0 AV* list = ((Listable*)self)->entities;
105 0 ▶ if ( av_exists(list,0) ) {
Branch: 1 branch
BranchTrueFalseTotal
if ( av_exists(list,0) ) { 0 0 0
106 0 SV* sv = *(av_fetch(list, 0, 0));
107 0 return (Node*)SvIV(SvRV(sv));
108 }
109 0 return NULL;
110 }
111  
112 0 int is_child_of( Node* self, Node* parent ) {
113 0 ▶ if ( self->parent != NULL ) {
Branch: 1 branch
BranchTrueFalseTotal
if ( self->parent != NULL ) { 0 0 0
114 0 return ((Identifiable*)self->parent)->id == ((Identifiable*)parent)->id;
115 }
116 0 return 0;
117 }
118  
119 0 int is_ancestor_of( Node* self, Node* desc ) {
120 0 Node* p = desc->parent;
121 0 int sid = ((Identifiable*)self)->id;
122 0 ▶ while( p != NULL ) {
Branch: 1 branch
BranchTrueFalseTotal
while( p != NULL ) { 0 0 0
123 0 ▶ if ( ((Identifiable*)p)->id == sid ) {
Branch: 1 branch
BranchTrueFalseTotal
if ( ((Identifiable*)p)->id == sid ) { 0 0 0
124 0 return 1;
125 }
126 0 p = p->parent;
127 }
128 0 return 0;
129 }
130  
131 0 int is_terminal( Node* self ) {
132 0 return ! av_exists(((Listable*)self)->entities, 0);
133 }
134  
135 0 int is_internal( Node* self ) {
136 0 return av_exists(((Listable*)self)->entities, 0);
137 }
138  
139 0 int is_root( Node* self ) {
140 0 return self->parent == NULL;
141 }
142  
143 0 void destroy_node(Node* self) {
144 0 destroy_listable((Listable*)self);
145 0 }
146 MODULE = Bio::PhyloXS::Forest::Node PACKAGE = Bio::PhyloXS::Forest::Node
147  
148 PROTOTYPES: DISABLE
149  
150  
151 Node *
152 create (classname)
153 const char * classname
154  
155 void
156 initialize_node (self)
157 Node * self
158 PREINIT:
159 I32* temp;
160 PPCODE:
161 0 temp = PL_markstack_ptr++;
162 0 initialize_node(self);
163 0 ▶ if (PL_markstack_ptr != temp) {
Branch: 1 branch
BranchTrueFalseTotal
if (PL_markstack_ptr != temp) { 0 0 0
164 /* truly void, because dXSARGS not invoked */
165 0 PL_markstack_ptr = temp;
166 0 XSRETURN_EMPTY; /* return empty stack */
167 }
168 /* must have used dXSARGS; list context implied */
169 0 return; /* assume stack size is correct */
170  
171 double
172 get_branch_length (self)
173 Node * self
174  
175 Node *
176 set_raw_branch_length (self, ...)
177 Node * self
178 PREINIT:
179 I32* temp;
180 CODE:
181 0 temp = PL_markstack_ptr++;
182 0 RETVAL = set_raw_branch_length(self);
183 0 PL_markstack_ptr = temp;
184 OUTPUT:
185 RETVAL
186  
187 Node *
188 set_tree (self, tree)
189 Node * self
190 Tree * tree
191  
192 Tree *
193 get_tree (self)
194 Node * self
195  
196 char *
197 get_rank (self)
198 Node * self
199  
200 Node *
201 set_rank (self, rank)
202 Node * self
203 char * rank
204  
205 Node *
206 set_raw_parent (self, ...)
207 Node * self
208 PREINIT:
209 I32* temp;
210 CODE:
211 0 temp = PL_markstack_ptr++;
212 0 RETVAL = set_raw_parent(self);
213 0 PL_markstack_ptr = temp;
214 OUTPUT:
215 RETVAL
216  
217 Node *
218 get_parent (self)
219 Node * self
220  
221 Node *
222 set_raw_child (self, child, ...)
223 Node * self
224 Node * child
225 PREINIT:
226 I32* temp;
227 CODE:
228 0 temp = PL_markstack_ptr++;
229 0 RETVAL = set_raw_child(self, child);
230 0 PL_markstack_ptr = temp;
231 OUTPUT:
232 RETVAL
233  
234 AV *
235 get_children (self)
236 Node * self
237  
238 Node *
239 get_first_daughter (self)
240 Node * self
241  
242 int
243 is_child_of (self, parent)
244 Node * self
245 Node * parent
246  
247 int
248 is_ancestor_of (self, desc)
249 Node * self
250 Node * desc
251  
252 int
253 is_terminal (self)
254 Node * self
255  
256 int
257 is_internal (self)
258 Node * self
259  
260 int
261 is_root (self)
262 Node * self
263  
264 void
265 destroy_node (self)
266 Node * self
267 PREINIT:
268 I32* temp;
269 PPCODE:
270 0 temp = PL_markstack_ptr++;
271 0 destroy_node(self);
272 0 ▶ if (PL_markstack_ptr != temp) {
Branch: 1 branch
BranchTrueFalseTotal
if (PL_markstack_ptr != temp) { 0 0 0
273 /* truly void, because dXSARGS not invoked */
274 0 PL_markstack_ptr = temp;
275 0 XSRETURN_EMPTY; /* return empty stack */
276 }
277 /* must have used dXSARGS; list context implied */
278 0 return; /* assume stack size is correct */
279  
« lib/Bio/PhyloXS.xs ↑ Summary lib/Bio/PhyloXS/Forest/Tree.xs »