Changeset 759
- Timestamp:
- Jun 8, 2007, 1:48:39 PM (17 years ago)
- Location:
- trunk/src/core
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/core/RpLibrary.cc
r758 r759 4 4 * 5 5 * ====================================================================== 6 * AUTHOR: Derrick Kearney, Purdue University6 * AUTHOR: Derrick S. Kearney, Purdue University 7 7 * Copyright (c) 2004-2007 Purdue Research Foundation 8 8 * … … 320 320 scew_attribute* attribute = NULL; 321 321 std::string attrVal; 322 // int attrValSize = 0;323 322 324 323 if (element != NULL) … … 625 624 RpLibrary::_find(std::string path, int create) const 626 625 { 627 // std::string* tagName;628 // std::string* id;629 626 std::string tagName = ""; 630 627 std::string id = ""; … … 645 642 646 643 if (path.empty()) { 647 //user gave an empty path 648 // return this; 644 // user gave an empty path 649 645 return tmpElement; 650 646 } … … 663 659 _splitPath(*(list[listIdx]),tagName,&index,id); 664 660 665 // if (id->empty()) {666 661 if (id.empty()) { 667 662 /* … … 671 666 */ 672 667 673 // eleList = scew_element_list(tmpElement, tagName->c_str(), &count);674 668 eleList = scew_element_list(tmpElement, tagName.c_str(), &count); 675 669 tmpCount = count; … … 697 691 */ 698 692 699 // eleList = scew_element_list(tmpElement, tagName->c_str(), &count);700 693 if (!tagName.empty()) { 701 694 eleList = scew_element_list(tmpElement, tagName.c_str(), &count); … … 709 702 tmpId = _get_attribute(eleList[lcv], "id"); 710 703 if (!tmpId.empty()) { 711 // if (*id == tmpId) {712 704 if (id == tmpId) { 713 705 node = eleList[lcv]; … … 730 722 // break out instead of returning because we still need to 731 723 // free the list variable 732 // return node;733 724 tmpElement = node; 734 725 break; … … 740 731 // create the new element 741 732 // need to figure out how to properly number the new element 742 // node = scew_element_add(tmpElement,tagName->c_str());743 733 node = scew_element_add(tmpElement,tagName.c_str()); 744 734 if (! node) { 745 // a new element was not created 735 // a new element was not created 746 736 } 747 737 748 738 // add an attribute and attrValue to the new element 749 // if (id && !id->empty()) {750 // scew_element_add_attr_pair(node,"id",id->c_str());751 739 if (!id.empty()) { 752 740 scew_element_add_attr_pair(node,"id",id.c_str()); … … 755 743 } 756 744 757 758 // change this so youre not allocating and deallocating so much.759 // make it static or something.760 // if (tagName) { delete (tagName); }761 // if (id) { delete (id); }762 745 tagName = ""; 763 746 id = ""; … … 785 768 } 786 769 770 /**********************************************************************/ 771 // METHOD: _checkPathConflict(scew_element *nodeA,scew_element *nodeB) 772 /// check to see if nodeA is in nodeB's path 773 /** 774 * This is used by put() function (the RpLibrary flavor). It is 775 * used to check if nodeA can be safely deleted and not effect nodeB 776 */ 777 778 int 779 RpLibrary::_checkPathConflict(scew_element *nodeA, scew_element *nodeB) const 780 { 781 scew_element *testNode = NULL; 782 783 if ( (nodeA == NULL) || (nodeB == NULL) ) { 784 return 0; 785 } 786 787 if (nodeA == nodeB) { 788 return 1; 789 } 790 791 testNode = nodeB; 792 793 while ((testNode = scew_element_parent(testNode)) != NULL) { 794 if (testNode == nodeA) { 795 return 1; 796 } 797 } 798 799 return 0; 800 } 787 801 788 802 /**********************************************************************/ … … 1180 1194 RpLibrary& 1181 1195 RpLibrary::copy ( std::string toPath, 1182 std::string fromPath,1183 RpLibrary* fromObj)1196 RpLibrary* fromObj, 1197 std::string fromPath ) 1184 1198 { 1185 1199 RpLibrary* value = NULL; 1186 // RpLibrary* child = NULL;1187 1200 1188 1201 if (!this->root) { … … 1196 1209 } 1197 1210 1211 if ( (fromObj == this) && (toPath == fromPath) ) { 1212 /* cannot copy over myself, causes path to disappear */ 1213 return (*this); 1214 } 1215 1198 1216 value = fromObj->element(fromPath); 1199 1217 1200 1218 if ( !value ) { 1201 // need a good way to raise error, and this is not it. 1219 status.error("fromPath could not be found within fromObj"); 1220 status.addContext("RpLibrary::copy"); 1202 1221 return *this; 1203 1222 } 1204 1223 1205 1224 this->put(toPath, value); 1225 status.addContext("RpLibrary::copy"); 1206 1226 delete value; 1207 1227 … … 1323 1343 1324 1344 RpLibrary* 1325 RpLibrary::children ( std::string path, 1326 RpLibrary* rpChildNode, 1345 RpLibrary::children ( std::string path, 1346 RpLibrary* rpChildNode, 1327 1347 std::string type, 1328 1348 int* childCount) … … 1725 1745 if (!this->root) { 1726 1746 // library doesn't exist, do nothing; 1747 status.error("invalid library object"); 1748 status.addContext("RpLibrary::put()"); 1727 1749 return *this; 1728 1750 } … … 1789 1811 std::stringstream valStr; 1790 1812 1791 if ( !this->root) {1813 if (this->root == NULL) { 1792 1814 // library doesn't exist, do nothing; 1815 status.error("invalid library object"); 1816 status.addContext("RpLibrary::put()"); 1793 1817 return *this; 1794 1818 } … … 1803 1827 /**********************************************************************/ 1804 1828 // METHOD: put() 1805 /// Put a RpLibrary* value into the xml. 1829 /// Put a RpLibrary* value into the xml. This is used by copy() 1806 1830 /** 1807 1831 * Append flag adds additional nodes, it does not merge same … … 1815 1839 unsigned int append ) 1816 1840 { 1817 scew_element *retNode = NULL;1818 // scew_element* old_elem = NULL;1819 scew_element * new_elem= NULL;1820 scew_element * childNode= NULL;1821 // std::string nodeName = "";1822 1823 int retVal = 1;1824 1825 if ( !this->root) {1841 scew_element *retNode = NULL; 1842 scew_element *new_elem = NULL; 1843 scew_element *childNode = NULL; 1844 scew_element *tmpNode = NULL; 1845 const char *contents = NULL; 1846 int retVal = 1; 1847 int deleteTmpNode = 0; 1848 1849 if (this->root == NULL) { 1826 1850 // library doesn't exist, do nothing; 1851 status.error("invalid library object"); 1852 status.addContext("RpLibrary::put()"); 1827 1853 return *this; 1828 1854 } 1829 1855 1830 // you cannot put a null RpLibrary into the tree 1831 if (!value) { 1832 // need to send back an error saying that user specified a null value 1856 if (value == NULL) { 1857 // you cannot put a null RpLibrary into the tree 1858 // user specified a null value 1859 status.error("user specified NULL value"); 1860 status.addContext("RpLibrary::put()"); 1833 1861 return *this; 1834 1862 } 1835 1863 1836 // nodeName = value->nodeComp(); 1837 // old_elem = _find(path+"."+nodeName,NO_CREATE_PATH); 1864 if (value->root == NULL) { 1865 // you cannot put a null RpLibrary into the tree 1866 // user specified a null value 1867 status.error("user specified uninitialized RpLibrary object"); 1868 status.addContext("RpLibrary::put()"); 1869 return *this; 1870 } 1871 1872 tmpNode = value->root; 1838 1873 1839 1874 if (append == RPLIB_OVERWRITE) { 1840 1875 retNode = _find(path,NO_CREATE_PATH); 1841 1876 if (retNode) { 1842 scew_element_free(retNode); 1877 // compare roots to see if they are part of the 1878 // same xml tree, if so, make a tmp copy of the 1879 // tree to be copied before freeing it. 1880 if (_checkPathConflict(retNode,tmpNode)) { 1881 tmpNode = scew_element_copy(tmpNode); 1882 deleteTmpNode = 1; 1883 } 1884 contents = scew_element_contents(tmpNode); 1885 if (contents) { 1886 scew_element_set_contents(retNode, ""); 1887 } 1888 1889 while ( (childNode = scew_element_next(retNode,childNode)) ) { 1890 scew_element_free(childNode); 1891 } 1843 1892 } 1844 1893 else { … … 1851 1900 1852 1901 if (retNode) { 1853 while ( (childNode = scew_element_next(value->root,childNode)) ) { 1902 contents = scew_element_contents(tmpNode); 1903 if (contents) { 1904 scew_element_set_contents(retNode, contents); 1905 } 1906 1907 while ( (childNode = scew_element_next(tmpNode,childNode)) ) { 1854 1908 if ((new_elem = scew_element_copy(childNode))) { 1855 1909 if (scew_element_add_elem(retNode, new_elem)) { … … 1860 1914 else { 1861 1915 // adding new element failed 1916 status.error("error while adding child node"); 1917 status.addContext("RpLibrary::put()"); 1862 1918 } 1863 1919 } 1864 1920 else { 1865 1921 // copying new element failed 1866 } 1922 status.error("error while copying child node"); 1923 status.addContext("RpLibrary::put()"); 1924 } 1925 } 1926 1927 if (deleteTmpNode == 1) { 1928 scew_element_free(tmpNode); 1867 1929 } 1868 1930 } 1869 1931 else { 1870 1932 // path did not exist and was not created. 1933 status.error("error while creating child node"); 1934 status.addContext("RpLibrary::put()"); 1871 1935 } 1872 1936 … … 2146 2210 file.open(outputFile.str().c_str(),std::ios::out); 2147 2211 2148 put("tool.version.rappture.date","$LastChangedDate$");2149 2212 put("tool.version.rappture.revision","$LastChangedRevision$"); 2150 put("tool.version.rappture.url","$URL$"); 2213 put("tool.version.rappture.modified","$LastChangedDate$"); 2214 if ( "" == get("tool.version.rappture.language") ) { 2215 put("tool.version.rappture.language","c++"); 2216 } 2151 2217 2152 2218 // generate a timestamp for the run file … … 2175 2241 // errors while writing the run.xml file. 2176 2242 if ( (!file.good()) 2177 || ((long)xmlText.length() != (file.tellp()-(long)1)) ) { 2243 || ((long)xmlText.length() != ((long)file.tellp()-(long)1)) 2244 ) { 2178 2245 status.error("Error while writing run file"); 2179 2246 status.addContext("RpLibrary::result()"); … … 2229 2296 if (element != NULL) 2230 2297 { 2231 /** 2232 * Iterates through the element's attribute list, printing the 2233 * pair name-value. 2234 */ 2235 attribute = NULL; 2236 while ((attribute = scew_attribute_next(element, attribute)) != NULL) 2237 { 2238 outString << " " << scew_attribute_name(attribute) << "=\"" << 2239 scew_attribute_value(attribute) << "\""; 2298 if (scew_attribute_count(element) > 0) { 2299 /** 2300 * Iterates through the element's attribute list, printing the 2301 * pair name-value. 2302 */ 2303 attribute = NULL; 2304 while((attribute=scew_attribute_next(element, attribute)) != NULL) 2305 { 2306 outString << " " << scew_attribute_name(attribute) << "=\"" << 2307 scew_attribute_value(attribute) << "\""; 2308 } 2240 2309 } 2241 2310 } -
trunk/src/core/RpLibrary.h
r758 r759 4 4 * 5 5 * ====================================================================== 6 * AUTHOR: Derrick Kearney, Purdue University6 * AUTHOR: Derrick S. Kearney, Purdue University 7 7 * Copyright (c) 2004-2007 Purdue Research Foundation 8 8 * … … 67 67 68 68 RpLibrary& copy ( std::string toPath, 69 std::string fromPath,70 RpLibrary* fromObj = NULL);69 RpLibrary* fromObj, 70 std::string fromPath); 71 71 72 72 std::string get ( std::string path = "", … … 199 199 std::string& id ) const; 200 200 scew_element* _find (std::string path, int create) const; 201 int _checkPathConflict (scew_element *nodeA, scew_element *nodeB) const; 201 202 void print_indent ( unsigned int indent, 202 203 std::stringstream& outString) const;
Note: See TracChangeset
for help on using the changeset viewer.