| 1 |
|
| #include "EXTERN.h" |
| 2 |
|
| #include "perl.h" |
| 3 |
|
| #include "XSUB.h" |
| 4 |
|
| |
| 5 |
|
| #include "src/types.h" |
| 6 |
|
| #include "src/Exceptions.h" |
| 7 |
|
| #include "src/Identifiable.h" |
| 8 |
|
| #include "src/Listable.h" |
| 9 |
|
| #include "src/Writable.h" |
| 10 |
|
| #include "src/Node.h" |
| 11 |
|
| |
| 12 |
0 |
| void initialize_listable(Listable* self){ |
| 13 |
0 |
| initialize_writable((Writable*)self); |
| 14 |
0 |
| self->index = 0; |
| 15 |
0 |
| self->entities = newAV(); |
| 16 |
0 |
| } |
| 17 |
|
| |
| 18 |
0 |
| int can_contain(Listable* self, Identifiable* element) { |
| 19 |
0 |
| Identifiable* listid = (Identifiable*)self; |
| 20 |
|
| |
| 21 |
|
| // in most cases, a simple comparison between the _type |
| 22 |
|
| // and _container fields should suffice |
| 23 |
0 |
▶ | if ( listid->_type == element->_container ) { |
Branch: 1 branch
| Branch | True | False | Total |
| if ( listid->_type == element->_container ) { |
0 |
0 |
0 |
|
| 24 |
0 |
| return 1; |
| 25 |
|
| } |
| 26 |
|
| |
| 27 |
|
| // tree nodes can go into trees, but also in other nodes |
| 28 |
|
| // as their children |
| 29 |
0 |
▶ | else if ( listid->_type == _NODE_ && element->_type == _NODE_ ) { |
Branch: 2 branches
| Branch | True | False | Total |
| else if ( listid->_type == _NODE_ && element->_type == _NODE_ ) { |
0 |
0 |
0 |
| else if ( listid->_type == _NODE_ && element->_type == _NODE_ ) { |
0 |
0 |
0 |
|
| 30 |
0 |
| return 1; |
| 31 |
|
| } |
| 32 |
|
| |
| 33 |
|
| // XXX once we deal with raw character data going into matrix rows |
| 34 |
|
| // we will need one more possibility here |
| 35 |
|
| else { |
| 36 |
0 |
| return 0; |
| 37 |
|
| } |
| 38 |
|
| } |
| 39 |
|
| |
| 40 |
0 |
| void insert(Listable* self, Identifiable* element) { |
| 41 |
0 |
▶ | if ( can_contain(self,element) ) { |
Branch: 1 branch
| Branch | True | False | Total |
| if ( can_contain(self,element) ) { |
0 |
0 |
0 |
|
| 42 |
0 |
| SV* sv = newSV(0); |
| 43 |
0 |
| int idx = element->_index; |
| 44 |
0 |
| sv_setref_pv( sv, package[idx], (void*)element ); |
| 45 |
0 |
| SvREFCNT_inc(sv); |
| 46 |
0 |
| av_push(self->entities, sv); |
| 47 |
|
| |
| 48 |
0 |
▶ | if ( element->_type == _NODE_ ) { |
Branch: 1 branch
| Branch | True | False | Total |
| if ( element->_type == _NODE_ ) { |
0 |
0 |
0 |
|
| 49 |
0 |
| ((Node*)element)->tree = (Tree*)self; |
| 50 |
|
| } |
| 51 |
|
| } |
| 52 |
|
| else { |
| 53 |
0 |
| croak("Object mismatch!"); |
| 54 |
|
| } |
| 55 |
0 |
| } |
| 56 |
|
| |
| 57 |
0 |
| void insert_at_index(Listable* self, Identifiable* element, int index) { |
| 58 |
0 |
▶ | if ( can_contain(self,element) ) { |
Branch: 1 branch
| Branch | True | False | Total |
| if ( can_contain(self,element) ) { |
0 |
0 |
0 |
|
| 59 |
0 |
| SV* sv = newSV(0); |
| 60 |
0 |
| int idx = element->_index; |
| 61 |
0 |
| sv_setref_pv( sv, package[idx], (void*)element ); |
| 62 |
0 |
| SvREFCNT_inc(sv); |
| 63 |
0 |
| av_store(self->entities, index, sv); |
| 64 |
|
| } |
| 65 |
|
| else { |
| 66 |
0 |
| croak("Object mismatch!"); |
| 67 |
|
| } |
| 68 |
0 |
| } |
| 69 |
|
| |
| 70 |
0 |
| void splice_at_index(Listable* self, Identifiable* element, int index) { |
| 71 |
0 |
▶ | if ( can_contain(self,element) ) { |
Branch: 1 branch
| Branch | True | False | Total |
| if ( can_contain(self,element) ) { |
0 |
0 |
0 |
|
| 72 |
|
| |
| 73 |
|
| // move any subsequent elements over |
| 74 |
|
| //int i; |
| 75 |
|
| //for ( i = ( self->used - 1 ); i >= index; i-- ) { |
| 76 |
|
| // self->entities[i+1] = self->entities[i]; |
| 77 |
|
| //} |
| 78 |
|
| //self->entities[index] = element; |
| 79 |
|
| //SvREFCNT_inc(element->ref); |
| 80 |
|
| } |
| 81 |
|
| else { |
| 82 |
0 |
| croak("Object mismatch!"); |
| 83 |
|
| } |
| 84 |
0 |
| } |
| 85 |
|
| |
| 86 |
0 |
| AV* get_entities(Listable* self) { |
| 87 |
0 |
| return self->entities; |
| 88 |
|
| } |
| 89 |
|
| |
| 90 |
0 |
| void destroy_listable(Listable* self) { |
| 91 |
0 |
| destroy_writable((Writable*)self); |
| 92 |
|
| //SvREFCNT_dec( self->entities ); |
| 93 |
0 |
| } |
| 94 |
|
| MODULE = Bio::PhyloXS::Listable PACKAGE = Bio::PhyloXS::Listable |
| 95 |
|
| |
| 96 |
|
| PROTOTYPES: DISABLE |
| 97 |
|
| |
| 98 |
|
| |
| 99 |
|
| void |
| 100 |
|
| initialize_listable (self) |
| 101 |
|
| Listable * self |
| 102 |
|
| PREINIT: |
| 103 |
|
| I32* temp; |
| 104 |
|
| PPCODE: |
| 105 |
0 |
| temp = PL_markstack_ptr++; |
| 106 |
0 |
| initialize_listable(self); |
| 107 |
0 |
▶ | if (PL_markstack_ptr != temp) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (PL_markstack_ptr != temp) { |
0 |
0 |
0 |
|
| 108 |
|
| /* truly void, because dXSARGS not invoked */ |
| 109 |
0 |
| PL_markstack_ptr = temp; |
| 110 |
0 |
| XSRETURN_EMPTY; /* return empty stack */ |
| 111 |
|
| } |
| 112 |
|
| /* must have used dXSARGS; list context implied */ |
| 113 |
0 |
| return; /* assume stack size is correct */ |
| 114 |
|
| |
| 115 |
|
| int |
| 116 |
|
| can_contain (self, element) |
| 117 |
|
| Listable * self |
| 118 |
|
| Identifiable * element |
| 119 |
|
| |
| 120 |
|
| void |
| 121 |
|
| insert (self, element) |
| 122 |
|
| Listable * self |
| 123 |
|
| Identifiable * element |
| 124 |
|
| PREINIT: |
| 125 |
|
| I32* temp; |
| 126 |
|
| PPCODE: |
| 127 |
0 |
| temp = PL_markstack_ptr++; |
| 128 |
0 |
| insert(self, element); |
| 129 |
0 |
▶ | if (PL_markstack_ptr != temp) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (PL_markstack_ptr != temp) { |
0 |
0 |
0 |
|
| 130 |
|
| /* truly void, because dXSARGS not invoked */ |
| 131 |
0 |
| PL_markstack_ptr = temp; |
| 132 |
0 |
| XSRETURN_EMPTY; /* return empty stack */ |
| 133 |
|
| } |
| 134 |
|
| /* must have used dXSARGS; list context implied */ |
| 135 |
0 |
| return; /* assume stack size is correct */ |
| 136 |
|
| |
| 137 |
|
| void |
| 138 |
|
| insert_at_index (self, element, index) |
| 139 |
|
| Listable * self |
| 140 |
|
| Identifiable * element |
| 141 |
|
| int index |
| 142 |
|
| PREINIT: |
| 143 |
|
| I32* temp; |
| 144 |
|
| PPCODE: |
| 145 |
0 |
| temp = PL_markstack_ptr++; |
| 146 |
0 |
| insert_at_index(self, element, index); |
| 147 |
0 |
▶ | if (PL_markstack_ptr != temp) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (PL_markstack_ptr != temp) { |
0 |
0 |
0 |
|
| 148 |
|
| /* truly void, because dXSARGS not invoked */ |
| 149 |
0 |
| PL_markstack_ptr = temp; |
| 150 |
0 |
| XSRETURN_EMPTY; /* return empty stack */ |
| 151 |
|
| } |
| 152 |
|
| /* must have used dXSARGS; list context implied */ |
| 153 |
0 |
| return; /* assume stack size is correct */ |
| 154 |
|
| |
| 155 |
|
| void |
| 156 |
|
| splice_at_index (self, element, index) |
| 157 |
|
| Listable * self |
| 158 |
|
| Identifiable * element |
| 159 |
|
| int index |
| 160 |
|
| PREINIT: |
| 161 |
|
| I32* temp; |
| 162 |
|
| PPCODE: |
| 163 |
0 |
| temp = PL_markstack_ptr++; |
| 164 |
0 |
| splice_at_index(self, element, index); |
| 165 |
0 |
▶ | if (PL_markstack_ptr != temp) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (PL_markstack_ptr != temp) { |
0 |
0 |
0 |
|
| 166 |
|
| /* truly void, because dXSARGS not invoked */ |
| 167 |
0 |
| PL_markstack_ptr = temp; |
| 168 |
0 |
| XSRETURN_EMPTY; /* return empty stack */ |
| 169 |
|
| } |
| 170 |
|
| /* must have used dXSARGS; list context implied */ |
| 171 |
0 |
| return; /* assume stack size is correct */ |
| 172 |
|
| |
| 173 |
|
| AV * |
| 174 |
|
| get_entities (self) |
| 175 |
|
| Listable * self |
| 176 |
|
| |
| 177 |
|
| void |
| 178 |
|
| destroy_listable (self) |
| 179 |
|
| Listable * self |
| 180 |
|
| PREINIT: |
| 181 |
|
| I32* temp; |
| 182 |
|
| PPCODE: |
| 183 |
0 |
| temp = PL_markstack_ptr++; |
| 184 |
0 |
| destroy_listable(self); |
| 185 |
0 |
▶ | if (PL_markstack_ptr != temp) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (PL_markstack_ptr != temp) { |
0 |
0 |
0 |
|
| 186 |
|
| /* truly void, because dXSARGS not invoked */ |
| 187 |
0 |
| PL_markstack_ptr = temp; |
| 188 |
0 |
| XSRETURN_EMPTY; /* return empty stack */ |
| 189 |
|
| } |
| 190 |
|
| /* must have used dXSARGS; list context implied */ |
| 191 |
0 |
| return; /* assume stack size is correct */ |
| 192 |
|
| |