lib/Bio/PhyloXS/NeXML/Writable.xs

filter: Statementstmt 0.0% 0 / 100 Branchbran 0.0% 0 / 16 Conditioncond n/a MC/DCmcdc n/a Subroutinesub n/a Podpod n/a totaltotal 0.0% 0 / 116 CC 0 SCAR 0
CC
0
Cov
0%
CRAP 0
« lib/Bio/PhyloXS/Mediators/TaxaMediator.xs ↑ Summary lib/Bio/PhyloXS/Util/Exceptions.c »
1 #include "EXTERN.h"
2 #include "perl.h"
3 #include "XSUB.h"
4 #include "INLINE.h"
5 # include "src/Writable.h"
6 # include "src/Identifiable.h"
7  
8 0 void initialize_writable(Writable* self){
9 0 initialize_identifiable((Identifiable*)self);
10 0 self->attributes = newHV();
11 0 self->meta = newAV();
12 0 self->url = NULL;
13 0 self->xml_id = NULL;
14 0 self->is_identifiable = 1;
15 0 self->is_suppress_ns = 0;
16 0 }
17  
18 0 Writable* set_attributes(Writable* self, ...) {
19 0 Inline_Stack_Vars; // handle variable argument list
20
21 // get either a hash ref or key/value pairs
22 HV* newValues;
23 0 ▶ if ( Inline_Stack_Items == 2 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ( Inline_Stack_Items == 2 ) { 0 0 0
24 0 newValues = (HV*)SvRV(Inline_Stack_Item(1));
25 }
26 else {
27 0 newValues = newHV();
28 int i;
29 0 ▶ for ( i = 1; i < Inline_Stack_Items - 1; i += 2 ) {
Branch: 1 branch
BranchTrueFalseTotal
for ( i = 1; i < Inline_Stack_Items - 1; i += 2 ) { 0 0 0
30 0 SV* key = Inline_Stack_Item(i);
31 0 SV* value = Inline_Stack_Item(i+1);
32 0 char* keystr = SvPV_nolen(key);
33 0 hv_store(newValues, keystr, strlen(keystr), value, 0);
34 }
35 }
36
37 // iterate over keys
38 0 I32 keys = hv_iterinit(newValues);
39 I32 i;
40 0 ▶ for ( i = 0; i < keys; i++ ) {
Branch: 1 branch
BranchTrueFalseTotal
for ( i = 0; i < keys; i++ ) { 0 0 0
41 0 char * key = NULL;
42 0 I32 key_length = 0;
43 0 SV* value = hv_iternextsv(newValues, &key, &key_length);
44
45 // verify namespace prefixes
46 0 char * pch = strchr( key, ':' );
47 0 ▶ if ( pch != NULL ) {
Branch: 1 branch
BranchTrueFalseTotal
if ( pch != NULL ) { 0 0 0
48 0 int pos = pch - key;
49 0 char * prefix = (char*) malloc(pos);
50 0 strncpy( prefix, key, pos );
51 0 char * msg = "Unbound attribute prefix '%s'\n";
52
53 // should use logger, and should be conditional on:
54 // 1. it not being 'xmlns',
55 // 2. it not being known in global set of namespaces
56 0 printf(msg,prefix);
57 }
58
59 // store value
60 0 hv_store(self->attributes, key, strlen(key), value, 0);
61 }
62  
63 0 return self;
64 }
65  
66 0 HV* get_attributes(Writable* self) {
67 0 return self->attributes;
68 }
69  
70 0 Writable* set_link(Writable* self, char* url) {
71 0 self->url = savepv(url);
72 0 return self;
73 }
74  
75 0 char* get_link(Writable* self) {
76 0 return self->url;
77 }
78  
79 0 Writable* set_name(Writable* self, char* name) {
80 0 hv_store(self->attributes, "label", 5, newSVpv(name,0), 0);
81 0 return self;
82 }
83  
84 0 char* get_name(Writable* self) {
85 0 ▶ if ( hv_exists(self->attributes, "label", 5) ) {
Branch: 1 branch
BranchTrueFalseTotal
if ( hv_exists(self->attributes, "label", 5) ) { 0 0 0
86 0 SV* label = *(hv_fetch(self->attributes, "label", 5, 0));
87 0 char * retval = SvPV_nolen(label);
88 0 return retval;
89 }
90 else {
91 0 return NULL;
92 }
93 }
94  
95 0 Writable* set_suppress_ns(Writable* self) {
96 0 self->is_suppress_ns = 1;
97 0 return self;
98 }
99  
100 0 Writable* clear_suppress_ns(Writable* self) {
101 0 self->is_suppress_ns = 0;
102 0 return self;
103 }
104  
105 0 int is_ns_suppressed(Writable* self) {
106 0 return self->is_suppress_ns;
107 }
108  
109 0 int get_suppress_ns(Writable* self) {
110 0 return self->is_suppress_ns;
111 }
112  
113 0 Writable* set_identifiable(Writable* self, int value) {
114 0 self->is_identifiable = value;
115 0 return self;
116 }
117  
118 0 int is_identifiable(Writable* self) {
119 0 return self->is_identifiable;
120 }
121  
122 0 int get_identifiable(Writable* self) {
123 0 return self->is_identifiable;
124 }
125  
126 0 const char * get_tag(Writable* self) {
127 0 int idx = ((Identifiable*)self)->_index;
128 0 return tag[idx];
129 }
130  
131 0 char * get_xml_id(Writable* self) {
132 char xml_id[10];
133 0 int idx = ((Identifiable*)self)->_index;
134 0 int end_idx = strlen(tag[idx]) - 1;
135 0 char start = tag[idx][0];
136 0 char end = tag[idx][end_idx];
137 0 sprintf(xml_id,"%c%c%d",start,end,((Identifiable*)self)->id);
138 0 self->xml_id = savepv(xml_id);
139 0 return self->xml_id;
140 }
141  
142 0 Writable* set_base_uri(Writable* self, char * uri) {
143 0 hv_store(self->attributes, "xml:base", 8, newSVpv(uri,0), 0);
144 0 return self;
145 }
146  
147 0 void destroy_writable(Writable* self) {
148 0 destroy_identifiable((Identifiable*)self);
149 // SvREFCNT_dec(self->attributes);
150 // SvREFCNT_dec(self->meta);
151 0 ▶ if ( self->url != NULL ) {
Branch: 1 branch
BranchTrueFalseTotal
if ( self->url != NULL ) { 0 0 0
152 0 Safefree(self->url);
153 }
154 0 }
155 MODULE = Bio::PhyloXS::NeXML::Writable PACKAGE = Bio::PhyloXS::NeXML::Writable
156  
157 PROTOTYPES: DISABLE
158  
159  
160 void
161 initialize_writable (self)
162 Writable * self
163 PREINIT:
164 I32* temp;
165 PPCODE:
166 0 temp = PL_markstack_ptr++;
167 0 initialize_writable(self);
168 0 ▶ if (PL_markstack_ptr != temp) {
Branch: 1 branch
BranchTrueFalseTotal
if (PL_markstack_ptr != temp) { 0 0 0
169 /* truly void, because dXSARGS not invoked */
170 0 PL_markstack_ptr = temp;
171 0 XSRETURN_EMPTY; /* return empty stack */
172 }
173 /* must have used dXSARGS; list context implied */
174 0 return; /* assume stack size is correct */
175  
176 Writable *
177 set_attributes (self, ...)
178 Writable * self
179 PREINIT:
180 I32* temp;
181 CODE:
182 0 temp = PL_markstack_ptr++;
183 0 RETVAL = set_attributes(self);
184 0 PL_markstack_ptr = temp;
185 OUTPUT:
186 RETVAL
187  
188 HV *
189 get_attributes (self)
190 Writable * self
191  
192 Writable *
193 set_link (self, url)
194 Writable * self
195 char * url
196  
197 char *
198 get_link (self)
199 Writable * self
200  
201 Writable *
202 set_name (self, name)
203 Writable * self
204 char * name
205  
206 char *
207 get_name (self)
208 Writable * self
209  
210 Writable *
211 set_suppress_ns (self)
212 Writable * self
213  
214 Writable *
215 clear_suppress_ns (self)
216 Writable * self
217  
218 int
219 is_ns_suppressed (self)
220 Writable * self
221  
222 int
223 get_suppress_ns (self)
224 Writable * self
225  
226 Writable *
227 set_identifiable (self, value)
228 Writable * self
229 int value
230  
231 int
232 is_identifiable (self)
233 Writable * self
234  
235 int
236 get_identifiable (self)
237 Writable * self
238  
239 const char *
240 get_tag (self)
241 Writable * self
242  
243 char *
244 get_xml_id (self)
245 Writable * self
246  
247 Writable *
248 set_base_uri (self, uri)
249 Writable * self
250 char * uri
251  
252 void
253 destroy_writable (self)
254 Writable * self
255 PREINIT:
256 I32* temp;
257 PPCODE:
258 0 temp = PL_markstack_ptr++;
259 0 destroy_writable(self);
260 0 ▶ if (PL_markstack_ptr != temp) {
Branch: 1 branch
BranchTrueFalseTotal
if (PL_markstack_ptr != temp) { 0 0 0
261 /* truly void, because dXSARGS not invoked */
262 0 PL_markstack_ptr = temp;
263 0 XSRETURN_EMPTY; /* return empty stack */
264 }
265 /* must have used dXSARGS; list context implied */
266 0 return; /* assume stack size is correct */
267  
« lib/Bio/PhyloXS/Mediators/TaxaMediator.xs ↑ Summary lib/Bio/PhyloXS/Util/Exceptions.c »