Changeset 83 for trunk/include/core/RpLibrary.h
- Timestamp:
- Oct 5, 2005, 8:17:26 AM (19 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/include/core/RpLibrary.h
r77 r83 1 /* 2 * ---------------------------------------------------------------------- 3 * Rappture Library Header 4 * 5 * ====================================================================== 6 * AUTHOR: Derrick Kearney, Purdue University 7 * Copyright (c) 2005 8 * Purdue Research Foundation, West Lafayette, IN 9 * ====================================================================== 10 */ 1 11 2 12 #include "scew.h" … … 5 15 #include <string> 6 16 #include <sstream> 17 #include <fstream> 7 18 #include <stdlib.h> 8 19 #include <errno.h> 20 #include <time.h> 9 21 10 22 /* indentation size (in whitespaces) */ … … 17 29 { 18 30 public: 19 31 20 32 // users member fxns 21 33 22 34 RpLibrary* element (std::string path = "", std::string as = "object"); 35 23 36 // should return RpObject& but for simplicity right now it doesnt 24 37 // RpObject will either be an Array, RpString, RpNumber ... 25 /* 26 RpLibrary** children ( std::string path = "", 27 std::string as = "object", 28 std::string type = "" ); 29 */ 30 31 RpLibrary* children ( std::string path = "", 32 RpLibrary* rpChildNode = NULL, 38 39 RpLibrary* children ( std::string path = "", 40 RpLibrary* rpChildNode = NULL, 33 41 std::string type = "", 34 42 int* childCount = NULL ); … … 42 50 std::string id = "", 43 51 int append = 0 ); 44 52 45 53 RpLibrary& put ( std::string path, 46 54 double value, … … 55 63 std::string nodeId(); 56 64 std::string nodeComp(); 57 65 66 void result(); 58 67 const char* nodeTypeC(); 59 68 const char* nodeIdC(); … … 67 76 tree (NULL), 68 77 root (NULL) 69 70 78 { 71 79 tree = scew_tree_create(); … … 81 89 root (NULL) 82 90 { 83 91 84 92 if (filePath.length() != 0) { 85 93 // file path should not be null or empty string unless we are … … 105 113 if (code == scew_error_expat) 106 114 { 107 enum XML_Error expat_code = 115 enum XML_Error expat_code = 108 116 scew_error_expat_code(parser); 109 printf("Expat error #%d (line %d, column %d): %s\n", 117 printf("Expat error #%d (line %d, column %d): %s\n", 110 118 expat_code, 111 119 scew_error_expat_line(parser), … … 115 123 // should probably exit program or something 116 124 // return EXIT_FAILURE; 117 125 118 126 } 119 127 … … 127 135 } 128 136 129 137 130 138 // copy constructor 131 139 // for some reason making this a const gives me problems when calling xml() … … 149 157 buffer = other.xml(); 150 158 buffLen = buffer.length(); 151 159 152 160 if (buffLen > 0) { 153 161 if (!scew_parser_load_buffer(parser,buffer.c_str(),buffLen)) … … 161 169 if (code == scew_error_expat) 162 170 { 163 enum XML_Error expat_code = 171 enum XML_Error expat_code = 164 172 scew_error_expat_code(parser); 165 173 printf("Expat error #%d (line %d, column %d): %s\n", … … 172 180 // return an empty RpLibrary? 173 181 // return EXIT_FAILURE; 174 182 175 183 parser = NULL; 176 184 } … … 214 222 215 223 // Loads the XML from other 216 // the length cannot be 0 because xml() should not be returning 224 // the length cannot be 0 because xml() should not be returning 217 225 // empty strings 218 226 buffer = other.xml(); 219 227 buffLen = buffer.length(); 220 228 221 229 if (buffLen > 0) { 222 230 if (!scew_parser_load_buffer(parser,buffer.c_str(),buffLen)) … … 242 250 // or maybe return an empty RpLibrary? 243 251 // return EXIT_FAILURE; 244 252 245 253 // return this object to its previous state. 246 254 parser = tmp_parser; … … 256 264 257 265 // free the current RpLibrary's data 258 // we do the free so far down so we can see if 266 // we do the free so far down so we can see if 259 267 // parsing the other object's xml fails. 260 // if the parsing fails, we can still return this 268 // if the parsing fails, we can still return this 261 269 // object to its previous state. 262 270 if (tmp_tree && tmp_freeTree) { … … 278 286 return *this; 279 287 } // end operator= 280 288 281 289 282 290 // default destructor … … 304 312 scew_tree* tree; 305 313 scew_element* root; 306 307 // flag to tell if we are responsible for calling scew_tree_free 308 // on the tree structure. if we get our tree by using the scew_tree_create 309 // fxn, we need to free it. if we get our tree using the scew_parser_tree 314 315 // flag to tell if we are responsible for calling scew_tree_free 316 // on the tree structure. if we get our tree by using the 317 // scew_tree_create 318 // fxn, we need to free it. if we get our tree using the 319 // scew_parser_tree 310 320 // fxn, then it will be free'd when the parser is free'd. 311 321 int freeTree; … … 316 326 tree (NULL), 317 327 root (node) 318 328 319 329 {} 320 330 … … 324 334 std::string _node2name (scew_element* node); 325 335 std::string _node2comp (scew_element* node); 326 int _splitPath (std::string& path, 327 std::string& tagName, 328 int* idx, 336 int _splitPath (std::string& path, 337 std::string& tagName, 338 int* idx, 329 339 std::string& id ); 330 scew_element* _find (std::string path, int create); 340 scew_element* _find (std::string path, int create); 331 341 void print_indent (unsigned int indent, std::stringstream& outString); 332 342 void print_attributes (scew_element* element, std::stringstream& outString); 333 void print_element( scew_element* element, 334 unsigned int indent, 343 void print_element( scew_element* element, 344 unsigned int indent, 335 345 std::stringstream& outString ); 336 346
Note: See TracChangeset
for help on using the changeset viewer.