1 | /* |
---|
2 | * ---------------------------------------------------------------------- |
---|
3 | * INTERFACE: Fortran Rappture Library Source |
---|
4 | * |
---|
5 | * ====================================================================== |
---|
6 | * AUTHOR: Derrick Kearney, Purdue University |
---|
7 | * Copyright (c) 2004-2005 Purdue Research Foundation |
---|
8 | * |
---|
9 | * See the file "license.terms" for information on usage and |
---|
10 | * redistribution of this file, and for a DISCLAIMER OF ALL WARRANTIES. |
---|
11 | * ====================================================================== |
---|
12 | */ |
---|
13 | |
---|
14 | #include "RpLibraryFInterface.h" |
---|
15 | #include "RpBindingsDict.h" |
---|
16 | #include "RpLibraryFStubs.c" |
---|
17 | |
---|
18 | /**********************************************************************/ |
---|
19 | // FUNCTION: rp_lib(const char* filePath, int filePath_len) |
---|
20 | /// Open the file at 'filePath' and return Rappture Library Object. |
---|
21 | /** |
---|
22 | */ |
---|
23 | |
---|
24 | int rp_lib(const char* filePath, int filePath_len) { |
---|
25 | |
---|
26 | RpLibrary* lib = NULL; |
---|
27 | int handle = -1; |
---|
28 | std::string inFilePath = ""; |
---|
29 | |
---|
30 | inFilePath = null_terminate_str(filePath, filePath_len); |
---|
31 | |
---|
32 | // create a RapptureIO object and store in dictionary |
---|
33 | lib = new RpLibrary(inFilePath); |
---|
34 | |
---|
35 | if (lib) { |
---|
36 | handle = storeObject_Lib(lib); |
---|
37 | } |
---|
38 | |
---|
39 | return handle; |
---|
40 | } |
---|
41 | |
---|
42 | /**********************************************************************/ |
---|
43 | // FUNCTION: rp_lib_element_obj() |
---|
44 | /// Return the node located at 'path'. |
---|
45 | /** |
---|
46 | */ |
---|
47 | int rp_lib_element_obj(int* handle, /* integer handle of library */ |
---|
48 | char* path, /* null terminated path */ |
---|
49 | int path_len |
---|
50 | ) |
---|
51 | { |
---|
52 | int newObjHandle = -1; |
---|
53 | |
---|
54 | std::string inPath = ""; |
---|
55 | |
---|
56 | RpLibrary* lib = NULL; |
---|
57 | RpLibrary* retObj = NULL; |
---|
58 | |
---|
59 | inPath = null_terminate_str(path,path_len); |
---|
60 | |
---|
61 | if ((handle) && (*handle != 0)) { |
---|
62 | lib = getObject_Lib(*handle); |
---|
63 | if (lib) { |
---|
64 | retObj = lib->element(inPath); |
---|
65 | |
---|
66 | if (retObj) { |
---|
67 | newObjHandle = storeObject_Lib(retObj); |
---|
68 | } |
---|
69 | } |
---|
70 | } |
---|
71 | |
---|
72 | return newObjHandle; |
---|
73 | } |
---|
74 | |
---|
75 | /**********************************************************************/ |
---|
76 | // FUNCTION: rp_lib_element_comp() |
---|
77 | /// Return the component name of the node located at 'path'. |
---|
78 | /** |
---|
79 | */ |
---|
80 | void rp_lib_element_comp( int* handle, /* integer handle of library */ |
---|
81 | char* path, /* null terminated path */ |
---|
82 | char* retText, /* return buffer for fortran*/ |
---|
83 | int path_len, |
---|
84 | int retText_len /* length of return text buffer */ |
---|
85 | ) |
---|
86 | { |
---|
87 | std::string inPath = ""; |
---|
88 | RpLibrary* lib = NULL; |
---|
89 | std::string retStr = ""; |
---|
90 | |
---|
91 | inPath = null_terminate_str(path,path_len); |
---|
92 | |
---|
93 | lib = getObject_Lib(*handle); |
---|
94 | |
---|
95 | if (lib) { |
---|
96 | retStr = lib->element(inPath)->nodeComp(); |
---|
97 | if (!retStr.empty()) { |
---|
98 | fortranify(retStr.c_str(),retText,retText_len); |
---|
99 | } |
---|
100 | } |
---|
101 | |
---|
102 | } |
---|
103 | |
---|
104 | /**********************************************************************/ |
---|
105 | // FUNCTION: rp_lib_element_id() |
---|
106 | /// Return the 'id' of node located at 'path'. |
---|
107 | /** |
---|
108 | */ |
---|
109 | void rp_lib_element_id( int* handle, /* integer handle of library */ |
---|
110 | char* path, /* path of element within xml */ |
---|
111 | char* retText, /* return buffer for fortran */ |
---|
112 | int path_len, |
---|
113 | int retText_len /* length of return text buffer */ |
---|
114 | ) |
---|
115 | { |
---|
116 | std::string inPath = ""; |
---|
117 | RpLibrary* lib = NULL; |
---|
118 | std::string retStr = ""; |
---|
119 | |
---|
120 | inPath = null_terminate_str(path,path_len); |
---|
121 | |
---|
122 | lib = getObject_Lib(*handle); |
---|
123 | |
---|
124 | if (lib) { |
---|
125 | retStr = lib->element(inPath)->nodeId(); |
---|
126 | if (!retStr.empty()) { |
---|
127 | fortranify(retStr.c_str(),retText,retText_len); |
---|
128 | } |
---|
129 | } |
---|
130 | } |
---|
131 | |
---|
132 | /**********************************************************************/ |
---|
133 | // FUNCTION: rp_lib_element_type() |
---|
134 | /// Return the type of the node located at 'path'. |
---|
135 | /** |
---|
136 | */ |
---|
137 | void rp_lib_element_type( int* handle, /* integer handle of library */ |
---|
138 | char* path, /* search path inside xml */ |
---|
139 | char* retText, /* return buffer for fortran*/ |
---|
140 | int path_len, |
---|
141 | int retText_len /* length of return text buffer */ |
---|
142 | ) |
---|
143 | { |
---|
144 | std::string inPath = ""; |
---|
145 | RpLibrary* lib = NULL; |
---|
146 | std::string retStr = ""; |
---|
147 | |
---|
148 | inPath = null_terminate_str(path,path_len); |
---|
149 | |
---|
150 | lib = getObject_Lib(*handle); |
---|
151 | |
---|
152 | if (lib) { |
---|
153 | retStr = lib->element(inPath)->nodeType(); |
---|
154 | fortranify(retStr.c_str(),retText,retText_len); |
---|
155 | } |
---|
156 | } |
---|
157 | |
---|
158 | /**********************************************************************/ |
---|
159 | // FUNCTION: rp_lib_children(const char* filePath, int filePath_len) |
---|
160 | /// Retrieve the next child of 'path' from the Rappture Library Object. |
---|
161 | /** |
---|
162 | */ |
---|
163 | int rp_lib_children ( int* handle, /* integer handle of library */ |
---|
164 | char* path, /* search path of the xml */ |
---|
165 | int* childHandle, /*integer hanlde of last returned child*/ |
---|
166 | int path_len /* length of the search path buffer */ |
---|
167 | ) { |
---|
168 | |
---|
169 | std::string inPath = ""; |
---|
170 | RpLibrary* lib = NULL; |
---|
171 | RpLibrary* childNode = NULL; |
---|
172 | int newObjHandle = -1; |
---|
173 | |
---|
174 | inPath = null_terminate_str(path,path_len); |
---|
175 | |
---|
176 | if (handle && (*handle >= 0) ) { |
---|
177 | lib = getObject_Lib(*handle); |
---|
178 | if (lib) { |
---|
179 | if (*childHandle < 1) { |
---|
180 | // check to see if there were any previously returned children |
---|
181 | childNode = getObject_Lib(*childHandle); |
---|
182 | } |
---|
183 | |
---|
184 | // call the children base method |
---|
185 | childNode = lib->children(path,childNode); |
---|
186 | |
---|
187 | // store the childNode in the dictionary. |
---|
188 | // |
---|
189 | // because the base method is using static memory to get store the |
---|
190 | // children we should be able to chekc and see if the childHandle |
---|
191 | // was valud. |
---|
192 | // if so, then we can just return the childHandle back to the user |
---|
193 | // if not, store the object in the dictionary and return the new |
---|
194 | // handle. |
---|
195 | |
---|
196 | if (childNode) { |
---|
197 | if (*childHandle < 1) { |
---|
198 | newObjHandle = storeObject_Lib(childNode); |
---|
199 | } |
---|
200 | else { |
---|
201 | newObjHandle = *childHandle; |
---|
202 | } |
---|
203 | } |
---|
204 | } |
---|
205 | } |
---|
206 | |
---|
207 | return newObjHandle; |
---|
208 | |
---|
209 | } |
---|
210 | |
---|
211 | |
---|
212 | //int rp_lib_child_comp ( int* handle, /* integer handle of library */ |
---|
213 | // char* path, /* DOM path of requested object */ |
---|
214 | // char* type, /* specific name of element */ |
---|
215 | // int* childNum, /* child number for iteration */ |
---|
216 | // char* retText, /* buffer to store return text */ |
---|
217 | // int path_len, /* length of path */ |
---|
218 | // int type_len, /* length of type */ |
---|
219 | // int retText_len /* length of return text buffer */ |
---|
220 | // ) |
---|
221 | /* |
---|
222 | { |
---|
223 | int retVal = 0; |
---|
224 | |
---|
225 | char* inPath = NULL; |
---|
226 | char* inType = NULL; |
---|
227 | |
---|
228 | inPath = null_terminate(path,path_len); |
---|
229 | inType = null_terminate(type,type_len); |
---|
230 | |
---|
231 | if (inPath) { |
---|
232 | path_len = strlen(inPath) + 1; |
---|
233 | } |
---|
234 | else { |
---|
235 | path_len = 0; |
---|
236 | } |
---|
237 | |
---|
238 | if (inType) { |
---|
239 | type_len = strlen(inType) + 1; |
---|
240 | } |
---|
241 | else { |
---|
242 | type_len = 0; |
---|
243 | } |
---|
244 | |
---|
245 | retVal = rp_lib_child_str( handle, |
---|
246 | inPath, |
---|
247 | "component", |
---|
248 | inType, |
---|
249 | childNum, |
---|
250 | retText, |
---|
251 | path_len, |
---|
252 | 10, |
---|
253 | type_len, |
---|
254 | retText_len |
---|
255 | ); |
---|
256 | |
---|
257 | if (inPath) { |
---|
258 | free(inPath); |
---|
259 | inPath = NULL; |
---|
260 | } |
---|
261 | |
---|
262 | if (inType) { |
---|
263 | free(inType); |
---|
264 | inType = NULL; |
---|
265 | } |
---|
266 | |
---|
267 | return retVal; |
---|
268 | } |
---|
269 | */ |
---|
270 | |
---|
271 | //int rp_lib_child_id( int* handle, /* integer handle of library */ |
---|
272 | // char* path, /* DOM path of requested object */ |
---|
273 | // char* type, /* specific name of element */ |
---|
274 | // int* childNum, /* child number for iteration */ |
---|
275 | // char* retText, /* buffer to store return text */ |
---|
276 | // int path_len, /* length of path */ |
---|
277 | // int type_len, /* length of type */ |
---|
278 | // int retText_len /* length of return text buffer */ |
---|
279 | // ) |
---|
280 | /* |
---|
281 | { |
---|
282 | int retVal = 0; |
---|
283 | char* inPath = NULL; |
---|
284 | char* inType = NULL; |
---|
285 | |
---|
286 | inPath = null_terminate(path,path_len); |
---|
287 | inType = null_terminate(type,type_len); |
---|
288 | |
---|
289 | if (inPath) { |
---|
290 | path_len = strlen(inPath) + 1; |
---|
291 | } |
---|
292 | else { |
---|
293 | path_len = 0; |
---|
294 | } |
---|
295 | |
---|
296 | if (inType) { |
---|
297 | type_len = strlen(inType) + 1; |
---|
298 | } |
---|
299 | else { |
---|
300 | type_len = 0; |
---|
301 | } |
---|
302 | |
---|
303 | retVal = rp_lib_child_str( handle, |
---|
304 | inPath, |
---|
305 | "id", |
---|
306 | inType, |
---|
307 | childNum, |
---|
308 | retText, |
---|
309 | path_len, |
---|
310 | 3, |
---|
311 | type_len, |
---|
312 | retText_len |
---|
313 | ); |
---|
314 | |
---|
315 | if (inPath) { |
---|
316 | free(inPath); |
---|
317 | inPath = NULL; |
---|
318 | } |
---|
319 | |
---|
320 | if (inType) { |
---|
321 | free(inType); |
---|
322 | inType = NULL; |
---|
323 | } |
---|
324 | |
---|
325 | return retVal; |
---|
326 | } |
---|
327 | */ |
---|
328 | |
---|
329 | //int rp_lib_child_type ( int* handle, /* integer handle of library */ |
---|
330 | // char* path, /* DOM path of requested object */ |
---|
331 | // char* type, /* specific name of element */ |
---|
332 | // int* childNum, /* child number for iteration */ |
---|
333 | // char* retText, /* buffer to store return text */ |
---|
334 | // int path_len, /* length of path */ |
---|
335 | // int type_len, /* length of type */ |
---|
336 | // int retText_len /* length of return text buffer */ |
---|
337 | // ) |
---|
338 | /* |
---|
339 | { |
---|
340 | int retVal = 0; |
---|
341 | char* inPath = NULL; |
---|
342 | char* inType = NULL; |
---|
343 | |
---|
344 | inPath = null_terminate(path,path_len); |
---|
345 | inType = null_terminate(type,type_len); |
---|
346 | |
---|
347 | if (inPath) { |
---|
348 | path_len = strlen(inPath) + 1; |
---|
349 | } |
---|
350 | else { |
---|
351 | path_len = 0; |
---|
352 | } |
---|
353 | |
---|
354 | if (inType) { |
---|
355 | type_len = strlen(inType) + 1; |
---|
356 | } |
---|
357 | else { |
---|
358 | type_len = 0; |
---|
359 | } |
---|
360 | |
---|
361 | retVal = rp_lib_child_str( handle, |
---|
362 | inPath, |
---|
363 | "type", |
---|
364 | inType, |
---|
365 | childNum, |
---|
366 | retText, |
---|
367 | path_len, |
---|
368 | 5, |
---|
369 | type_len, |
---|
370 | retText_len |
---|
371 | ); |
---|
372 | |
---|
373 | if (inPath) { |
---|
374 | free(inPath); |
---|
375 | inPath = NULL; |
---|
376 | } |
---|
377 | |
---|
378 | if (inType) { |
---|
379 | free(inType); |
---|
380 | inType = NULL; |
---|
381 | } |
---|
382 | |
---|
383 | return retVal; |
---|
384 | } |
---|
385 | */ |
---|
386 | |
---|
387 | /* |
---|
388 | int rp_lib_child_obj ( int* handle, |
---|
389 | char* path, |
---|
390 | char* type, |
---|
391 | int path_len, |
---|
392 | int type_len |
---|
393 | ) |
---|
394 | { |
---|
395 | int newObjHandle = -1; |
---|
396 | |
---|
397 | PyObject* lib = NULL; |
---|
398 | PyObject* list = NULL; |
---|
399 | |
---|
400 | char* inPath = NULL; |
---|
401 | char* inType = NULL; |
---|
402 | |
---|
403 | inPath = null_terminate(path,path_len); |
---|
404 | inType = null_terminate(type,type_len); |
---|
405 | |
---|
406 | if (rapptureStarted) { |
---|
407 | if ((handle) && (*handle != 0)) { |
---|
408 | lib = getObject_Lib(*handle); |
---|
409 | |
---|
410 | if (lib) { |
---|
411 | list = rpChildren_f(lib, inPath, "object"); |
---|
412 | if (list) { |
---|
413 | // store the whole list, |
---|
414 | // need to make a way to read the nodes |
---|
415 | newObjHandle = storeObject_Lib(list); |
---|
416 | // Py_DECREF(list); |
---|
417 | } |
---|
418 | else { |
---|
419 | |
---|
420 | } |
---|
421 | } |
---|
422 | } |
---|
423 | } |
---|
424 | |
---|
425 | if (inPath) { |
---|
426 | free(inPath); |
---|
427 | inPath = NULL; |
---|
428 | } |
---|
429 | |
---|
430 | if (inType) { |
---|
431 | free(inType); |
---|
432 | inType = NULL; |
---|
433 | } |
---|
434 | |
---|
435 | return newObjHandle; |
---|
436 | |
---|
437 | } |
---|
438 | */ |
---|
439 | |
---|
440 | /**********************************************************************/ |
---|
441 | // FUNCTION: rp_lib() |
---|
442 | /// Get data located at 'path' and return it as a string value. |
---|
443 | /** |
---|
444 | */ |
---|
445 | void rp_lib_get( int* handle, /* integer handle of library */ |
---|
446 | char* path, /* null terminated path */ |
---|
447 | char* retText, /* return text buffer for fortran*/ |
---|
448 | int path_len, |
---|
449 | int retText_len /* length of return text buffer */ |
---|
450 | ) |
---|
451 | { |
---|
452 | std::string xmlText = ""; |
---|
453 | |
---|
454 | RpLibrary* lib = NULL; |
---|
455 | |
---|
456 | std::string inPath = ""; |
---|
457 | |
---|
458 | inPath = null_terminate_str(path,path_len); |
---|
459 | |
---|
460 | if ((handle) && (*handle != 0)) { |
---|
461 | lib = getObject_Lib(*handle); |
---|
462 | |
---|
463 | if (lib) { |
---|
464 | xmlText = lib->getString(inPath); |
---|
465 | if (!xmlText.empty()) { |
---|
466 | fortranify(xmlText.c_str(),retText,retText_len); |
---|
467 | } |
---|
468 | |
---|
469 | } |
---|
470 | } |
---|
471 | } |
---|
472 | |
---|
473 | /**********************************************************************/ |
---|
474 | // FUNCTION: rp_lib_get_double() |
---|
475 | /// Get data located at 'path' and return it as a double precision value. |
---|
476 | /** |
---|
477 | */ |
---|
478 | double rp_lib_get_double( int* handle, /* integer handle of library */ |
---|
479 | char* path, /* null terminated path */ |
---|
480 | int path_len |
---|
481 | ) |
---|
482 | { |
---|
483 | double retVal = 0.0; |
---|
484 | |
---|
485 | RpLibrary* lib = NULL; |
---|
486 | |
---|
487 | std::string inPath = ""; |
---|
488 | |
---|
489 | inPath = null_terminate_str(path,path_len); |
---|
490 | |
---|
491 | if ((handle) && (*handle != 0)) { |
---|
492 | lib = getObject_Lib(*handle); |
---|
493 | |
---|
494 | if (lib) { |
---|
495 | retVal = lib->getDouble(inPath); |
---|
496 | } |
---|
497 | } |
---|
498 | |
---|
499 | return retVal; |
---|
500 | } |
---|
501 | |
---|
502 | |
---|
503 | /**********************************************************************/ |
---|
504 | // FUNCTION: rp_lib_put_str() |
---|
505 | /// Put string into Rappture Library Object at location 'path'. |
---|
506 | /** |
---|
507 | */ |
---|
508 | void rp_lib_put_str( int* handle, |
---|
509 | char* path, |
---|
510 | char* value, |
---|
511 | int* append, |
---|
512 | int path_len, |
---|
513 | int value_len |
---|
514 | ) |
---|
515 | { |
---|
516 | std::string inPath = ""; |
---|
517 | std::string inValue = ""; |
---|
518 | RpLibrary* lib = NULL; |
---|
519 | |
---|
520 | inPath = null_terminate_str(path,path_len); |
---|
521 | inValue = null_terminate_str(value,value_len); |
---|
522 | |
---|
523 | if ((handle) && (*handle != 0)) { |
---|
524 | lib = getObject_Lib(*handle); |
---|
525 | |
---|
526 | if (lib) { |
---|
527 | lib->put(inPath,inValue,"",*append); |
---|
528 | } |
---|
529 | } |
---|
530 | |
---|
531 | return; |
---|
532 | |
---|
533 | } |
---|
534 | |
---|
535 | |
---|
536 | /**********************************************************************/ |
---|
537 | // FUNCTION: rp_lib_put_id_str() |
---|
538 | /// Put string into Rappture Library Object at location 'path' with id = 'id' |
---|
539 | /** |
---|
540 | */ |
---|
541 | void rp_lib_put_id_str ( int* handle, |
---|
542 | char* path, |
---|
543 | char* value, |
---|
544 | char* id, |
---|
545 | int* append, |
---|
546 | int path_len, |
---|
547 | int value_len, |
---|
548 | int id_len |
---|
549 | ) |
---|
550 | { |
---|
551 | RpLibrary* lib = NULL; |
---|
552 | |
---|
553 | std::string inPath = ""; |
---|
554 | std::string inValue = ""; |
---|
555 | std::string inId = ""; |
---|
556 | |
---|
557 | inPath = null_terminate_str(path,path_len); |
---|
558 | inValue = null_terminate_str(value,value_len); |
---|
559 | inId = null_terminate_str(id,id_len); |
---|
560 | |
---|
561 | if ((handle) && (*handle != 0)) { |
---|
562 | lib = getObject_Lib(*handle); |
---|
563 | |
---|
564 | if (lib) { |
---|
565 | lib->put(inPath,inValue,inId,*append); |
---|
566 | } |
---|
567 | } |
---|
568 | |
---|
569 | } |
---|
570 | |
---|
571 | //void rp_lib_put_obj( int* handle, |
---|
572 | // char* path, |
---|
573 | // int* valHandle, |
---|
574 | // int* append, |
---|
575 | // int path_len |
---|
576 | // ) |
---|
577 | //{ |
---|
578 | // std::string inPath = ""; |
---|
579 | // RpLibrary* lib = NULL; |
---|
580 | // |
---|
581 | // // inPath = null_terminate(path,path_len); |
---|
582 | // inPath = std::string(path,path_len); |
---|
583 | // |
---|
584 | // /* |
---|
585 | // if (inPath) { |
---|
586 | // path_len = strlen(inPath) + 1; |
---|
587 | // } |
---|
588 | // */ |
---|
589 | // |
---|
590 | // if ((handle) && (*handle != 0)) { |
---|
591 | // lib = getObject_Lib(*handle); |
---|
592 | // |
---|
593 | // if (lib) { |
---|
594 | // // rpPut(lib, inPath, inValue, inId, *append); |
---|
595 | // lib->put(inPath,inValue,"",*append); |
---|
596 | // } |
---|
597 | // } |
---|
598 | // |
---|
599 | // /* |
---|
600 | // rp_lib_put_id_obj(handle,inPath,valHandle,NULL,append,path_len,0); |
---|
601 | // |
---|
602 | // if (inPath) { |
---|
603 | // free(inPath); |
---|
604 | // inPath = NULL; |
---|
605 | // } |
---|
606 | // */ |
---|
607 | // |
---|
608 | //} |
---|
609 | |
---|
610 | /* |
---|
611 | void rp_lib_put_id_obj ( int* handle, |
---|
612 | char* path, |
---|
613 | int* valHandle, |
---|
614 | char* id, |
---|
615 | int* append, |
---|
616 | int path_len, |
---|
617 | int id_len |
---|
618 | ) |
---|
619 | { |
---|
620 | PyObject* lib = NULL; |
---|
621 | PyObject* value = NULL; |
---|
622 | |
---|
623 | char* inPath = NULL; |
---|
624 | char* inId = NULL; |
---|
625 | |
---|
626 | inPath = null_terminate(path,path_len); |
---|
627 | inId = null_terminate(id,id_len); |
---|
628 | |
---|
629 | if (rapptureStarted) { |
---|
630 | if ((handle) && (*handle != 0)) { |
---|
631 | lib = getObject_Lib(*handle); |
---|
632 | value = getObject_Lib(*valHandle); |
---|
633 | |
---|
634 | if (lib && value) { |
---|
635 | // retObj is a borrowed object |
---|
636 | // whose contents must not be modified |
---|
637 | rpPutObj(lib, inPath, value, inId, *append); |
---|
638 | } |
---|
639 | } |
---|
640 | } |
---|
641 | |
---|
642 | if (inPath) { |
---|
643 | free(inPath); |
---|
644 | inPath = NULL; |
---|
645 | } |
---|
646 | |
---|
647 | if (inId) { |
---|
648 | free(inId); |
---|
649 | inId = NULL; |
---|
650 | } |
---|
651 | |
---|
652 | } |
---|
653 | */ |
---|
654 | |
---|
655 | /* |
---|
656 | int rp_lib_remove (int* handle, char* path, int path_len) |
---|
657 | { |
---|
658 | int newObjHandle = -1; |
---|
659 | |
---|
660 | PyObject* lib = NULL; |
---|
661 | PyObject* removedObj = NULL; |
---|
662 | |
---|
663 | char* inPath = NULL; |
---|
664 | |
---|
665 | inPath = null_terminate(path,path_len); |
---|
666 | |
---|
667 | if (rapptureStarted) { |
---|
668 | if ((handle) && (*handle != 0)) { |
---|
669 | lib = getObject_Lib(*handle); |
---|
670 | |
---|
671 | if (lib) { |
---|
672 | removedObj = rpRemove(lib, inPath); |
---|
673 | |
---|
674 | if (removedObj) { |
---|
675 | newObjHandle = storeObject_Lib(removedObj); |
---|
676 | // Py_DECREF(removedObj); |
---|
677 | } |
---|
678 | |
---|
679 | } |
---|
680 | } |
---|
681 | } |
---|
682 | |
---|
683 | if (inPath) { |
---|
684 | free(inPath); |
---|
685 | inPath = NULL; |
---|
686 | } |
---|
687 | |
---|
688 | return newObjHandle; |
---|
689 | } |
---|
690 | */ |
---|
691 | |
---|
692 | /* |
---|
693 | int rp_lib_xml_len (int* handle) |
---|
694 | { |
---|
695 | int length = -1; |
---|
696 | char* xmlText = NULL; |
---|
697 | |
---|
698 | PyObject* lib = NULL; |
---|
699 | |
---|
700 | if (rapptureStarted) { |
---|
701 | if ((handle) && (*handle != 0)) { |
---|
702 | lib = getObject_Lib(*handle); |
---|
703 | |
---|
704 | if (lib) { |
---|
705 | // dont modify xmlText, borrowed pointer |
---|
706 | xmlText = rpXml(lib); |
---|
707 | |
---|
708 | if (xmlText) { |
---|
709 | length = strlen(xmlText) + 1; |
---|
710 | free(xmlText); |
---|
711 | // printf("len = :%d:\n",length); |
---|
712 | } |
---|
713 | } |
---|
714 | } |
---|
715 | } |
---|
716 | return length; |
---|
717 | } |
---|
718 | */ |
---|
719 | |
---|
720 | /**********************************************************************/ |
---|
721 | // FUNCTION: rp_lib_write_xml() |
---|
722 | /// Write the xml text into a file. |
---|
723 | /** |
---|
724 | * \sa {rp_result} |
---|
725 | */ |
---|
726 | int rp_lib_write_xml(int* handle, char* outFile, int outFile_len) |
---|
727 | { |
---|
728 | int retVal = -1; |
---|
729 | RpLibrary* lib = NULL; |
---|
730 | std::string inOutFile = ""; |
---|
731 | std::string xmlText = ""; |
---|
732 | std::fstream file; |
---|
733 | |
---|
734 | inOutFile = null_terminate_str(outFile, outFile_len); |
---|
735 | |
---|
736 | if (!inOutFile.empty() ) { |
---|
737 | file.open(inOutFile.c_str(),std::ios::out); |
---|
738 | } |
---|
739 | |
---|
740 | if ( file.is_open() ) { |
---|
741 | if ((handle) && (*handle != 0)) { |
---|
742 | lib = getObject_Lib(*handle); |
---|
743 | |
---|
744 | if (lib) { |
---|
745 | xmlText = lib->xml(); |
---|
746 | if (!xmlText.empty()) { |
---|
747 | file << xmlText; |
---|
748 | retVal = 0; |
---|
749 | } |
---|
750 | } |
---|
751 | } |
---|
752 | |
---|
753 | file.close(); |
---|
754 | } |
---|
755 | |
---|
756 | return retVal; |
---|
757 | } |
---|
758 | |
---|
759 | /**********************************************************************/ |
---|
760 | // FUNCTION: rp_lib_xml() |
---|
761 | /// Return this node's xml text |
---|
762 | /** |
---|
763 | */ |
---|
764 | void rp_lib_xml(int* handle, char* retText, int retText_len) |
---|
765 | { |
---|
766 | std::string xmlText = ""; |
---|
767 | |
---|
768 | RpLibrary* lib = NULL; |
---|
769 | |
---|
770 | if ((handle) && (*handle != 0)) { |
---|
771 | lib = getObject_Lib(*handle); |
---|
772 | |
---|
773 | if (lib) { |
---|
774 | xmlText = lib->xml(); |
---|
775 | if (!xmlText.empty()) { |
---|
776 | fortranify(xmlText.c_str(), retText, retText_len); |
---|
777 | } |
---|
778 | } |
---|
779 | } |
---|
780 | } |
---|
781 | |
---|
782 | /**********************************************************************/ |
---|
783 | // FUNCTION: rp_lib_node_comp() |
---|
784 | /// Return this node's component name |
---|
785 | /** |
---|
786 | */ |
---|
787 | void rp_lib_node_comp ( int* handle, char* retText, int retText_len ) { |
---|
788 | |
---|
789 | std::string retStr = ""; |
---|
790 | RpLibrary* node = NULL; |
---|
791 | |
---|
792 | if ((handle) && (*handle != 0)) { |
---|
793 | node = getObject_Lib(*handle); |
---|
794 | |
---|
795 | if (node) { |
---|
796 | retStr = node->nodeComp(); |
---|
797 | if (!retStr.empty()) { |
---|
798 | fortranify(retStr.c_str(), retText, retText_len); |
---|
799 | } |
---|
800 | } |
---|
801 | } |
---|
802 | } |
---|
803 | |
---|
804 | /**********************************************************************/ |
---|
805 | // FUNCTION: rp_lib_node_type() |
---|
806 | /// Return this node's type |
---|
807 | /** |
---|
808 | */ |
---|
809 | void rp_lib_node_type ( int* handle, char* retText, int retText_len ) { |
---|
810 | |
---|
811 | std::string retStr = ""; |
---|
812 | RpLibrary* node = NULL; |
---|
813 | |
---|
814 | if ((handle) && (*handle != 0)) { |
---|
815 | node = getObject_Lib(*handle); |
---|
816 | |
---|
817 | if (node) { |
---|
818 | retStr = node->nodeType(); |
---|
819 | if (!retStr.empty()) { |
---|
820 | fortranify(retStr.c_str(), retText, retText_len); |
---|
821 | } |
---|
822 | } |
---|
823 | } |
---|
824 | } |
---|
825 | |
---|
826 | /**********************************************************************/ |
---|
827 | // FUNCTION: rp_lib_node_id() |
---|
828 | /// Return this node's id. |
---|
829 | /** |
---|
830 | */ |
---|
831 | void rp_lib_node_id ( int* handle, char* retText, int retText_len ) { |
---|
832 | |
---|
833 | std::string retStr = ""; |
---|
834 | RpLibrary* node = NULL; |
---|
835 | |
---|
836 | if ((handle) && (*handle != 0)) { |
---|
837 | node = getObject_Lib(*handle); |
---|
838 | |
---|
839 | if (node) { |
---|
840 | retStr = node->nodeId(); |
---|
841 | if (!retStr.empty()) { |
---|
842 | fortranify(retStr.c_str(), retText, retText_len); |
---|
843 | } |
---|
844 | } |
---|
845 | } |
---|
846 | } |
---|
847 | |
---|
848 | /**********************************************************************/ |
---|
849 | // FUNCTION: rp_result() |
---|
850 | /// Write xml text to a run.xml file and signal the program has completed |
---|
851 | /** |
---|
852 | */ |
---|
853 | void rp_result(int* handle) { |
---|
854 | RpLibrary* lib = NULL; |
---|
855 | |
---|
856 | if (handle && *handle != 0) { |
---|
857 | lib = getObject_Lib(*handle); |
---|
858 | if (lib) { |
---|
859 | lib->result(); |
---|
860 | } |
---|
861 | } |
---|
862 | |
---|
863 | // do no delete this, still working on testing this |
---|
864 | cleanLibDict(); |
---|
865 | } |
---|
866 | |
---|