Changeset 671 for trunk/src/core
- Timestamp:
- Apr 15, 2007, 10:53:36 PM (17 years ago)
- Location:
- trunk/src/core
- Files:
-
- 2 added
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/core/RpLibrary.cc
r625 r671 14 14 #include "RpLibrary.h" 15 15 #include "RpEntityRef.h" 16 #include "RpEncode.h" 16 17 #include <algorithm> 17 18 #include <iostream> … … 48 49 freeRoot (1) 49 50 { 51 std::stringstream msg; 50 52 51 53 if (filePath.length() != 0) { … … 63 65 printf("Unable to load file (error #%d: %s)\n", code, 64 66 scew_error_string(code)); 65 66 /* 67 std::cout << "Unable to load file (error #" \ 68 << code << ": " << scew_error_string(code) \ 69 << ")\n" << std::endl; 70 */ 67 msg << "Unable to load file (error #" << code 68 << ": " << scew_error_string(code) << ")\n"; 71 69 72 70 if (code == scew_error_expat) … … 79 77 scew_error_expat_column(parser), 80 78 scew_error_expat_string(expat_code)); 81 } 82 // should probably exit program or something 83 // return EXIT_FAILURE; 79 msg << "Expat error #" << expat_code << " (line " 80 << scew_error_expat_line(parser) << ", column " 81 << scew_error_expat_column(parser) << "): " 82 << "\n"; 83 } 84 84 85 fflush(stdout); 85 86 scew_parser_free(parser); 86 87 parser = NULL; 87 } 88 else 88 89 // update the status of the call 90 status.error(msg.str().c_str()); 91 status.addContext("RpLibrary::RpLibrary()"); 92 } 93 else 89 94 { 90 95 tree = scew_parser_tree(parser); … … 111 116 freeRoot (1) 112 117 { 118 std::stringstream msg; 113 119 std::string buffer; 114 120 int buffLen; … … 132 138 printf("Unable to load buffer (error #%d: %s)\n", code, 133 139 scew_error_string(code)); 140 msg << "Unable to load file (error #" << code 141 << ": " << scew_error_string(code) << ")\n"; 134 142 135 143 if (code == scew_error_expat) … … 142 150 scew_error_expat_column(parser), 143 151 scew_error_expat_string(expat_code)); 152 msg << "Expat error #" << expat_code << " (line " 153 << scew_error_expat_line(parser) << ", column " 154 << scew_error_expat_column(parser) << "): " 155 << "\n"; 144 156 } 145 157 … … 148 160 149 161 parser = NULL; 162 163 // update the status of the call 164 status.error(msg.str().c_str()); 165 status.addContext("RpLibrary::RpLibrary()"); 150 166 } 151 167 else { … … 172 188 RpLibrary::operator= (const RpLibrary& other) { 173 189 190 std::stringstream msg; 174 191 std::string buffer; 175 192 int buffLen; … … 207 224 printf("Unable to load buffer (error #%d: %s)\n", code, 208 225 scew_error_string(code)); 226 msg << "Unable to load file (error #" << code 227 << ": " << scew_error_string(code) << ")\n"; 209 228 210 229 if (code == scew_error_expat) … … 217 236 scew_error_expat_column(parser), 218 237 scew_error_expat_string(expat_code)); 238 msg << "Expat error #" << expat_code << " (line " 239 << scew_error_expat_line(parser) << ", column " 240 << scew_error_expat_column(parser) << "): " 241 << "\n"; 219 242 } 220 243 … … 225 248 // return this object to its previous state. 226 249 parser = tmp_parser; 250 251 // update the status of the call 252 status.error(msg.str().c_str()); 253 status.addContext("RpLibrary::RpLibrary()"); 227 254 } 228 255 else { … … 1469 1496 const char* translatedContents = NULL; 1470 1497 std::string retStr = ""; 1498 Rappture::Buffer inData; 1471 1499 1472 1500 if (!this->root) { … … 1488 1516 } 1489 1517 1518 inData = Rappture::Buffer(retCStr); 1519 status &= Rappture::encoding::decode(inData,0); 1520 status.addContext("RpLibrary::getSting"); 1521 inData.append("\0",1); 1522 1490 1523 if (translateFlag == RPLIB_TRANSLATE) { 1491 translatedContents = ERTranslator.decode( retCStr);1524 translatedContents = ERTranslator.decode(inData.bytes()); 1492 1525 if (translatedContents == NULL) { 1493 1526 // translation failed 1494 return retStr; 1495 } 1496 retStr = std::string(translatedContents); 1497 translatedContents = NULL; 1527 if (!status) { 1528 status.error("Error while translating entity references"); 1529 status.addContext("RpLibrary::getSting"); 1530 } 1531 } 1532 else { 1533 retStr = std::string(translatedContents); 1534 translatedContents = NULL; 1535 } 1498 1536 } 1499 1537 else { 1500 retStr = std::string(retCStr); 1501 } 1538 retStr = std::string(inData.bytes()); 1539 } 1540 1541 inData.clear(); 1502 1542 1503 1543 return retStr; … … 1521 1561 } 1522 1562 1523 retValStr = this->getString(path); 1563 retValStr = this->getString(path); 1564 status.addContext("RpLibrary::getDouble"); 1524 1565 // think about changing this to strtod() 1525 1566 retValDbl = atof(retValStr.c_str()); 1526 1567 1527 // how do we raise error?1528 // currently we depend on getString to raise the error1529 1568 return retValDbl; 1530 1569 } … … 1548 1587 } 1549 1588 1550 retValStr = this->getString(path); 1589 retValStr = this->getString(path); 1590 status.addContext("RpLibrary::getInt"); 1551 1591 // think about changing this to strtod() 1552 1592 retValInt = atoi(retValStr.c_str()); 1553 1593 1554 // how do we raise error?1555 // currently we depend on getString to raise the error1556 1594 return retValInt; 1557 1595 } … … 1577 1615 1578 1616 retValStr = this->getString(path); 1617 status.addContext("RpLibrary::getBool"); 1579 1618 std::transform (retValStr.begin(),retValStr.end(),retValStr.begin(),tolower); 1580 1619 retValLen = retValStr.length(); … … 1599 1638 } 1600 1639 1601 // how do we raise error?1602 // currently we depend on getString to raise the error1603 1640 return retValBool; 1604 1641 } … … 1612 1649 1613 1650 Rappture::Buffer 1614 RpLibrary::getData (std::string path , Rappture::Outcome& status) const1651 RpLibrary::getData (std::string path) const 1615 1652 { 1616 1653 Rappture::EntityRef ERTranslator; … … 1639 1676 1640 1677 if (retCStr == NULL) { 1641 status.error("element located at path is empty"); 1642 status.addContext("RpLibrary::getData()"); 1678 // element located at path is empty 1643 1679 return buf; 1644 1680 } … … 1648 1684 if (translatedContents == NULL) { 1649 1685 // translation failed 1650 return buf; 1651 } 1652 len = strlen(translatedContents); 1653 buf.append(translatedContents,len); 1654 translatedContents = NULL; 1686 if (!status) { 1687 status.error("Error while translating entity references"); 1688 status.addContext("RpLibrary::getData()"); 1689 } 1690 } 1691 else { 1692 len = strlen(translatedContents); 1693 buf.append(translatedContents,len); 1694 translatedContents = NULL; 1695 } 1655 1696 } 1656 1697 else { … … 1687 1728 } 1688 1729 1730 // check for binary data 1731 if (Rappture::encoding::isbinary(value.c_str(),value.length()) != 0) { 1732 putData(path,value.c_str(),value.length(),append); 1733 status.addContext("RpLibrary::put() - putString"); 1734 return *this; 1735 } 1736 1689 1737 retNode = _find(path,CREATE_PATH); 1690 1738 … … 1700 1748 if (translateFlag == RPLIB_TRANSLATE) { 1701 1749 translatedContents = ERTranslator.encode(value.c_str()); 1702 if (translatedContents == NULL) { 1703 // translation failed 1704 return *this; 1705 } 1750 } 1751 else { 1752 translatedContents = value.c_str(); 1753 } 1754 1755 if (translatedContents == NULL) { 1756 // entity referene translation failed 1757 if (!status) { 1758 status.error("Error while translating entity references"); 1759 } 1760 } 1761 else { 1706 1762 scew_element_set_contents(retNode,translatedContents); 1707 1763 translatedContents = NULL; 1708 1764 } 1709 else { 1710 scew_element_set_contents(retNode,value.c_str()); 1711 } 1712 } 1713 1765 } 1766 else { 1767 // node not found, set error 1768 if (!status) { 1769 status.error("Error while searching for node: node not found"); 1770 } 1771 } 1772 1773 status.addContext("RpLibrary::put() - putString"); 1714 1774 return *this; 1715 1775 } … … 1736 1796 valStr << value; 1737 1797 1738 return this->put(path,valStr.str(),id,append); 1798 put(path,valStr.str(),id,append); 1799 status.addContext("RpLibrary::put() - putDouble"); 1800 return *this; 1739 1801 } 1740 1802 … … 1829 1891 scew_element* retNode = NULL; 1830 1892 const char* contents = NULL; 1831 Rappture::Buffer buf;1893 Rappture::Buffer inData; 1832 1894 unsigned int bytesWritten = 0; 1895 int flags = 0; 1833 1896 1834 1897 if (!this->root) { … … 1843 1906 if (append == RPLIB_APPEND) { 1844 1907 if ( (contents = scew_element_contents(retNode)) ) { 1845 buf.append(contents);1908 inData.append(contents); 1846 1909 // base64 decode and un-gzip the data 1847 buf.decode(); 1848 } 1849 } 1850 1851 buf.append(bytes,nbytes); 1910 status &= Rappture::encoding::decode(inData,0); 1911 if (int(status) != 0) { 1912 status.addContext("RpLibrary::putData()"); 1913 return *this; 1914 } 1915 } 1916 } 1917 1918 inData.append(bytes,nbytes); 1852 1919 // gzip and base64 encode the data 1853 buf.encode(); 1854 1855 bytesWritten = (unsigned int) buf.size(); 1856 scew_element_set_contents_binary(retNode,buf.bytes(),&bytesWritten); 1857 } 1858 1920 flags = RPENC_Z|RPENC_B64|RPENC_HDR; 1921 status &= Rappture::encoding::encode(inData,flags); 1922 1923 bytesWritten = (unsigned int) inData.size(); 1924 scew_element_set_contents_binary(retNode,inData.bytes(),&bytesWritten); 1925 } 1926 else { 1927 // node not found, set error 1928 if (!status) { 1929 status.error("Error while searching for node: node not found"); 1930 } 1931 } 1932 1933 status.addContext("RpLibrary::putData()"); 1859 1934 return *this; 1860 1935 } … … 1892 1967 put(path,fileBuf.bytes(),"",append,RPLIB_TRANSLATE); 1893 1968 } 1969 status.addContext("RpLibrary::putFile()"); 1894 1970 return *this; 1895 1971 } … … 2028 2104 2029 2105 return _node2path(root); 2106 } 2107 2108 /**********************************************************************/ 2109 // METHOD: outcome() 2110 /// Return the status object of this library object. 2111 /** 2112 */ 2113 2114 Rappture::Outcome& 2115 RpLibrary::outcome() const 2116 { 2117 return status; 2030 2118 } 2031 2119 … … 2040 2128 * ====================================================================== 2041 2129 * AUTHOR: Michael McLennan, Purdue University 2042 * Copyright (c) 2004-200 52130 * Copyright (c) 2004-2007 2043 2131 * Purdue Research Foundation, West Lafayette, IN 2044 2132 * ====================================================================== … … 2058 2146 file.open(outputFile.str().c_str(),std::ios::out); 2059 2147 2060 put("tool. repository.rappture.date","$Date$");2061 put("tool. repository.rappture.revision","$Rev$");2062 put("tool. repository.rappture.url","$URL$");2148 put("tool.version.rappture.date","$LastChangedDate$"); 2149 put("tool.version.rappture.revision","$LastChangedRevision$"); 2150 put("tool.version.rappture.url","$URL$"); 2063 2151 2064 2152 // generate a timestamp for the run file … … 2085 2173 file.close(); 2086 2174 } 2175 else { 2176 status.error("Error while opening run file"); 2177 status.addContext("RpLibrary::result()"); 2178 } 2087 2179 std::cout << "=RAPPTURE-RUN=>" << outputFile.str() << std::endl; 2088 2180 } -
trunk/src/core/RpLibrary.h
r625 r671 78 78 int getInt ( std::string path = "") const; 79 79 bool getBool ( std::string path = "") const; 80 Rappture::Buffer getData ( std::string path, 81 Rappture::Outcome& status) const; 80 Rappture::Buffer getData ( std::string path = "") const; 82 81 83 82 /* … … 134 133 std::string nodeComp() const; 135 134 std::string nodePath() const; 135 136 Rappture::Outcome& outcome() const; 136 137 137 138 void result(); … … 171 172 int freeRoot; 172 173 174 mutable Rappture::Outcome status; 173 175 174 176 RpLibrary ( scew_element* node, scew_tree* tree)
Note: See TracChangeset
for help on using the changeset viewer.