source: trunk/src/core/RpLibrary.cc @ 589

Last change on this file since 589 was 589, checked in by dkearney, 18 years ago

added c bindings to the putData and putFile functions
added example usage of putFile for c++ and c with example dx file
adjusted append flag from int to unsigned int on all c rpPut functions
adjusted a tcl units test

  • Property svn:keywords set to Date Rev URL
File size: 49.6 KB
Line 
1/*
2 * ----------------------------------------------------------------------
3 *  Rappture Library Source
4 *
5 * ======================================================================
6 *  AUTHOR:  Derrick Kearney, Purdue University
7 *  Copyright (c) 2004-2007  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 "RpLibrary.h"
15#include "RpEntityRef.h"
16
17static RpEntityRef ERTranslator;
18
19/**********************************************************************/
20// METHOD: _get_attribute()
21/// Return the attribute value matching the provided attribute name.
22/**
23 */
24
25std::string
26RpLibrary::_get_attribute(scew_element* element, std::string attributeName)
27{
28    scew_attribute* attribute = NULL;
29    std::string attrVal;
30    // int attrValSize = 0;
31
32    if (element != NULL)
33    {
34        if (scew_attribute_count(element) > 0) {
35
36            while((attribute=scew_attribute_next(element, attribute)) != NULL)
37            {
38                if (    strcmp( scew_attribute_name(attribute),
39                                attributeName.c_str()) == 0     ){
40                    attrVal = scew_attribute_value(attribute);
41                }
42            }
43        }
44        else {
45            // there are no attributes, count == 0
46        }
47    }
48
49    return attrVal;
50}
51
52/**********************************************************************/
53// METHOD: _path2list()
54/// Convert a path into a list of element names.
55/**
56 */
57
58int
59RpLibrary::_path2list (std::string& path, std::string** list, int listLen)
60{
61    std::string::size_type pos = 0;
62    std::string::size_type start = 0;
63    std::string::size_type end = path.length();
64    int index = 0;
65    int retVal = 0;
66    unsigned int parenDepth = 0;
67
68    for (   pos = 0; (pos < end) && (index < listLen); pos++) {
69        if (path[pos] == '(') {
70            parenDepth++;
71            continue;
72        }
73
74        if (path[pos] == ')') {
75            parenDepth--;
76            continue;
77        }
78
79        if ( (path[pos] == '.') && (parenDepth == 0) ) {
80            list[index] = new std::string(path.substr(start,pos-start));
81            index++;
82            start = pos + 1;
83        }
84    }
85
86    // add the last path to the list
87    // error checking for path names like p1.p2.
88    if ( (start < end) && (pos == end) ) {
89        list[index] = new std::string(path.substr(start,pos-start));
90    }
91    retVal = index;
92    index++;
93
94    // null out the rest of the pointers so we know where to stop free'ing
95    while (index < listLen) {
96        list[index++] = NULL;
97    }
98
99    return retVal;
100}
101
102/**********************************************************************/
103// METHOD: _node2name()
104/// Retrieve the id of a node.
105/**
106 */
107
108std::string
109RpLibrary::_node2name (scew_element* node)
110{
111    // XML_Char const* name = _get_attribute(node,"id");
112    std::string name = _get_attribute(node,"id");
113    std::stringstream retVal;
114    XML_Char const* type = NULL;
115    scew_element* parent = NULL;
116    scew_element** siblings = NULL;
117    unsigned int count = 0;
118    int tmpCount = 0;
119    int index = 0;
120    std::string indexStr;
121
122    type = scew_element_name(node);
123    parent = scew_element_parent(node);
124
125    if (parent) {
126
127        // if (name == NULL) {
128        if (name.empty()) {
129            siblings = scew_element_list(parent, type, &count);
130            if (count > 0) {
131                tmpCount = count;
132                while ((index < tmpCount) && (siblings[index] != node)) {
133                    index++;
134                }
135
136                if (index < tmpCount) {
137
138                    if (index > 0) {
139
140                        retVal << type << --index;
141                    }
142                    else {
143
144                        retVal << type;
145                    }
146
147                    /*
148                    if (retVal == NULL) {
149                        // error with allocating space
150                        return NULL;
151                    }
152                    */
153                }
154            }
155
156            scew_element_list_free(siblings);
157
158        }
159        else {
160
161            retVal << name;
162        }
163    }
164
165    return (retVal.str());
166}
167
168/**********************************************************************/
169// METHOD: _node2comp()
170/// Retrieve the component name of a node
171/**
172 */
173
174std::string
175RpLibrary::_node2comp (scew_element* node)
176{
177    // XML_Char const* name = _get_attribute(node,"id");
178    std::string id = _get_attribute(node,"id");
179    std::stringstream retVal;
180    XML_Char const* type = NULL;
181    scew_element* parent = NULL;
182    scew_element** siblings = NULL;
183    unsigned int count = 0;
184    int tmpCount = 0;
185    int index = 0;
186    std::string indexStr;
187
188    type = scew_element_name(node);
189    parent = scew_element_parent(node);
190
191    if (parent) {
192        if (id.empty()) {
193            siblings = scew_element_list(parent, type, &count);
194            if (count > 0) {
195                tmpCount = count;
196                // figure out what the index value should be
197                while ((index < tmpCount) && (siblings[index] != node)) {
198                    index++;
199                }
200
201                if (index < tmpCount) {
202                    if (index > 0) {
203                        // retVal << type << --index;
204                        retVal << type << index;
205                    }
206                    else {
207                        retVal << type;
208                    }
209                }
210
211            }
212            else {
213                // count == 0 ??? this state should never be reached
214            }
215            scew_element_list_free(siblings);
216
217        }
218        else {
219            // node has attribute id
220            retVal << type << "(" << id << ")";
221
222        }
223    }
224
225    return (retVal.str());
226}
227
228/**********************************************************************/
229// METHOD: _node2path()
230/// Retrieve the full path name of a node
231/**
232 */
233
234std::string
235RpLibrary::_node2path (scew_element* node)
236{
237
238    std::stringstream path;
239    scew_element* snode = node;
240    scew_element* parent = NULL;
241
242    if (snode) {
243        parent = scew_element_parent(snode);
244        path.clear();
245
246        while (snode && parent) {
247
248            if (!path.str().empty()) {
249                path.str(_node2comp(snode) + "." + path.str());
250                // path.str("." + _node2comp(snode) + path.str());
251            }
252            else {
253                path.str(_node2comp(snode));
254                // path.str("." + _node2comp(snode));
255            }
256
257            snode = scew_element_parent(snode);
258            parent = scew_element_parent(snode);
259        }
260    }
261
262    return (path.str());
263}
264
265/**********************************************************************/
266// METHOD: _splitPath()
267/// Split a path (component) name into its tag name, index, and id
268/**
269 */
270
271int
272RpLibrary::_splitPath (std::string& path, std::string& tagName, int* idx, std::string& id )
273{
274    int stop = 0;
275    int start = 0;
276    int index = path.length();
277
278    if (index) {
279        index--;
280    }
281
282    if (!path.empty()) {
283        if (path[index] == ')') {
284            stop = index;
285            while (path[index] != '(') {
286                index--;
287            }
288            start = index+1;
289            // strncpy(id,path+start,stop-start);
290            // id = new std::string(path.substr(start,stop-start));
291            id = path.substr(start,stop-start);
292            index--;
293        }
294        if (isdigit(path[index])) {
295            stop = index;
296            while (isdigit(path[index])) {
297                index--;
298            }
299            // sscanf(path[index+1],"%d",idx);
300            sscanf(path.c_str()+index+1,"%d",idx);
301        }
302        if (isalpha(path[index])) {
303            start = 0;
304            stop = index+1;
305            // tagName = new std::string(path.substr(start,stop-start));
306            tagName = path.substr(start,stop-start);
307            // strncpy(tagName,path+start,stop-start);
308        }
309    }
310    else {
311        tagName = "";
312        *idx = 0;
313        id = "";
314    }
315
316    return 1;
317}
318
319/**********************************************************************/
320// METHOD: _find()
321/// Find or create a node and return it.
322/**
323 */
324
325scew_element*
326RpLibrary::_find(std::string path, int create)
327{
328    // std::string* tagName;
329    // std::string* id;
330    std::string tagName = "";
331    std::string id = "";
332    int index = 0;
333    int listLen = (path.length()/2)+1;
334    std::string** list;
335    int path_size = 0;
336    int listIdx = 0;
337    unsigned int count = 0;
338    int tmpCount = 0;
339    int lcv = 0;
340    std::string tmpId;
341
342    scew_element* tmpElement = this->root;
343    scew_element* node = NULL;
344    scew_element** eleList = NULL;
345
346
347    if (path.empty()) {
348        //user gave an empty path
349        // return this;
350        return tmpElement;
351    }
352
353    list = (std::string **) calloc(listLen, sizeof( std::string * ) );
354
355    if (!list) {
356        // error calloc'ing space for list
357        return NULL;
358    }
359
360    path_size = _path2list (path,list,listLen);
361
362    while ( (listIdx <= path_size) && (tmpElement != NULL ) ){
363
364        _splitPath(*(list[listIdx]),tagName,&index,id);
365
366        // if (id->empty()) {
367        if (id.empty()) {
368            /*
369            # If the name is like "type2", then look for elements with
370            # the type name and return the one with the given index.
371            # If the name is like "type", then assume the index is 0.
372            */
373
374            // eleList = scew_element_list(tmpElement, tagName->c_str(), &count);
375            eleList = scew_element_list(tmpElement, tagName.c_str(), &count);
376            tmpCount = count;
377            if (index < tmpCount) {
378                node = eleList[index];
379            }
380            else {
381                /* there is no element with the specified index */
382                node = NULL;
383            }
384
385            scew_element_list_free(eleList);
386            eleList = NULL;
387        }
388        else {
389
390            /* what if its like type2(id) ? */
391            /* still unresolved */
392
393            /*
394            # If the name is like "type(id)", then look for elements
395            # that match the type and see if one has the requested name.
396            # if the name is like "(id)", then look for any elements
397            # with the requested name.
398            */
399
400            // eleList = scew_element_list(tmpElement, tagName->c_str(), &count);
401            if (!tagName.empty()) {
402                eleList = scew_element_list(tmpElement, tagName.c_str(), &count);
403            }
404            else {
405                eleList = scew_element_list_all(tmpElement, &count);
406            }
407
408            tmpCount = count;
409            for (lcv = 0; (lcv < tmpCount); lcv++) {
410                tmpId = _get_attribute(eleList[lcv], "id");
411                if (!tmpId.empty()) {
412                    // if (*id == tmpId) {
413                    if (id == tmpId) {
414                        node = eleList[lcv];
415                        break;
416                    }
417                }
418            }
419
420            if (lcv >= tmpCount) {
421                node = NULL;
422            }
423
424            scew_element_list_free(eleList);
425            eleList = NULL;
426
427        }
428
429        if (node == NULL) {
430            if (create == NO_CREATE_PATH) {
431                // break out instead of returning because we still need to
432                // free the list variable
433                // return node;
434                tmpElement = node;
435                break;
436            }
437            else {
438                // create == CREATE_PATH
439                // we should create the rest of the path
440
441                // create the new element
442                // need to figure out how to properly number the new element
443                // node = scew_element_add(tmpElement,tagName->c_str());
444                node = scew_element_add(tmpElement,tagName.c_str());
445                if (! node) {
446                    // a new element was not created
447                }
448
449                // add an attribute and attrValue to the new element
450                // if (id && !id->empty()) {
451                    // scew_element_add_attr_pair(node,"id",id->c_str());
452                if (!id.empty()) {
453                    scew_element_add_attr_pair(node,"id",id.c_str());
454                }
455            }
456        }
457
458
459        // change this so youre not allocating and deallocating so much.
460        // make it static or something.
461        // if (tagName)    { delete (tagName); }
462        // if (id)         { delete (id); }
463        tagName = "";
464        id = "";
465        index = 0;
466        tmpElement = node;
467        listIdx++;
468    }
469
470    // need to free the strings inside of list
471
472    if (list) {
473        for (listIdx = 0; listIdx < listLen; listIdx++) {
474            if (list[listIdx]) {
475                delete(list[listIdx]);
476                list[listIdx] = NULL;
477            }
478        }
479
480        free(list);
481        list = NULL;
482    }
483
484
485    return tmpElement;
486}
487
488
489/**********************************************************************/
490// METHOD: element()
491/// Search the path of a xml tree and return a RpLibrary node.
492/**
493 * It is the user's responsibility to delete the object when
494 * they are finished using it?, else i need to make this static
495 */
496
497RpLibrary*
498RpLibrary::element (std::string path)
499{
500    RpLibrary* retLib = NULL;
501    scew_element* retNode = NULL;
502
503    if (!this->root) {
504        // library doesn't exist, do nothing;
505        return NULL;
506    }
507
508    /*
509    if (path.empty()) {
510        // an empty path returns the current RpLibrary
511        return this;
512    }
513    */
514
515    if (path.empty()) {
516        // this should be a smart pointer,
517        // if someone deletes the original this->root, this object is void
518        // and will be a memory leak.
519        // retNode = this->root;
520        retLib = new RpLibrary(*this);
521    }
522    else {
523        // get the node located at path
524        retNode = _find(path,NO_CREATE_PATH);
525
526        // if the node exists, create a rappture library object for it.
527        if (retNode) {
528            retLib = new RpLibrary( retNode,this->tree );
529        }
530    }
531
532    return retLib;
533}
534
535/**********************************************************************/
536// METHOD: entities()
537/// Search the path of a xml tree and return a list of its entities.
538/**
539 */
540
541std::list<std::string>
542RpLibrary::entities  (std::string path)
543{
544    std::list<std::string> queue;
545    std::list<std::string>::iterator iter;
546    std::list<std::string> retList;
547    std::list<std::string> childList;
548    std::list<std::string>::iterator childIter;
549
550    RpLibrary* ele = NULL;
551    std::string pathBack = "";
552
553    RpLibrary* child = NULL;
554    std::string childType = "";
555    std::string childPath = "";
556    std::string paramsPath = "";
557
558    RpLibrary* cchild = NULL;
559    std::string cchildType = "";
560    std::string cchildPath = "";
561
562    queue.push_back(path);
563    iter = queue.begin();
564
565    while( iter != queue.end() ) {
566        ele = this->element(*iter);
567        child = NULL;
568
569        if ((*iter).empty()) {
570            pathBack = "";
571        }
572        else {
573            pathBack = *iter + ".";
574        }
575
576        while ( ele && (child = ele->children("",child)) != NULL ) {
577            childList.push_back(child->nodeComp());
578            delete child;
579        }
580
581        childIter = childList.begin();
582
583        while (childIter != childList.end()) {
584            child = ele->element(*childIter);
585
586            childType = child->nodeType();
587            childPath = child->nodeComp();
588            if ( (childType == "group") || (childType == "phase") ) {
589                // add this path to the queue for paths to search
590                queue.push_back(pathBack+childPath);
591            }
592            else if (childType == "structure") {
593                // add this path to the return list
594                retList.push_back(pathBack+child->nodeComp());
595
596                // check to see if there is a ".current.parameters" node
597                // if so, add them to the queue list for paths to search
598                paramsPath = "current.parameters";
599                if (child->element(paramsPath) != NULL) {
600                    queue.push_back((pathBack+child->nodeComp()+"."+paramsPath));
601                }
602            }
603            else {
604                // add this path to the return list
605                retList.push_back(pathBack+child->nodeComp());
606
607                // look for embedded groups and phases
608                // add them to the queue list for paths to search
609                cchild = NULL;
610                while ( (cchild = child->children("",cchild)) != NULL ) {
611                    cchildType = cchild->nodeType();
612                    cchildPath = cchild->nodePath();
613                    if ( (cchildType == "group") || (cchildType == "phase") ) {
614                        // add this path to the queue for paths to search
615                        queue.push_back(cchildPath);
616                    }
617                    delete cchild;
618                }
619            }
620
621            childList.erase(childIter);
622            childIter = childList.begin();
623            delete child;
624        }
625
626        queue.erase(iter);
627        iter = queue.begin();
628    }
629
630    return retList;
631}
632
633/**********************************************************************/
634// METHOD: diff()
635/// find the differences between two xml trees.
636/**
637 */
638
639std::list<std::string>
640RpLibrary::diff (RpLibrary* otherLib, std::string path)
641{
642
643    std::list<std::string> thisVal; // two node list of specific entity's value
644    std::list<std::string> otherVal; // two node list of specific entity's value
645
646    std::list<std::string> thisv; // list of this library's entities
647    std::list<std::string>::iterator thisIter;
648
649    std::list<std::string> otherv; // list of other library's entities
650    std::list<std::string>::iterator otherIter;
651
652    std::list<std::string> retList;
653
654    std::string entry = "";
655    std::string thisSpath = "";  // temp string
656    std::string otherSpath = ""; // temp string
657
658    if ( (!this->root) || (!otherLib->root) ) {
659        // library doesn't exist, do nothing;
660        return retList;
661    }
662
663
664    thisv = this->entities(path);
665    otherv = otherLib->entities(path);
666
667    thisIter = thisv.begin();
668
669    while (thisIter != thisv.end() ) {
670        // reset otherIter for a new search.
671        otherIter = otherv.begin();
672        while ( (otherIter != otherv.end()) && (*otherIter != *thisIter) ) {
673            otherIter++;
674        }
675
676        //if (!path.empty()) {
677        //    thisSpath = path + "." + *thisIter;
678        //}
679        //else {
680        //    thisSpath = *thisIter;
681        //}
682        thisSpath = *thisIter;
683
684        if (otherIter == otherv.end()) {
685            // we've reached the end of the search
686            // and did not find anything, mark this as a '-'
687            thisVal = this->value(thisSpath);
688            retList.push_back("-");
689            retList.push_back(thisSpath);
690            retList.push_back(thisVal.front());
691            retList.push_back("");
692        }
693        else {
694
695            //if (!path.empty()) {
696            //    otherSpath = path + "." + *otherIter;
697            //}
698            //else {
699            //    otherSpath = *otherIter;
700            //}
701            otherSpath = *otherIter;
702
703            thisVal = this->value(thisSpath);
704            otherVal = otherLib->value(otherSpath);
705            if (thisVal.back() != otherVal.back()) {
706                // add the difference to the return list
707                retList.push_back("c");
708                retList.push_back(otherSpath);
709                retList.push_back(thisVal.front());
710                retList.push_back(otherVal.front());
711            }
712
713            // remove the last processed value from otherv
714            otherv.erase(otherIter);
715        }
716
717        // increment thisv's iterator.
718        thisIter++;
719    }
720
721    // add any left over values in otherv to the return list
722    otherIter = otherv.begin();
723    while ( otherIter != otherv.end() ) {
724
725        //if (!path.empty()) {
726        //    otherSpath = path + "." + *otherIter;
727        //}
728        //else {
729        //    otherSpath = *otherIter;
730        //}
731        otherSpath = *otherIter;
732
733        otherVal = otherLib->value(otherSpath);
734
735        retList.push_back("+");
736        retList.push_back(otherSpath);
737        retList.push_back("");
738        retList.push_back(otherVal.front());
739
740        otherv.erase(otherIter);
741        otherIter = otherv.begin();
742    }
743
744    return retList;
745}
746
747/**********************************************************************/
748// METHOD: value(path)
749/// Return a 2 element list containing the regular and normalized values.
750/**
751 */
752
753std::list<std::string>
754RpLibrary::value (std::string path)
755{
756    std::list<std::string> retArr;
757
758    std::string raw = "";
759    std::string val = "";
760
761    RpLibrary* ele = NULL;
762    RpLibrary* tele = NULL;
763
764    int childCount = 0;
765    std::stringstream valStr;
766
767    ele = this->element(path);
768
769    if (ele != NULL ) {
770
771        if (ele->nodeType() == "structure") {
772            raw = path;
773            // try to find a label to represent the structure
774            val = ele->get("about.label");
775
776            if (val == "") {
777               val = ele->get("current.about.label");
778            }
779
780            if (val == "") {
781               tele = ele->element("current");
782               if ( (tele != NULL) && (tele->nodeComp() != "") ) {
783                   tele->children("components",NULL,"",&childCount);
784                   valStr << "<structure> with " << childCount  << " components";
785                   val = valStr.str();
786               }
787            }
788
789        }
790        /*
791        else if (ele->nodeType() == "number") {
792            raw = "";
793            retArr[1] = "";
794            if ( (tele = ele->element("current")) != NULL) {
795                raw = tele->get();
796            }
797            else if ( (tele = ele->element("default")) != NULL) {
798                raw = tele->get();
799            }
800            val = raw
801            if ( "" != raw) {
802                // normalize the units
803                units = ele->get("units");
804                if ( "" != units) {
805
806                }
807        }
808        */
809        else {
810            raw = "";
811            if ( (tele = ele->element("current")) != NULL) {
812                raw = tele->get();
813            }
814            else if ( (tele = ele->element("default")) != NULL) {
815                raw = tele->get();
816            }
817            val = raw;
818        }
819    }
820
821    retArr.push_back(raw);
822    retArr.push_back(val);
823
824    return retArr;
825}
826
827/**********************************************************************/
828// METHOD: parent()
829/// Search the path of a xml tree and return its parent.
830/**
831 * It is the user's responsibility to delete the object when
832 * they are finished using it?, else i need to make this static
833 */
834
835RpLibrary*
836RpLibrary::parent (std::string path)
837{
838    RpLibrary* retLib = NULL;
839    std::string parentPath = "";
840    // std::string::size_type pos = 0;
841    scew_element* ele = NULL;
842    scew_element* retNode = NULL;
843
844    if (!this->root) {
845        // library doesn't exist, do nothing;
846        return NULL;
847    }
848
849    if (path.empty()) {
850        // an empty path returns the parent of the current RpLibrary
851        ele = this->root;
852    }
853    else {
854        // else find the node representing the provided path
855        ele = _find(path,NO_CREATE_PATH);
856    }
857
858    if (ele != NULL) {
859        retNode = scew_element_parent(ele);
860        if (retNode) {
861            // allocate a new rappture library object for the node
862            retLib = new RpLibrary( retNode,this->tree );
863        }
864    }
865    else {
866        // path was not found by _find
867    }
868
869
870    return retLib;
871}
872
873/**********************************************************************/
874// METHOD: copy()
875/// Copy the value from fromPath to toPath.
876//  Copy the value from fromObj.fromPath to toPath
877//  of the current rappture library object. This can copy rappture
878//  library elements within or between xml trees.
879/**
880 */
881
882RpLibrary&
883RpLibrary::copy (std::string toPath, std::string fromPath, RpLibrary* fromObj)
884{
885    RpLibrary* value = NULL;
886    // RpLibrary* child = NULL;
887
888    if (!this->root) {
889        // library doesn't exist, do nothing;
890        // need a good way to raise error, and this is not it.
891        return *this;
892    }
893
894    if (fromObj == NULL) {
895        fromObj = this;
896    }
897
898    value = fromObj->element(fromPath);
899
900    if ( !value ) {
901        // need a good way to raise error, and this is not it.
902        return *this;
903    }
904
905    this->put(toPath, value);
906    delete value;
907
908    return (*this);
909
910}
911
912/**********************************************************************/
913// METHOD: children()
914/// Return the next child of the node located at 'path'
915//
916// The lookup is reset when you send a NULL rpChilNode.
917// User is responsible for deleting returned values
918//
919/**
920 */
921
922/*
923RpLibrary*
924RpLibrary::children (   std::string path,
925                        RpLibrary* rpChildNode,
926                        std::string type,
927                        int* childCount)
928{
929    static std::string old_path = "";
930    static RpLibrary* retLib = NULL;
931    int myChildCount = 0;
932    scew_element* parentNode = NULL;
933    scew_element* childNode = NULL;
934    std::string childName = "";
935
936    if (!this->root) {
937        // library doesn't exist, do nothing;
938        return NULL;
939    }
940
941
942    if (path.empty()) {
943        // an empty path uses the current RpLibrary as parent
944        parentNode = this->root;
945    }
946    else {
947        // check to see if this path is the same as the one set
948        // in the last call to this function.
949        // if so, then we dont need to reset the parentNode
950        //
951        // this check is probably more dependent on rpChildNode
952        // because we want to see if the person want to continue
953        // an old search or start from the beginning of the child list
954        //
955        if ( (path.compare(old_path) == 0) && (rpChildNode != NULL) ) {
956            parentNode = NULL;
957        }
958        // we need to search for a new parentNode
959        else {
960            parentNode = _find(path,NO_CREATE_PATH);
961            if (parentNode == NULL) {
962                // node not found
963                // add error code here
964                return NULL;
965            }
966        }
967    }
968
969    old_path = path;
970
971
972    if (rpChildNode) {
973        childNode = rpChildNode->root;
974    }
975
976    if (parentNode) {
977        myChildCount = scew_element_count(parentNode);
978    }
979
980    if (childCount) {
981        *childCount = myChildCount;
982    }
983
984    // clean up old memory
985    delete retLib;
986
987    if ( (childNode = scew_element_next(parentNode,childNode)) ) {
988
989        if (!type.empty()) {
990            childName = scew_element_name(childNode);
991            // we are searching for a specific child name
992            // keep looking till we find a name that matches the type.
993            // if the current name does not match out search type,
994            // grab the next child and check to see if its null
995            // if its not null, get its name and test for type again
996            while (  (type != childName)
997                  && (childNode = scew_element_next(parentNode,childNode)) ) {
998
999                childName = scew_element_name(childNode);
1000            }
1001            if (type == childName) {
1002                // found a child with a name that matches type
1003                retLib = new RpLibrary( childNode,this->tree );
1004            }
1005            else {
1006                // no children with names that match 'type' were found
1007                retLib = NULL;
1008            }
1009        }
1010        else {
1011            retLib = new RpLibrary( childNode,this->tree );
1012        }
1013    }
1014    else {
1015        // somthing happened within scew, get error code and display
1016        // its probable there are no more child elements left to report
1017        retLib = NULL;
1018    }
1019
1020    return retLib;
1021}
1022*/
1023
1024RpLibrary*
1025RpLibrary::children (   std::string path,
1026                        RpLibrary* rpChildNode,
1027                        std::string type,
1028                        int* childCount)
1029{
1030    // this is static for efficency reasons
1031    static std::string old_path = "";
1032    // this was static so user never has to delete the retLib.
1033    // should be replaced by a smart pointer
1034    // static RpLibrary* retLib = NULL;
1035    RpLibrary* retLib = NULL;
1036    int myChildCount = 0;
1037    scew_element* parentNode = NULL;
1038    scew_element* childNode = NULL;
1039    std::string childName = "";
1040
1041    if (!this->root) {
1042        // library doesn't exist, do nothing;
1043        return NULL;
1044    }
1045
1046
1047    // check to see if the last call to this function
1048    // was searching for children of the same path.
1049    if ( (path.compare(old_path) == 0) && (rpChildNode != NULL) ) {
1050        parentNode = NULL;
1051    }
1052    else if (path.empty()) {
1053        // searching for children in a new path.
1054        // an empty path uses the current RpLibrary as parent
1055        parentNode = this->root;
1056    }
1057    else {
1058        // searching for children in a new, non-empty, path.
1059        parentNode = _find(path,NO_CREATE_PATH);
1060        if (parentNode == NULL) {
1061            // node not found
1062            // add error code here
1063            return NULL;
1064        }
1065    }
1066
1067    old_path = path;
1068
1069    if (rpChildNode) {
1070        childNode = rpChildNode->root;
1071    }
1072
1073    if (parentNode) {
1074        myChildCount = scew_element_count(parentNode);
1075        if (childCount) {
1076            *childCount = myChildCount;
1077        }
1078    }
1079
1080    // clean up old memory
1081    // delete retLib;
1082
1083    if ( (childNode = scew_element_next(parentNode,childNode)) ) {
1084
1085        if (!type.empty()) {
1086            childName = scew_element_name(childNode);
1087            // we are searching for a specific child name
1088            // keep looking till we find a name that matches the type.
1089            // if the current name does not match out search type,
1090            // grab the next child and check to see if its null
1091            // if its not null, get its name and test for type again
1092            while (  (type != childName)
1093                  && (childNode = scew_element_next(parentNode,childNode)) ) {
1094
1095                childName = scew_element_name(childNode);
1096            }
1097            if (type == childName) {
1098                // found a child with a name that matches type
1099                retLib = new RpLibrary( childNode,this->tree );
1100            }
1101            else {
1102                // no children with names that match 'type' were found
1103                retLib = NULL;
1104            }
1105        }
1106        else {
1107            retLib = new RpLibrary( childNode,this->tree );
1108        }
1109    }
1110    else {
1111        // somthing happened within scew, get error code and display
1112        // its probable there are no more child elements left to report
1113        retLib = NULL;
1114    }
1115
1116    return retLib;
1117}
1118
1119/**********************************************************************/
1120// METHOD: children()
1121/// Returns a std::list<RpLibrary*> of all children under 'path'
1122//
1123//
1124/**
1125 */
1126
1127RpLibrary&
1128RpLibrary::childCount ( std::string path,
1129                        int* childCount)
1130{
1131    scew_element* parentNode;
1132    int myChildCount = 0;
1133
1134    if (this->root) {
1135
1136        if (path.empty()) {
1137            // an empty path uses the current RpLibrary as parent
1138            parentNode = this->root;
1139        }
1140
1141        if (parentNode) {
1142            myChildCount = scew_element_count(parentNode);
1143        }
1144
1145        if (childCount) {
1146            *childCount = myChildCount;
1147        }
1148
1149    }
1150
1151    return *this;
1152}
1153
1154/**********************************************************************/
1155// METHOD: isNull()
1156/// returns whether this RpLibrary is a valid library node
1157//
1158//
1159/**
1160 */
1161
1162bool
1163RpLibrary::isNull ()
1164{
1165    if (this->root) {
1166        return false;
1167    }
1168
1169    return true;
1170}
1171
1172/**********************************************************************/
1173// METHOD: get()
1174/// Return the string value of the object held at location 'path'
1175/**
1176 */
1177
1178std::string
1179RpLibrary::get (std::string path, int translateFlag)
1180{
1181    return (this->getString(path, translateFlag));
1182}
1183
1184/**********************************************************************/
1185// METHOD: getString()
1186/// Return the string value of the object held at location 'path'
1187/**
1188 */
1189
1190std::string
1191RpLibrary::getString (std::string path, int translateFlag)
1192{
1193    scew_element* retNode = NULL;
1194    XML_Char const* retCStr = NULL;
1195    char* translatedContents = NULL;
1196    std::string retStr = "";
1197    int len = 0;
1198
1199    if (!this->root) {
1200        // library doesn't exist, do nothing;
1201        return std::string("");
1202    }
1203
1204    retNode = _find(path,NO_CREATE_PATH);
1205
1206    if (retNode == NULL) {
1207        // need to raise error
1208        return std::string("");
1209    }
1210
1211    retCStr = scew_element_contents(retNode);
1212
1213    if (!retCStr) {
1214        return std::string("");
1215    }
1216
1217    if (translateFlag == RPLIB_TRANSLATE) {
1218        // translatedContents = new char[strlen(retCStr)+1];
1219        len = strlen(retCStr);
1220        translatedContents = (char*) calloc((len+1),sizeof(char));
1221        if (translatedContents) {
1222            strncpy(translatedContents, retCStr, len);
1223            _translateOut(translatedContents);
1224            retStr = std::string(translatedContents);
1225            // delete[] translatedContents;
1226            free(translatedContents);
1227        }
1228        else {
1229            // error allocating space
1230            return std::string("");
1231        }
1232    }
1233    else {
1234        retStr = std::string(retCStr);
1235    }
1236
1237    return retStr;
1238}
1239
1240/**********************************************************************/
1241// METHOD: getDouble()
1242/// Return the double value of the object held at location 'path'
1243/**
1244 */
1245
1246double
1247RpLibrary::getDouble (std::string path)
1248{
1249    std::string retValStr = "";
1250    double retValDbl = 0;
1251
1252    if (!this->root) {
1253        // library doesn't exist, do nothing;
1254        return retValDbl;
1255    }
1256
1257    retValStr = this->getString(path);
1258    // think about changing this to strtod()
1259    retValDbl = atof(retValStr.c_str());
1260
1261    // how do we raise error?
1262    // currently we depend on getString to raise the error
1263    return retValDbl;
1264}
1265
1266
1267/**********************************************************************/
1268// METHOD: getInt()
1269/// Return the integer value of the object held at location 'path'
1270/**
1271 */
1272
1273int
1274RpLibrary::getInt (std::string path)
1275{
1276    std::string retValStr = "";
1277    int retValInt = 0;
1278
1279    if (!this->root) {
1280        // library doesn't exist, do nothing;
1281        return retValInt;
1282    }
1283
1284    retValStr = this->getString(path);
1285    // think about changing this to strtod()
1286    retValInt = atoi(retValStr.c_str());
1287
1288    // how do we raise error?
1289    // currently we depend on getString to raise the error
1290    return retValInt;
1291}
1292
1293
1294/**********************************************************************/
1295// METHOD: getBool()
1296/// Return the boolean value of the object held at location 'path'
1297/**
1298 */
1299
1300bool
1301RpLibrary::getBool (std::string path)
1302{
1303    std::string retValStr = "";
1304    bool retValBool = false;
1305    int retValLen = 0;
1306
1307    if (!this->root) {
1308        // library doesn't exist, do nothing;
1309        return retValBool;
1310    }
1311
1312    retValStr = this->getString(path);
1313    transform (retValStr.begin(),retValStr.end(),retValStr.begin(),tolower);
1314    retValLen = retValStr.length();
1315
1316    if ((retValStr.compare(0,retValLen,"1",0,retValLen) == 0  )   ||
1317        (retValStr.compare(0,retValLen,"yes",0,retValLen) == 0 )  ||
1318        (retValStr.compare(0,retValLen,"true",0,retValLen) == 0 ) ||
1319        (retValStr.compare(0,retValLen,"on",0,retValLen) == 0))
1320    {
1321        retValBool = true;
1322    }
1323    else if((retValStr.compare(0,retValLen,"0",0,retValLen) == 0  )   ||
1324            (retValStr.compare(0,retValLen,"no",0,retValLen) == 0 )  ||
1325            (retValStr.compare(0,retValLen,"false",0,retValLen) == 0 ) ||
1326            (retValStr.compare(0,retValLen,"off",0,retValLen) == 0))
1327    {
1328        retValBool = false;
1329    }
1330    else {
1331        // default to false?
1332        retValBool = false;
1333    }
1334
1335    // how do we raise error?
1336    // currently we depend on getString to raise the error
1337    return retValBool;
1338}
1339
1340
1341/**********************************************************************/
1342// METHOD: getData()
1343/// Return a pointer and memory size of the object held at location 'path'
1344/**
1345 */
1346
1347/*
1348Rappture::Buffer&
1349RpLibrary::getData (std::string path)
1350{
1351    const char* retCStr = NULL;
1352    Rappture::Buffer buf;
1353
1354    if (!this->root) {
1355        // library doesn't exist, do nothing;
1356        return buf;
1357    }
1358
1359    retNode = _find(path,NO_CREATE_PATH);
1360
1361    if (retNode == NULL) {
1362        // need to raise error
1363        return buf;
1364    }
1365
1366    retCStr = scew_element_contents(retNode);
1367
1368    if (retCStr == NULL) {
1369        return buf;
1370    }
1371
1372    len = strlen(retCStr);
1373    buf.append(retCStr,len);
1374    return buf;
1375}
1376*/
1377
1378
1379/**********************************************************************/
1380// METHOD: put()
1381/// Put a string value into the xml.
1382/**
1383 */
1384
1385RpLibrary&
1386RpLibrary::put (    std::string path,
1387                    std::string value,
1388                    std::string id,
1389                    int append,
1390                    int translateFlag)
1391{
1392    scew_element* retNode = NULL;
1393    std::string tmpVal = "";
1394    const char* contents = NULL;
1395    std::string translatedContents = "";
1396
1397    if (!this->root) {
1398        // library doesn't exist, do nothing;
1399        return *this;
1400    }
1401
1402    retNode = _find(path,CREATE_PATH);
1403
1404    if (retNode) {
1405
1406        if (append == RPLIB_APPEND) {
1407            if ( (contents = scew_element_contents(retNode)) ) {
1408                tmpVal = std::string(contents);
1409            }
1410            value = tmpVal + value;
1411        }
1412
1413        if (translateFlag == RPLIB_TRANSLATE) {
1414            _translateIn(value,translatedContents);
1415            scew_element_set_contents(retNode,translatedContents.c_str());
1416        }
1417        else {
1418            scew_element_set_contents(retNode,value.c_str());
1419        }
1420    }
1421
1422    return *this;
1423}
1424
1425/**********************************************************************/
1426// METHOD: put()
1427/// Put a double value into the xml.
1428/**
1429 */
1430
1431RpLibrary&
1432RpLibrary::put ( std::string path, double value, std::string id, int append )
1433{
1434    std::stringstream valStr;
1435
1436    if (!this->root) {
1437        // library doesn't exist, do nothing;
1438        return *this;
1439    }
1440
1441    valStr << value;
1442
1443    return this->put(path,valStr.str(),id,append);
1444}
1445
1446/**********************************************************************/
1447// METHOD: put()
1448/// Put a RpLibrary* value into the xml.
1449/**
1450 *  Append flag adds additional nodes, it does not merge same
1451 *  named nodes together
1452 */
1453
1454RpLibrary&
1455RpLibrary::put ( std::string path, RpLibrary* value, std::string id, int append )
1456{
1457    scew_element* retNode   = NULL;
1458    // scew_element* old_elem  = NULL;
1459    scew_element* new_elem  = NULL;
1460    scew_element* childNode = NULL;
1461    // std::string nodeName    = "";
1462
1463    int retVal = 1;
1464
1465    if (!this->root) {
1466        // library doesn't exist, do nothing;
1467        return *this;
1468    }
1469
1470    // you cannot put a null RpLibrary into the tree
1471    if (!value) {
1472        // need to send back an error saying that user specified a null value
1473        return *this;
1474    }
1475
1476    // nodeName = value->nodeComp();
1477    // old_elem = _find(path+"."+nodeName,NO_CREATE_PATH);
1478
1479    if (append == RPLIB_OVERWRITE) {
1480        retNode = _find(path,NO_CREATE_PATH);
1481        if (retNode) {
1482            scew_element_free(retNode);
1483        }
1484        else {
1485            // path did not exist and was not created
1486            // do nothing
1487        }
1488    }
1489
1490    retNode = _find(path,CREATE_PATH);
1491
1492    if (retNode) {
1493        while ( (childNode = scew_element_next(value->root,childNode)) ) {
1494            if ((new_elem = scew_element_copy(childNode))) {
1495                if (scew_element_add_elem(retNode, new_elem)) {
1496                    // maybe we want to count the number of children
1497                    // that we have successfully added?
1498                    retVal = 0;
1499                }
1500                else {
1501                    // adding new element failed
1502                }
1503            }
1504            else {
1505                // copying new element failed
1506            }
1507        }
1508    }
1509    else {
1510        // path did not exist and was not created.
1511    }
1512
1513    return *this;
1514}
1515
1516
1517/**********************************************************************/
1518// METHOD: putData()
1519/// Put a data from a buffer into the xml.
1520/**
1521 *  Append flag adds additional nodes, it does not merge same
1522 *  named nodes together
1523 */
1524
1525RpLibrary&
1526RpLibrary::putData (std::string path,
1527                    const char* bytes,
1528                    int nbytes,
1529                    int append  )
1530{
1531    scew_element* retNode = NULL;
1532    const char* contents = NULL;
1533    Rappture::Buffer buf;
1534    unsigned int bytesWritten = 0;
1535
1536    if (!this->root) {
1537        // library doesn't exist, do nothing;
1538        return *this;
1539    }
1540
1541    retNode = _find(path,CREATE_PATH);
1542
1543    if (retNode) {
1544
1545        if (append == RPLIB_APPEND) {
1546            if ( (contents = scew_element_contents(retNode)) ) {
1547                buf.append(contents);
1548                // base64 decode and un-gzip the data
1549                buf.decode();
1550            }
1551        }
1552
1553        buf.append(bytes,nbytes);
1554        // gzip and base64 encode the data
1555        buf.encode();
1556
1557        bytesWritten = (unsigned int) buf.size();
1558        scew_element_set_contents_binary(retNode,buf.bytes(),&bytesWritten);
1559    }
1560
1561    return *this;
1562}
1563
1564
1565/**********************************************************************/
1566// METHOD: putData()
1567/// Put data from a file into the xml.
1568/**
1569 *  Append flag adds additional nodes, it does not merge same
1570 *  named nodes together
1571 */
1572
1573RpLibrary&
1574RpLibrary::putFile (std::string path,
1575                    std::string fileName,
1576                    bool binary,
1577                    int append  )
1578{
1579    scew_element* retNode = NULL;
1580    const char* contents = NULL;
1581    Rappture::Buffer buf;
1582    Rappture::Buffer fileBuf;
1583    unsigned int bytesWritten = 0;
1584
1585    if (!this->root) {
1586        // library doesn't exist, do nothing;
1587        return *this;
1588    }
1589
1590    retNode = _find(path,CREATE_PATH);
1591
1592    if (retNode) {
1593
1594        if (append == RPLIB_APPEND) {
1595            if ( (contents = scew_element_contents(retNode)) ) {
1596                buf.append(contents);
1597                if (binary == true) {
1598                    // base64 decode and un-gzip the data
1599                    buf.decode();
1600                }
1601            }
1602        }
1603
1604        fileBuf.load(fileName.c_str());
1605        buf += fileBuf;
1606
1607        if (binary == true) {
1608            // gzip and base64 encode the data
1609            buf.encode();
1610        }
1611
1612        bytesWritten = (unsigned int) buf.size();
1613        scew_element_set_contents_binary(retNode,buf.bytes(),&bytesWritten);
1614
1615    }
1616
1617    return *this;
1618}
1619
1620
1621/**********************************************************************/
1622// METHOD: remove()
1623/// Remove the provided path from this RpLibrary
1624/**
1625 */
1626
1627RpLibrary*
1628RpLibrary::remove ( std::string path )
1629{
1630    scew_element* ele = NULL;
1631    int setNULL = 0;
1632    RpLibrary* retLib = NULL;
1633
1634    if (!this->root) {
1635        // library doesn't exist, do nothing;
1636        return NULL;
1637    }
1638
1639    if ( !path.empty() ) {
1640        ele = _find(path,NO_CREATE_PATH);
1641    }
1642    else {
1643        // telling this function to remove "" is essentially destroying
1644        // the object. most functions will fail after a call like this.
1645        ele = this->root;
1646        setNULL++;
1647    }
1648
1649    if (ele) {
1650        scew_element_free(ele);
1651        if (setNULL != 0) {
1652            // this is the case where user specified an empty path.
1653            // the object is useless, and will be deleted.
1654            this->root = NULL;
1655            retLib = NULL;
1656        }
1657        else {
1658            retLib = this;
1659        }
1660    }
1661
1662    return retLib;
1663}
1664
1665/**********************************************************************/
1666// METHOD: xml()
1667/// Return the xml text held in this RpLibrary
1668/**
1669 */
1670
1671std::string
1672RpLibrary::xml ()
1673{
1674    std::stringstream outString;
1675
1676    if (!this->root) {
1677        // library doesn't exist, do nothing;
1678        return std::string("");
1679    }
1680
1681    outString << "<?xml version=\"1.0\"?>\n";
1682    print_element(this->root, 0, outString);
1683
1684    return outString.str();
1685}
1686
1687/**********************************************************************/
1688// METHOD: nodeType()
1689/// Return the type name of this node
1690/**
1691 */
1692
1693std::string
1694RpLibrary::nodeType ()
1695{
1696    if (!this->root) {
1697        // library doesn't exist, do nothing;
1698        return std::string("");
1699    }
1700
1701    return std::string(scew_element_name(root));
1702}
1703
1704/**********************************************************************/
1705// METHOD: nodeId()
1706/// Return the id of this node.
1707/**
1708 */
1709
1710std::string
1711RpLibrary::nodeId ()
1712{
1713    if (!this->root) {
1714        // library doesn't exist, do nothing;
1715        return std::string("");
1716    }
1717
1718    return _node2name(root);
1719}
1720
1721/**********************************************************************/
1722// METHOD: nodeComp()
1723/// Return the component name of this node.
1724/**
1725 */
1726
1727std::string
1728RpLibrary::nodeComp ()
1729{
1730    if (!this->root) {
1731        // library doesn't exist, do nothing;
1732        return std::string("");
1733    }
1734
1735    return _node2comp(root);
1736}
1737
1738/**********************************************************************/
1739// METHOD: nodePath()
1740/// Return the component name of this node's path.
1741/**
1742 */
1743
1744std::string
1745RpLibrary::nodePath ()
1746{
1747    if (!this->root) {
1748        // library doesn't exist, do nothing;
1749        return std::string("");
1750    }
1751
1752    return _node2path(root);
1753}
1754
1755/*
1756 * ----------------------------------------------------------------------
1757 *  METHOD: result
1758 *
1759 *  Clients call this function at the end of their simulation, to
1760 *  pass the simulation result back to the Rappture GUI.  It writes
1761 *  out the given XML object to a runXXX.xml file, and then writes
1762 *  out the name of that file to stdout.
1763 * ======================================================================
1764 *  AUTHOR:  Michael McLennan, Purdue University
1765 *  Copyright (c) 2004-2005
1766 *  Purdue Research Foundation, West Lafayette, IN
1767 * ======================================================================
1768 */
1769void
1770RpLibrary::result() {
1771    std::stringstream outputFile;
1772    std::fstream file;
1773    std::string xmlText = "";
1774    time_t t = 0;
1775    struct tm* timeinfo = NULL;
1776    std::string timestamp = "";
1777
1778    if (this->root) {
1779        outputFile << "run" << (int)time(&t) << ".xml";
1780        file.open(outputFile.str().c_str(),std::ios::out);
1781
1782        put("tool.repository.rappture.date","$Date: 2007-02-23 19:36:18 +0000 (Fri, 23 Feb 2007) $");
1783        put("tool.repository.rappture.revision","$Rev: 589 $");
1784        put("tool.repository.rappture.url","$URL: trunk/src/core/RpLibrary.cc $");
1785
1786        // generate a timestamp for the run file
1787        timeinfo = localtime(&t);
1788        timestamp = std::string(ctime(&t));
1789        // erase the 24th character because it is a newline
1790        timestamp.erase(24);
1791        // concatinate the timezone
1792        timestamp.append(" ");
1793        timestamp.append(timeinfo->tm_zone);
1794
1795        // add the timestamp to the run file
1796        put("output.time", timestamp);
1797
1798        if ( file.is_open() ) {
1799            xmlText = xml();
1800            if (!xmlText.empty()) {
1801                file << xmlText;
1802            }
1803        }
1804        std::cout << "=RAPPTURE-RUN=>" << outputFile.str() << std::endl;
1805    }
1806}
1807
1808/**********************************************************************/
1809// METHOD: print_indent()
1810/// Add indentations to the requested stringstream object.
1811/**
1812 */
1813
1814void
1815RpLibrary::print_indent(unsigned int indent, std::stringstream& outString)
1816{
1817
1818    // keep this around incase you want to use tabs instead of spaces
1819    // while ( (indent--) > 0)
1820    // {
1821    //     outString << "\t";
1822    // }
1823
1824    // keep this around incase you want to use spaces instead of tabs
1825    int cnt = indent*INDENT_SIZE;
1826    while ( (cnt--) > 0)
1827    {
1828        outString << " ";
1829    }
1830
1831}
1832
1833/**********************************************************************/
1834// METHOD: print_attributes()
1835/// Print the attribute names and values for the provided xml node
1836/**
1837 */
1838
1839void
1840RpLibrary::print_attributes(scew_element* element, std::stringstream& outString)
1841{
1842    scew_attribute* attribute = NULL;
1843
1844    if (element != NULL)
1845    {
1846        /**
1847         * Iterates through the element's attribute list, printing the
1848         * pair name-value.
1849         */
1850        attribute = NULL;
1851        while ((attribute = scew_attribute_next(element, attribute)) != NULL)
1852        {
1853            outString << " " << scew_attribute_name(attribute) << "=\"" <<
1854                   scew_attribute_value(attribute) << "\"";
1855        }
1856    }
1857}
1858
1859
1860/**********************************************************************/
1861// METHOD: print_element()
1862/// Print the value of the node and its attributes to a stringstream object
1863/**
1864 */
1865
1866void
1867RpLibrary::print_element(   scew_element* element,
1868                            unsigned int indent,
1869                            std::stringstream& outString    )
1870{
1871    scew_element* child = NULL;
1872    XML_Char const* contents = NULL;
1873
1874    if (element == NULL)
1875    {
1876        return;
1877    }
1878
1879    /**
1880     * Prints the starting element tag with its attributes.
1881     */
1882    print_indent(indent, outString);
1883    outString << "<" << scew_element_name(element);
1884    print_attributes(element,outString);
1885    outString << ">";
1886    contents = scew_element_contents(element);
1887    if (contents == NULL)
1888    {
1889        outString << "\n";
1890    }
1891
1892    /**
1893     * Call print_element function again for each child of the
1894     * current element.
1895     */
1896    child = NULL;
1897    while ((child = scew_element_next(element, child)) != NULL)
1898    {
1899        print_element(child, indent + 1, outString);
1900    }
1901
1902    /* Prints element's content. */
1903    if (contents != NULL)
1904    {
1905        outString << contents;
1906    }
1907    else
1908    {
1909        print_indent(indent, outString);
1910    }
1911
1912    /**
1913     * Prints the closing element tag.
1914     */
1915    outString << "</" << scew_element_name(element) << ">\n" ;
1916}
1917
1918/**********************************************************************/
1919// METHOD: translateIn()
1920/// Translate entity and character reference text coming in from the user
1921/**
1922 */
1923
1924int
1925RpLibrary::_translateIn(std::string& outStr,std::string& translatedStr)
1926{
1927    ERTranslator.appendEscaped(outStr, translatedStr);
1928    return 0;
1929}
1930
1931
1932/**********************************************************************/
1933// METHOD: translateOut()
1934/// Translate entity and character reference text going out to the user
1935/**
1936 */
1937
1938int
1939RpLibrary::_translateOut(char* inStr)
1940{
1941    int newLen = 0;
1942    ERTranslator.TranslateEntityRefs(inStr, &newLen);
1943    return 0;
1944}
Note: See TracBrowser for help on using the repository browser.