Changeset 394 for trunk/src/core/RpLibrary.cc
- Timestamp:
- Apr 2, 2006, 11:44:53 PM (19 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/core/RpLibrary.cc
r365 r394 13 13 14 14 #include "RpLibrary.h" 15 #include "RpEntityRef.h" 16 17 static RpEntityRef ERTranslator; 15 18 16 19 /**********************************************************************/ … … 163 166 { 164 167 // XML_Char const* name = _get_attribute(node,"id"); 165 std::string name= _get_attribute(node,"id");168 std::string id = _get_attribute(node,"id"); 166 169 std::stringstream retVal; 167 170 XML_Char const* type = NULL; … … 177 180 178 181 if (parent) { 179 if ( name.empty()) {182 if (id.empty()) { 180 183 siblings = scew_element_list(parent, type, &count); 181 184 if (count > 0) { … … 188 191 if (index < tmpCount) { 189 192 if (index > 0) { 190 retVal << type << --index; 193 // retVal << type << --index; 194 retVal << type << index; 191 195 } 192 196 else { … … 204 208 else { 205 209 // node has attribute id 206 retVal << type << "(" << name<< ")";210 retVal << type << "(" << id << ")"; 207 211 208 212 } … … 540 544 child = NULL; 541 545 542 while ( (child = ele->children("",child)) != NULL ) {546 while ( ele && (child = ele->children("",child)) != NULL ) { 543 547 childList.push_back(child->nodeComp()); 544 548 } … … 636 640 } 637 641 638 thisSpath = path + "." + *thisIter; 642 if (!path.empty()) { 643 thisSpath = path + "." + *thisIter; 644 } 645 else { 646 thisSpath = *thisIter; 647 } 639 648 640 649 if (otherIter == otherv.end()) { … … 649 658 else { 650 659 651 otherSpath = path + "." + *otherIter; 660 if (!path.empty()) { 661 otherSpath = path + "." + *otherIter; 662 } 663 else { 664 otherSpath = *otherIter; 665 } 652 666 653 667 thisVal = this->value(thisSpath); … … 673 687 while ( otherIter != otherv.end() ) { 674 688 675 otherSpath = path + "." + *otherIter; 689 if (!path.empty()) { 690 otherSpath = path + "." + *otherIter; 691 } 692 else { 693 otherSpath = *otherIter; 694 } 676 695 677 696 otherVal = otherLib->value(otherSpath); … … 691 710 /**********************************************************************/ 692 711 // METHOD: value(path) 693 /// find the differences between two xml trees.712 /// Return a 2 element list containing the regular and normalized values. 694 713 /** 695 714 */ … … 734 753 /* 735 754 else if (ele->nodeType() == "number") { 736 r etArr[0]= "";755 raw = ""; 737 756 retArr[1] = ""; 738 757 if ( (tele = ele->element("current")) != NULL) { 739 retArr[0] = tele->get(); 740 retArr[1] = retArr[0]; 758 raw = tele->get(); 741 759 } 742 760 else if ( (tele = ele->element("default")) != NULL) { 743 retArr[0] = tele->get(); 744 retArr[1] = retArr[0]; 745 } 761 raw = tele->get(); 762 } 763 val = raw 764 if ( "" != raw) { 765 // normalize the units 766 units = ele->get("units"); 767 if ( "" != units) { 768 769 } 746 770 } 747 771 */ … … 822 846 { 823 847 RpLibrary* value = NULL; 848 RpLibrary* child = NULL; 824 849 825 850 if (!this->root) { 826 851 // library doesn't exist, do nothing; 852 // need a good way to raise error, and this is not it. 827 853 return *this; 828 854 } … … 839 865 } 840 866 841 return (this->put(toPath,value)); 867 while ( (child = value->children("",child)) ) { 868 this->put(toPath, child); 869 } 870 871 return (*this); 842 872 843 873 } … … 852 882 */ 853 883 884 /* 854 885 RpLibrary* 855 886 RpLibrary::children ( std::string path, … … 951 982 return retLib; 952 983 } 984 */ 985 986 RpLibrary* 987 RpLibrary::children ( std::string path, 988 RpLibrary* rpChildNode, 989 std::string type, 990 int* childCount) 991 { 992 // this is static for efficency reasons 993 static std::string old_path = ""; 994 // this was static so user never has to delete the retLib. 995 // should be replaced by a smart pointer 996 static RpLibrary* retLib = NULL; 997 int myChildCount = 0; 998 scew_element* parentNode = NULL; 999 scew_element* childNode = NULL; 1000 std::string childName = ""; 1001 1002 if (!this->root) { 1003 // library doesn't exist, do nothing; 1004 return NULL; 1005 } 1006 1007 1008 // check to see if the last call to this function 1009 // was searching for children of the same path. 1010 if ( (path.compare(old_path) == 0) && (rpChildNode != NULL) ) { 1011 parentNode = NULL; 1012 } 1013 else if (path.empty()) { 1014 // searching for children in a new path. 1015 // an empty path uses the current RpLibrary as parent 1016 parentNode = this->root; 1017 } 1018 else { 1019 // searching for children in a new, non-empty, path. 1020 parentNode = _find(path,NO_CREATE_PATH); 1021 if (parentNode == NULL) { 1022 // node not found 1023 // add error code here 1024 return NULL; 1025 } 1026 } 1027 1028 old_path = path; 1029 1030 if (rpChildNode) { 1031 childNode = rpChildNode->root; 1032 } 1033 1034 if (parentNode) { 1035 myChildCount = scew_element_count(parentNode); 1036 if (childCount) { 1037 *childCount = myChildCount; 1038 } 1039 } 1040 1041 // clean up old memory 1042 delete retLib; 1043 1044 if ( (childNode = scew_element_next(parentNode,childNode)) ) { 1045 1046 if (!type.empty()) { 1047 childName = scew_element_name(childNode); 1048 // we are searching for a specific child name 1049 // keep looking till we find a name that matches the type. 1050 // if the current name does not match out search type, 1051 // grab the next child and check to see if its null 1052 // if its not null, get its name and test for type again 1053 while ( (type != childName) 1054 && (childNode = scew_element_next(parentNode,childNode)) ) { 1055 1056 childName = scew_element_name(childNode); 1057 } 1058 if (type == childName) { 1059 // found a child with a name that matches type 1060 retLib = new RpLibrary( childNode,this->tree ); 1061 } 1062 else { 1063 // no children with names that match 'type' were found 1064 retLib = NULL; 1065 } 1066 } 1067 else { 1068 retLib = new RpLibrary( childNode,this->tree ); 1069 } 1070 } 1071 else { 1072 // somthing happened within scew, get error code and display 1073 // its probable there are no more child elements left to report 1074 retLib = NULL; 1075 } 1076 1077 return retLib; 1078 } 953 1079 954 1080 /**********************************************************************/ … … 1012 1138 1013 1139 std::string 1014 RpLibrary::get (std::string path )1015 { 1016 return (this->getString(path ));1140 RpLibrary::get (std::string path, int translateFlag) 1141 { 1142 return (this->getString(path, translateFlag)); 1017 1143 } 1018 1144 … … 1024 1150 1025 1151 std::string 1026 RpLibrary::getString (std::string path )1152 RpLibrary::getString (std::string path, int translateFlag) 1027 1153 { 1028 1154 scew_element* retNode = NULL; 1029 1155 XML_Char const* retCStr = NULL; 1156 char* translatedContents = NULL; 1157 std::string retStr = ""; 1158 int len = 0; 1030 1159 1031 1160 if (!this->root) { … … 1047 1176 } 1048 1177 1049 return std::string(retCStr); 1178 if (translateFlag == TRANSLATE) { 1179 // translatedContents = new char[strlen(retCStr)+1]; 1180 len = strlen(retCStr); 1181 translatedContents = (char*) calloc((len+1),sizeof(char)); 1182 if (translatedContents) { 1183 strncpy(translatedContents, retCStr, len); 1184 _translateOut(translatedContents); 1185 retStr = std::string(translatedContents); 1186 // delete[] translatedContents; 1187 free(translatedContents); 1188 } 1189 else { 1190 // error allocating space 1191 return std::string(""); 1192 } 1193 } 1194 else { 1195 retStr = std::string(retCStr); 1196 } 1197 1198 return retStr; 1050 1199 } 1051 1200 … … 1084 1233 1085 1234 RpLibrary& 1086 RpLibrary::put ( std::string path, std::string value, std::string id, int append ) 1235 RpLibrary::put ( std::string path, 1236 std::string value, 1237 std::string id, 1238 int append, 1239 int translateFlag) 1087 1240 { 1088 1241 scew_element* retNode = NULL; 1089 1242 std::string tmpVal = ""; 1090 1243 const char* contents = NULL; 1244 std::string translatedContents = ""; 1091 1245 1092 1246 if (!this->root) { … … 1106 1260 } 1107 1261 1108 scew_element_set_contents(retNode,value.c_str()); 1262 if (translateFlag == TRANSLATE) { 1263 _translateIn(value,translatedContents); 1264 scew_element_set_contents(retNode,translatedContents.c_str()); 1265 } 1266 else { 1267 scew_element_set_contents(retNode,value.c_str()); 1268 } 1109 1269 } 1110 1270 … … 1451 1611 } 1452 1612 1613 /**********************************************************************/ 1614 // METHOD: translateIn() 1615 /// Translate entity and character reference text coming in from the user 1616 /** 1617 */ 1618 1619 int 1620 RpLibrary::_translateIn(std::string& outStr,std::string& translatedStr) 1621 { 1622 ERTranslator.appendEscaped(outStr, translatedStr); 1623 return 0; 1624 } 1625 1626 1627 /**********************************************************************/ 1628 // METHOD: translateOut() 1629 /// Translate entity and character reference text going out to the user 1630 /** 1631 */ 1632 1633 int 1634 RpLibrary::_translateOut(char* inStr) 1635 { 1636 int newLen = 0; 1637 ERTranslator.TranslateEntityRefs(inStr, &newLen); 1638 return 0; 1639 }
Note: See TracChangeset
for help on using the changeset viewer.