Changeset 1581 for trunk/src/objects
- Timestamp:
- Oct 17, 2009, 9:01:23 PM (15 years ago)
- Location:
- trunk/src/objects
- Files:
-
- 4 added
- 12 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/objects/Makefile.in
r1566 r1581 65 65 RpHistogram.h \ 66 66 RpLibObj.h \ 67 RpLibStorage.h \ 67 68 RpNumber.h \ 68 69 RpParserXML.h \ … … 72 73 RpScatter.h \ 73 74 RpString.h \ 75 RpTest.h \ 74 76 RpTree.h \ 75 77 RpObjConfig.h \ … … 95 97 RpHistogram.o \ 96 98 RpLibObj.o \ 99 RpLibStorage.o \ 97 100 RpNumber.o \ 98 101 RpParserXML.o \ … … 102 105 RpScatter.o \ 103 106 RpString.o \ 107 RpTest.o \ 104 108 RpTree.o \ 105 109 RpUtils2.o \ -
trunk/src/objects/RpLibObj.cc
r1566 r1581 25 25 #include <time.h> 26 26 #include <cctype> 27 #include <fstream> 27 28 28 29 using namespace Rappture; … … 41 42 Library::__libInit() 42 43 { 43 _ objList = Rp_ChainCreate();44 _status.addContext("Rappture::Library::__libInit"); 44 45 return; 45 46 } … … 48 49 Library::__libFree() 49 50 { 50 if (_objList != NULL) {51 Rp_ChainLink *l = NULL;52 Rappture::Object *objVal = NULL;53 l = Rp_ChainFirstLink(_objList);54 while(l) {55 objVal = (Rappture::Object *) Rp_ChainGetValue(l);56 delete objVal;57 objVal = NULL;;58 l = Rp_ChainNextLink(l);59 }60 Rp_ChainDestroy(_objList);61 _objList = NULL;62 }63 51 return; 64 52 } … … 85 73 // FIXME: add error check for Rp_ParserXmlParse 86 74 87 // convert xml tree into chain of rappture objects 88 Rp_Chain *tmpObjList = Rp_ChainCreate(); 89 __parseTree2ObjectList(p,tmpObjList); 75 //_objStorage.backup(); 76 _objStorage.clear(); 77 __parseTree2ObjectList(p); 78 /* 90 79 if (!_status) { 91 __libFree(); 92 _objList = tmpObjList; 93 } 80 _objStorage.save(); 81 } else { 82 _objStorage.restore() 83 } 84 */ 94 85 95 86 return _status; … … 107 98 } 108 99 100 // null terminate string holding file 101 fileBuf.append("\0",1); 102 109 103 loadXml(fileBuf.bytes()); 110 104 111 105 return _status; 106 } 107 108 Library & 109 Library::value ( 110 const char *key, 111 void *storage, 112 size_t numHints, 113 ...) 114 { 115 _status.addContext("Rappture::Library::value"); 116 Rappture::Object *o = _objStorage.find(key); 117 118 if (o == NULL) { 119 _status.addError("Error while retrieving object " 120 "with key \"%s\": object does not exist", key); 121 return *this; 122 } 123 124 va_list arg; 125 126 va_start(arg,numHints); 127 o->vvalue(storage,numHints,arg); 128 _status = o->outcome(); 129 va_end(arg); 130 131 return *this; 112 132 } 113 133 … … 115 135 Library::xml() const 116 136 { 137 _status.addContext("Rappture::Library::xml"); 117 138 Rp_ParserXml *p = Rp_ParserXmlCreate(); 118 139 Rp_ChainLink *l = NULL; 119 140 120 l = Rp_ChainFirstLink(_objList); 141 const Rp_Chain *objList = _objStorage.contains(); 142 143 l = Rp_ChainFirstLink(objList); 121 144 122 145 while (l != NULL) { 123 146 Rappture::Object *o = (Rappture::Object *) Rp_ChainGetValue(l); 124 o->dump(RPCONFIG_TREE,(ClientData)p); 147 if (o != NULL) { 148 // FIXME: we can remove the if statement when 149 // LibraryStorage is fixed to clean up holes 150 // in the object chain. 151 o->dump(RPCONFIG_TREE,(ClientData)p); 152 } 125 153 l = Rp_ChainNextLink(l); 126 154 } … … 130 158 131 159 void 132 Library::__parseTree2ObjectList( 133 Rp_ParserXml *p, 134 Rp_Chain *retObjList) 160 Library::__parseTree2ObjectList(Rp_ParserXml *p) 135 161 { 136 162 _status.addContext("Rappture::Library::__parseTree2ObjectList"); … … 141 167 } 142 168 143 if (retObjList == NULL) {144 _status.addError("return object list is NULL");145 return;146 }147 148 // get the children nodes of "tool", "input", and "output"149 169 Rp_Chain *children = Rp_ChainCreate(); 170 171 // parse out the tool information 150 172 // Rp_ParserXmlChildren(p, "tool", NULL, children); 173 // if there is a child called tool, grab its 174 // title char * 175 // about char * 176 // command char * 177 // limits.cputime double 178 // layout char * 179 // control char * 180 // analyzer char * 181 // reportJobFailures int 182 183 // get the children nodes of "input", and "output" 151 184 Rp_ParserXmlChildren(p, "input", NULL, children); 152 185 Rp_ParserXmlChildren(p, "output", NULL, children); … … 164 197 Rappture::Number *obj = new Rappture::Number(); 165 198 obj->configure(RPCONFIG_TREE,(void*)p); 166 Rp_ChainAppend(retObjList,(void*)obj); 199 _objStorage.store(obj->name(),obj); 200 _objStorage.link(obj->name(),obj->path()); 201 // Rp_ChainAppend(retObjList,(void*)obj); 202 203 // FIXME: add code to check for strings, choices, 204 // groups, curves, notes, images, molecules... 205 // all of the rappture object types 167 206 } else { 168 207 _status.addError("unrecognized object type: %s",label); … … 178 217 } 179 218 219 220 180 221 Outcome & 181 222 Library::outcome() const … … 184 225 } 185 226 227 int 228 Library::error() const 229 { 230 return (int) _status; 231 } 232 233 /* 234 Outcome & 235 Library::result(int status) 236 { 237 Rappture::SimpleCharBuffer tmpBuf; 238 std::fstream file; 239 const char *xmlText = NULL; 240 time_t t = 0; 241 struct tm* timeinfo = NULL; 242 timestamp = ""; 243 std::string username = ""; 244 std::string hostname = ""; 245 char *user = NULL; 246 247 tmpBuf.appendf("run%i.xml",(int)time(&t)); 248 file.open(tmpBuf.bytes(),std::ios::out); 249 250 // put("tool.version.rappture.revision", 251 // "$LastChangedRevision: 1527 $"); 252 // put("tool.version.rappture.modified", 253 // "$LastChangedDate: 2009-06-22 15:38:49 -0400" 254 // " (Mon, 22 Jun 2009) $"); 255 // if ( "" == get("tool.version.rappture.language") ) { 256 // put("tool.version.rappture.language","c++"); 257 // } 258 259 // generate a timestamp for the run file 260 timeinfo = localtime(&t); 261 timestamp = std::string(ctime(&t)); 262 // erase the 24th character because it is a newline 263 timestamp.erase(24); 264 // concatinate the timezone 265 timestamp.append(" "); 266 #ifdef _WIN32 267 timestamp.append(_tzname[_daylight]); 268 // username is left blank for windows because i dont know 269 // how to retrieve username on win32 environment. 270 username = ""; 271 hostname = ""; 272 #else 273 timestamp.append(timeinfo->tm_zone); 274 user = getenv("USER"); 275 if (user != NULL) { 276 username = std::string(user); 277 } else { 278 user = getenv("LOGNAME"); 279 if (user != NULL) { 280 username = std::string(user); 281 } 282 } 283 #endif 284 285 // add the timestamp to the run file 286 // put("output.time", timestamp); 287 // put("output.status",exitStatus); 288 // put("output.user",username); 289 // put("output.host",hostname); 290 291 if ( file.is_open() ) { 292 xmlText = xml(); 293 if (xmlText == NULL) { 294 } 295 file << xmlText; 296 // check to make sure there were no 297 // errors while writing the run.xml file. 298 if ( (!file.good()) 299 || (strlen(xmlText) != ((long)file.tellp()-(long)1)) 300 ) { 301 status.error("Error while writing run file"); 302 status.addContext("RpLibrary::result()"); 303 } 304 file.close(); 305 } 306 else { 307 status.error("Error while opening run file"); 308 status.addContext("RpLibrary::result()"); 309 } 310 std::printf("=RAPPTURE-RUN=>%s\n",outputFile.bytes()); 311 } 312 */ 313 186 314 const Rp_Chain * 187 315 Library::contains() const 188 316 { 189 return _objList; 190 } 317 return _objStorage.contains(); 318 } 319 -
trunk/src/objects/RpLibObj.h
r1566 r1581 32 32 #include "RpChain.h" 33 33 #include "RpParserXML.h" 34 #include "RpLibStorage.h" 35 #include <cstdarg> 34 36 35 37 namespace Rappture { … … 46 48 47 49 48 // Library *value(const char *key, void *storage); 50 Library &value(const char *key, void *storage, 51 size_t numHints, ...); 49 52 50 53 // Rp_Chain *diff(Library *lib); 51 54 52 // Library *remove (const char *key);55 // Library &remove (const char *key); 53 56 54 57 const char *xml() const; 55 58 56 59 Outcome &outcome() const; 60 int error() const; 57 61 58 // Library *result(int status);62 // Outcome &result(int status); 59 63 60 64 const Rp_Chain *contains() const; 61 65 private: 62 Rp_Chain *_objList; 63 // Rp_HashTable _objHash; 64 mutable Rappture::Outcome _status; 66 LibraryStorage _objStorage; 67 mutable Outcome _status; 65 68 66 69 void __libInit(); 67 70 void __libFree(); 68 void __parseTree2ObjectList(Rp_ParserXml *p , Rp_Chain *retObjList);71 void __parseTree2ObjectList(Rp_ParserXml *p); 69 72 70 73 }; // end class Library -
trunk/src/objects/RpNumber.cc
r1569 r1581 24 24 _minSet (0), 25 25 _maxSet (0), 26 _defSet (0), 27 _curSet (0), 26 28 _presets (NULL) 27 29 { … … 43 45 _minSet (0), 44 46 _maxSet (0), 47 _defSet (0), 48 _curSet (0), 45 49 _presets (NULL) 46 50 { … … 69 73 _minSet (0), 70 74 _maxSet (0), 75 _defSet (0), 76 _curSet (0), 71 77 _presets (NULL) 72 78 { … … 110 116 : Object (o), 111 117 _minSet (o._minSet), 112 _maxSet (o._maxSet) 118 _maxSet (o._maxSet), 119 _defSet (o._defSet), 120 _curSet (o._curSet) 113 121 { 114 122 this->def(o.def()); … … 139 147 } 140 148 149 int 150 Number::minset() const 151 { 152 return _minSet; 153 } 154 155 int 156 Number::maxset() const 157 { 158 return _maxSet; 159 } 160 161 int 162 Number::defset() const 163 { 164 return _defSet; 165 } 166 167 int 168 Number::curset() const 169 { 170 return _curSet; 171 } 172 141 173 /**********************************************************************/ 142 174 // METHOD: convert() … … 146 178 */ 147 179 148 int 180 Outcome& 149 181 Number::convert(const char *to) 150 182 { 151 183 const RpUnits* toUnit = NULL; 152 184 const RpUnits* fromUnit = NULL; 153 double convertedVal = cur(); 154 int err = 0; 185 186 _status.addContext("Rappture::Number::convert"); 187 188 if (to == NULL) { 189 return _status; 190 } 191 192 if (strcmp(units(),to) == 0) { 193 return _status; 194 } 155 195 156 196 // make sure all units functions accept char*'s 157 197 toUnit = RpUnits::find(std::string(to)); 158 198 if (!toUnit) { 159 // should raise error! 160 // conversion not defined because unit does not exist 161 return convertedVal; 199 _status.addError("conversion not defined, unit \"%s\" does not exist",to); 200 return _status; 162 201 } 163 202 164 203 fromUnit = RpUnits::find(std::string(units())); 165 204 if (!fromUnit) { 166 // should raise error! 167 // conversion not defined because unit does not exist 168 return convertedVal; 205 _status.addError("conversion not defined, unit \"%s\" does not exist",to); 206 return _status; 169 207 } 170 208 171 209 // perform the conversion 210 int err = 0; 211 double convertedVal; 212 172 213 convertedVal = fromUnit->convert(toUnit,def(), &err); 173 if (!err) { 214 if (err) { 215 _status.addError("undefined error while converting %s to %s", 216 (fromUnit->getUnitsName()).c_str(), 217 (toUnit->getUnitsName()).c_str()); 218 } else { 174 219 def(convertedVal); 175 220 } 176 221 177 222 convertedVal = fromUnit->convert(toUnit,cur(), &err); 178 if (!err) { 223 if (err) { 224 _status.addError("undefined error while converting %s to %s", 225 (fromUnit->getUnitsName()).c_str(), 226 (toUnit->getUnitsName()).c_str()); 227 } else { 179 228 cur(convertedVal); 180 229 } 181 230 182 return err;231 return _status; 183 232 } 184 233 … … 188 237 /** 189 238 * does not change the value of the object 190 * error code is returned 191 */ 192 193 int 194 Number::value(const char *to, double *value) const 195 { 196 return 1; 239 * error code is set on trouble 240 */ 241 242 double 243 Number::value(const char *to) const 244 { 245 const RpUnits* toUnit = NULL; 246 const RpUnits* fromUnit = NULL; 247 248 _status.addContext("Rappture::Number::value"); 249 250 double val = 0.0; 251 252 if (_defSet) { 253 val = def(); 254 } 255 256 if (_curSet) { 257 val = cur(); 258 } 259 260 if (to == NULL) { 261 return val; 262 } 263 264 if (strcmp(units(),to) == 0) { 265 return val; 266 } 267 268 // make sure all units functions accept char*'s 269 toUnit = RpUnits::find(std::string(to)); 270 if (!toUnit) { 271 _status.addError("conversion not defined, unit \"%s\" does not exist",to); 272 return val; 273 } 274 275 fromUnit = RpUnits::find(std::string(units())); 276 if (!fromUnit) { 277 _status.addError("conversion not defined, unit \"%s\" does not exist",to); 278 return val; 279 } 280 281 // perform the conversion 282 int err = 0; 283 double convertedVal = fromUnit->convert(toUnit,val, &err); 284 if (err) { 285 _status.addError("undefined error while converting %s to %s", 286 (fromUnit->getUnitsName()).c_str(), 287 (toUnit->getUnitsName()).c_str()); 288 return cur(); 289 } 290 291 return convertedVal; 292 } 293 294 /**********************************************************************/ 295 // METHOD: vvalue() 296 /// Get the value of this object based on provided hints 297 /** 298 * does not change the value of the object 299 * currently recognized hints: 300 * units 301 * error code is set on trouble 302 */ 303 304 void 305 Number::vvalue(void *storage, size_t numHints, va_list arg) const 306 { 307 char buf[1024]; 308 char *hintCopy = NULL; 309 size_t hintLen = 0; 310 311 char *hint = NULL; 312 const char *hintKey = NULL; 313 const char *hintVal = NULL; 314 315 double *ret = (double *) storage; 316 317 *ret = 0.0; 318 319 if (_defSet) { 320 *ret = def(); 321 } 322 323 if (_curSet) { 324 *ret = cur(); 325 } 326 327 while (numHints > 0) { 328 numHints--; 329 hint = va_arg(arg, char *); 330 hintLen = strlen(hint); 331 if (hintLen < 1024) { 332 hintCopy = buf; 333 } else { 334 // buf too small, allocate some space 335 hintCopy = new char[hintLen]; 336 } 337 strcpy(hintCopy,hint); 338 339 // parse the hint into a key and value 340 __hintParser(hintCopy,&hintKey,&hintVal); 341 342 // evaluate the hint key 343 if (('u' == *hintKey) && 344 (strcmp("units",hintKey) == 0)) { 345 *ret = value(hintVal); 346 347 } 348 349 if (hintCopy != buf) { 350 // clean up memory 351 delete hintCopy; 352 } 353 } 354 return; 197 355 } 198 356 … … 300 458 } 301 459 302 /**********************************************************************/303 // METHOD: configure(ClientData c)304 /// construct a number object from the provided tree305 /**306 * construct a number object from the provided tree307 */308 309 void310 Number::configure(size_t as, ClientData c)311 {312 if (as == RPCONFIG_XML) {313 __configureFromXml(c);314 } else if (as == RPCONFIG_TREE) {315 __configureFromTree(c);316 }317 }318 319 /**********************************************************************/320 // METHOD: configureFromXml(const char *xmltext)321 /// configure the object based on Rappture1.1 xmltext322 /**323 * Configure the object based on the provided xml324 */325 326 void327 Number::__configureFromXml(ClientData c)328 {329 const char *xmltext = (const char *)c;330 if (xmltext == NULL) {331 // FIXME: setup error332 return;333 }334 335 Rp_ParserXml *p = Rp_ParserXmlCreate();336 Rp_ParserXmlParse(p, xmltext);337 configure(RPCONFIG_TREE, p);338 339 return;340 }341 342 460 void 343 461 Number::__configureFromTree(ClientData c) … … 394 512 395 513 /**********************************************************************/ 396 // METHOD: dump(size_t as, void *p) 397 /// construct a number object from the provided tree 398 /** 399 * construct a number object from the provided tree 400 */ 401 402 void 403 Number::dump(size_t as, ClientData p) 404 { 405 if (as == RPCONFIG_XML) { 406 __dumpToXml(p); 407 } else if (as == RPCONFIG_TREE) { 408 __dumpToTree(p); 409 } 410 } 411 412 /**********************************************************************/ 413 // METHOD: dumpToXml(ClientData p) 414 /// configure the object based on Rappture1.1 xmltext 415 /** 416 * Configure the object based on the provided xml 417 */ 418 419 void 420 Number::__dumpToXml(ClientData c) 514 // METHOD: dumpToTree(ClientData p) 515 /// dump the object to a Rappture1.1 based tree 516 /** 517 * Dump the object to a Rappture1.1 based tree 518 */ 519 520 void 521 Number::__dumpToTree(ClientData c) 421 522 { 422 523 if (c == NULL) { … … 425 526 } 426 527 427 ClientDataXml *d = (ClientDataXml *)c;428 Rp_ParserXml *parser = Rp_ParserXmlCreate();429 __dumpToTree(parser);430 _tmpBuf.appendf("%s",Rp_ParserXmlXml(parser));431 d->retStr = _tmpBuf.bytes();432 Rp_ParserXmlDestroy(&parser);433 }434 435 /**********************************************************************/436 // METHOD: dumpToTree(ClientData p)437 /// dump the object to a Rappture1.1 based tree438 /**439 * Dump the object to a Rappture1.1 based tree440 */441 442 void443 Number::__dumpToTree(ClientData c)444 {445 if (c == NULL) {446 // FIXME: setup error447 return;448 }449 450 528 Rp_ParserXml *parser = (Rp_ParserXml *)c; 451 529 … … 463 541 Rp_ParserXmlPutF(parser,p.path(),"%s",label()); 464 542 543 p.type("description"); 544 Rp_ParserXmlPutF(parser,p.path(),"%s",desc()); 545 465 546 p.del(); 466 p.add("description"); 467 Rp_ParserXmlPutF(parser,p.path(),"%s",desc()); 468 469 p.del(); 470 p.del(); 471 p.add("units"); 547 p.type("units"); 472 548 Rp_ParserXmlPutF(parser,p.path(),"%s",units()); 473 549 474 550 475 551 if (_minSet) { 476 p.del(); 477 p.add("min"); 478 Rp_ParserXmlPutF(parser,p.path(),"%g",min()); 552 p.type("min"); 553 Rp_ParserXmlPutF(parser,p.path(),"%g%s",min(),units()); 479 554 } 480 555 481 556 if (_maxSet) { 482 p.del(); 483 p.add("max"); 484 Rp_ParserXmlPutF(parser,p.path(),"%g",max()); 485 } 486 487 p.del(); 488 p.add("default"); 489 Rp_ParserXmlPutF(parser,p.path(),"%g",def()); 490 491 p.del(); 492 p.add("current"); 493 Rp_ParserXmlPutF(parser,p.path(),"%g",cur()); 494 495 // still need to add presets 557 p.type("max"); 558 Rp_ParserXmlPutF(parser,p.path(),"%g%s",max(),units()); 559 } 560 561 p.type("default"); 562 Rp_ParserXmlPutF(parser,p.path(),"%g%s",def(),units()); 563 564 p.type("current"); 565 Rp_ParserXmlPutF(parser,p.path(),"%g%s",cur(),units()); 566 567 // process presets 568 p.type("preset"); 569 p.add("label"); 570 Rp_ChainLink *l = Rp_ChainFirstLink(_presets); 571 while (l != NULL) { 572 struct preset *presetObj = (struct preset *) Rp_ChainGetValue(l); 573 574 p.type("label"); 575 Rp_ParserXmlPutF(parser,p.path(),"%s",presetObj->label()); 576 //p.type("description"); 577 //Rp_ParserXmlPutF(parser,p.path(),"%s",presetObj->desc()); 578 // p.type("units"); 579 // Rp_ParserXmlPutF(parser,p.path(),"%s",presetObj->units()); 580 p.type("value"); 581 Rp_ParserXmlPutF(parser,p.path(),"%g%s",presetObj->val(),presetObj->units()); 582 583 p.prev(); 584 p.degree(p.degree()+1); 585 p.next(); 586 587 l = Rp_ChainNextLink(l); 588 } 589 496 590 return; 497 591 } … … 512 606 513 607 608 void 609 Number::__convertFromString( 610 const char *val, 611 double *ret) 612 { 613 if (val == NULL) { 614 return; 615 } 616 617 if (ret == NULL) { 618 return; 619 } 620 621 double numericVal = 0.0; 622 if (units()) { 623 // convert the provided string into 624 // the objects default units 625 int err = 0; 626 std::string strVal; 627 strVal = RpUnits::convert(val,units(),RPUNITS_UNITS_OFF,&err); 628 if (err) { 629 _status.addError("Unknown error while converting units"); 630 } 631 632 char *endPtr = NULL; 633 numericVal = strtod(strVal.c_str(),&endPtr); 634 if (endPtr == strVal.c_str()) { 635 // no conversion was performed 636 _status.addError("Could not convert \"%s\" into a number", 637 strVal.c_str()); 638 } else if (endPtr == (strVal.c_str()+strVal.length())) { 639 *ret = numericVal; 640 } else { 641 // the whole string could not be converted to a number 642 // signal error? 643 _status.addError("Could not convert \"%s\" of \"%s\"into a number", 644 endPtr, strVal.c_str()); 645 } 646 } else { 647 // try to figure out the units 648 // store units and return the numeric value to the user 649 const char *foundUnits = NULL; 650 __valUnitsSplit(val,&numericVal,&foundUnits); 651 units(foundUnits); 652 *ret = numericVal; 653 } 654 655 } 656 657 void 658 Number::__valUnitsSplit( 659 const char *inStr, 660 double *val, 661 const char **units) 662 { 663 if (inStr == NULL) { 664 return; 665 } 666 667 if (val == NULL) { 668 return; 669 } 670 671 if (units == NULL) { 672 return; 673 } 674 675 char *endPtr = NULL; 676 *val = strtod(inStr,&endPtr); 677 if (endPtr == inStr) { 678 // no conversion was performed 679 _status.addError("Could not convert \"%s\" into a number", inStr); 680 } else if (endPtr == (inStr+strlen(inStr))) { 681 // the whole string was used in the numeric conversion 682 // set units to NULL 683 *units = NULL; 684 } else { 685 // the whole string could not be converted to a number 686 // we assume the rest of the string are the units 687 *units = endPtr; 688 } 689 } 690 514 691 /**********************************************************************/ 515 692 // METHOD: minFromStr() … … 524 701 { 525 702 double numericVal = 0; 526 int err = 0; 527 528 numericVal = rpConvertDbl(val,units(),&err); 529 530 if (!err) { 703 704 if (val == NULL) { 705 return; 706 } 707 708 __convertFromString(val,&numericVal); 709 710 if (!_status) { 531 711 min(numericVal); 532 } else {533 // FIXME: add error code534 } 712 _minSet = 1; 713 } 714 535 715 } 536 716 … … 547 727 { 548 728 double numericVal = 0; 549 int err = 0; 550 551 numericVal = rpConvertDbl(val,units(),&err); 552 553 if (!err) { 729 730 if (val == NULL) { 731 return; 732 } 733 734 __convertFromString(val,&numericVal); 735 736 if (!_status) { 554 737 max(numericVal); 555 } else {556 // FIXME: add error code557 } 738 _maxSet = 1; 739 } 740 558 741 } 559 742 … … 570 753 { 571 754 double numericVal = 0; 572 int err = 0; 573 574 numericVal = rpConvertDbl(val,units(),&err); 575 576 if (!err) { 755 756 if (val == NULL) { 757 return; 758 } 759 760 __convertFromString(val,&numericVal); 761 762 if (!_status) { 577 763 def(numericVal); 578 } else {579 // FIXME: add error code580 } 764 _defSet = 1; 765 } 766 581 767 } 582 768 … … 593 779 { 594 780 double numericVal = 0; 595 int err = 0; 596 597 numericVal = rpConvertDbl(val,units(),&err); 598 599 if (!err) { 781 782 if (val == NULL) { 783 return; 784 } 785 786 __convertFromString(val,&numericVal); 787 788 if (!_status) { 600 789 cur(numericVal); 601 } else {602 // FIXME: add error code603 } 790 _curSet = 1; 791 } 792 604 793 } 605 794 -
trunk/src/objects/RpNumber.h
r1569 r1581 39 39 void units(const char *p); 40 40 41 int minset() const; 42 int maxset() const; 43 int defset() const; 44 int curset() const; 45 41 46 // convert the value stored in this object to specified units 42 47 // does not return the converted value 43 48 // error code is returned 44 intconvert(const char *to);49 Outcome& convert(const char *to); 45 50 46 51 // get the value of this object converted to specified units 47 52 // does not change the value of the object 48 53 // error code is returned 49 int value(const char *units, double *value) const; 54 double value(const char *units) const; 55 void vvalue(void *storage, size_t numHints, va_list arg) const; 50 56 51 57 Number& addPreset(const char *label, const char *desc, … … 57 63 Number& delPreset(const char *label); 58 64 59 60 void configure(size_t as, ClientData c);61 void dump(size_t as, ClientData c);62 65 63 66 const int is() const; … … 73 76 int _minSet; 74 77 int _maxSet; 78 int _defSet; 79 int _curSet; 75 80 76 81 // hash or linked list of preset values … … 84 89 }; 85 90 86 void __configureFromXml(ClientData c);87 91 void __configureFromTree(ClientData c); 88 void __dumpToXml(ClientData c);89 92 void __dumpToTree(ClientData c); 93 94 void __convertFromString(const char *val, double *ret); 95 void __valUnitsSplit( const char *inStr, double *val, 96 const char **units); 90 97 }; 91 98 -
trunk/src/objects/RpObject.cc
r1569 r1581 16 16 #include "RpObject.h" 17 17 #include "RpHashHelper.h" 18 #include <cstring> 18 19 19 20 using namespace Rappture; … … 251 252 delete[] tmp; 252 253 tmp = NULL; 254 return; 255 } 256 257 void 258 Object::__hintParser( 259 char *hint, 260 const char **hintKey, 261 const char **hintVal) const 262 { 263 264 // hints are null terminated strings with a hint key 265 // and hint value separated by an equal sign. 266 // they take the following form: 267 // hintKey=hintVal 268 // this function does change the original hint string. 269 270 char *v = NULL; 271 272 if (hint == NULL) { 273 return; 274 } 275 276 v = strchrnul(hint,'='); 277 *hintKey = hint; 278 if ((*v == '\0') || (*(v+1) == '\0')) { 279 // incomplete hint string 280 *hintVal = NULL; 281 } else { 282 *v = '\0'; 283 *hintVal = v+1; 284 } 285 286 return; 287 } 288 289 void 290 Object::vvalue(void *storage, size_t numHints, va_list arg) const 291 { 292 // bland objects take no hints 293 char buf[1024]; 294 char *hintCopy = NULL; 295 size_t hintLen = 0; 296 297 char *hint = NULL; 298 const char *hintKey = NULL; 299 const char *hintVal = NULL; 300 301 while (numHints > 0) { 302 numHints--; 303 hint = va_arg(arg, char *); 304 hintLen = strlen(hint); 305 if (hintLen < 1024) { 306 hintCopy = buf; 307 } else { 308 hintCopy = new char[hintLen+1]; 309 } 310 strcpy(hintCopy,hint); 311 __hintParser(hintCopy,&hintKey,&hintVal); 312 if (hintCopy != buf) { 313 delete hintCopy; 314 } 315 } 253 316 return; 254 317 } … … 297 360 } 298 361 362 /* 299 363 const char * 300 364 Object::xml(size_t indent, size_t tabstop) const … … 302 366 return NULL; 303 367 } 368 */ 304 369 305 370 /* … … 311 376 */ 312 377 378 /**********************************************************************/ 379 // METHOD: configure(ClientData c) 380 /// construct an object from the provided tree 381 /** 382 * construct an object from the provided tree 383 */ 384 313 385 void 314 386 Object::configure(size_t as, ClientData c) 315 387 { 316 return; 317 } 318 319 void 320 Object::dump(size_t as, ClientData c) 321 { 322 return; 388 if (as == RPCONFIG_XML) { 389 __configureFromXml(c); 390 } else if (as == RPCONFIG_TREE) { 391 __configureFromTree(c); 392 } 393 } 394 395 /**********************************************************************/ 396 // METHOD: configureFromXml(const char *xmltext) 397 /// configure the object based on Rappture1.1 xmltext 398 /** 399 * Configure the object based on the provided xml 400 */ 401 402 void 403 Object::__configureFromXml(ClientData c) 404 { 405 const char *xmltext = (const char *)c; 406 if (xmltext == NULL) { 407 // FIXME: setup error 408 return; 409 } 410 411 Rp_ParserXml *p = Rp_ParserXmlCreate(); 412 Rp_ParserXmlParse(p, xmltext); 413 __configureFromTree(p); 414 415 return; 416 } 417 418 void 419 Object::__configureFromTree(ClientData c) 420 { 421 Rp_ParserXml *p = (Rp_ParserXml *)c; 422 if (p == NULL) { 423 // FIXME: setup error 424 return; 425 } 426 427 Rp_TreeNode node = Rp_ParserXmlElement(p,NULL); 428 429 Rappture::Path pathObj(Rp_ParserXmlNodePath(p,node)); 430 431 path(pathObj.parent()); 432 name(Rp_ParserXmlNodeId(p,node)); 433 434 pathObj.clear(); 435 pathObj.add("about"); 436 pathObj.add("label"); 437 label(Rp_ParserXmlGet(p,pathObj.path())); 438 pathObj.type("description"); 439 desc(Rp_ParserXmlGet(p,pathObj.path())); 440 pathObj.type("hints"); 441 hints(Rp_ParserXmlGet(p,pathObj.path())); 442 pathObj.type("color"); 443 color(Rp_ParserXmlGet(p,pathObj.path())); 444 445 return; 446 } 447 448 /**********************************************************************/ 449 // METHOD: dump(size_t as, void *p) 450 /// construct a number object from the provided tree 451 /** 452 * construct a number object from the provided tree 453 */ 454 455 void 456 Object::dump(size_t as, ClientData p) 457 { 458 if (as == RPCONFIG_XML) { 459 __dumpToXml(p); 460 } else if (as == RPCONFIG_TREE) { 461 __dumpToTree(p); 462 } 463 } 464 465 /**********************************************************************/ 466 // METHOD: dumpToXml(ClientData p) 467 /// configure the object based on Rappture1.1 xmltext 468 /** 469 * Configure the object based on the provided xml 470 */ 471 472 void 473 Object::__dumpToXml(ClientData c) 474 { 475 if (c == NULL) { 476 // FIXME: setup error 477 return; 478 } 479 480 ClientDataXml *d = (ClientDataXml *)c; 481 Rp_ParserXml *parser = Rp_ParserXmlCreate(); 482 __dumpToTree(parser); 483 _tmpBuf.appendf("%s",Rp_ParserXmlXml(parser)); 484 d->retStr = _tmpBuf.bytes(); 485 Rp_ParserXmlDestroy(&parser); 486 } 487 488 /**********************************************************************/ 489 // METHOD: dumpToTree(ClientData p) 490 /// dump the object to a Rappture1.1 based tree 491 /** 492 * Dump the object to a Rappture1.1 based tree 493 */ 494 495 void 496 Object::__dumpToTree(ClientData c) 497 { 498 if (c == NULL) { 499 // FIXME: setup error 500 return; 501 } 502 503 Rp_ParserXml *parser = (Rp_ParserXml *)c; 504 505 Path p; 506 507 p.parent(path()); 508 p.last(); 509 510 p.add("object"); 511 p.id(name()); 512 513 p.add("about"); 514 515 p.add("label"); 516 Rp_ParserXmlPutF(parser,p.path(),"%s",label()); 517 518 p.type("description"); 519 Rp_ParserXmlPutF(parser,p.path(),"%s",desc()); 520 521 p.type("hints"); 522 Rp_ParserXmlPutF(parser,p.path(),"%s", hints()); 523 524 p.type("color"); 525 Rp_ParserXmlPutF(parser,p.path(),"%s", color()); 526 527 return; 528 } 529 530 Outcome & 531 Object::outcome() const 532 { 533 return _status; 323 534 } 324 535 -
trunk/src/objects/RpObject.h
r1569 r1581 14 14 #include "RpInt.h" 15 15 #include "RpHash.h" 16 #include "RpOutcome.h" 16 17 #include "RpAccessor.h" 17 18 #include "RpBuffer.h" … … 19 20 #include "RpParserXML.h" 20 21 #include "RpObjConfig.h" 22 #include <cstdarg> 21 23 22 24 namespace Rappture { … … 71 73 void propremove (const char *key); 72 74 75 // return the value of object based on provided hints 76 virtual void vvalue (void *storage, size_t numHints, va_list arg) const; 77 73 78 // get the Rappture1.1 xml text for this object 74 virtual const char *xml(size_t indent, size_t tabstop) const; 75 76 // set the object properties based on Rappture1.1 xml text 77 // virtual void xml(const char *xmltext); 79 // virtual const char *xml(size_t indent, size_t tabstop) const; 78 80 79 81 // configure the object properties based on Rappture1.1 xml text … … 81 83 virtual void dump(size_t as, ClientData c); 82 84 85 virtual Outcome &outcome() const; 83 86 virtual const int is() const; 84 87 … … 88 91 SimpleCharBuffer _tmpBuf; 89 92 93 /// status of the object 94 mutable Rappture::Outcome _status; 95 96 virtual void __hintParser(char *hint, 97 const char **hintKey, const char **hintVal) const; 98 99 virtual void __configureFromXml(ClientData c); 100 virtual void __configureFromTree(ClientData c); 101 virtual void __dumpToXml(ClientData c); 102 virtual void __dumpToTree(ClientData c); 90 103 private: 91 104 -
trunk/src/objects/RpParserXML.cc
r1568 r1581 70 70 Rp_TreeGetValue(inf->tree,inf->curr,Rp_ParserXml_Field_VALUE,(void **)&value); 71 71 72 // strip trailing spaces 73 int i = 0; 74 for (i = strlen(value)-1; i >= 0; i--) { 75 if (isspace(value[i])) { 76 value[i] = '\0'; 77 } else { 78 break; 79 } 80 } 81 82 // strip leading spaces 83 int j = 0; 84 for (j = 0; j < i; j++) { 85 if (isspace(value[j])) { 86 value[j] = '\0'; 87 } else { 88 break; 89 } 90 } 91 92 if (j > 0) { 93 // reallocate the trimmed string 94 char *newValue = new char[i-j+1+1]; 95 strcpy(newValue,value+j); 96 Rp_TreeSetValue(inf->tree,inf->curr,Rp_ParserXml_Field_VALUE,(void *)newValue); 97 delete value; 98 value = NULL; 72 if (value != NULL) { 73 // strip trailing spaces 74 int i = 0; 75 for (i = strlen(value)-1; i >= 0; i--) { 76 if (isspace(value[i])) { 77 value[i] = '\0'; 78 } else { 79 break; 80 } 81 } 82 83 // strip leading spaces 84 int j = 0; 85 for (j = 0; j < i; j++) { 86 if (isspace(value[j])) { 87 value[j] = '\0'; 88 } else { 89 break; 90 } 91 } 92 93 if (j > 0) { 94 // reallocate the trimmed string 95 char *newValue = new char[i-j+1+1]; 96 strcpy(newValue,value+j); 97 Rp_TreeSetValue(inf->tree,inf->curr,Rp_ParserXml_Field_VALUE, 98 (void *)newValue); 99 delete value; 100 value = NULL; 101 } 99 102 } 100 103 … … 218 221 } 219 222 223 int 224 Rp_ParserXmlNodeIdentify( 225 Rp_ParserXml *p, 226 Rp_TreeNode n, 227 const char *name, 228 const char *id) 229 { 230 int criteriaMet = 0; 231 int criteriaTotal = 0; 232 233 if (n) { 234 if (name) { 235 criteriaTotal++; 236 if (strcmp(name,Rp_TreeNodeLabel(n)) == 0) { 237 criteriaMet++; 238 } 239 } 240 if (id) { 241 criteriaTotal++; 242 const char *nodeId = NULL; 243 Rp_TreeGetValue(p->tree,n,Rp_ParserXml_Field_ID, 244 (void **)&nodeId); 245 if (strcmp(id,nodeId) == 0) { 246 criteriaMet++; 247 } 248 } 249 } 250 251 // check if all of the eligable criteria have been met 252 int retVal = 0; 253 if (criteriaMet == criteriaTotal) { 254 retVal = 0; 255 } else { 256 retVal = 1; 257 } 258 259 return retVal; 260 261 } 262 263 void 264 Rp_ParserXmlFindChild( 265 Rp_ParserXml *p, 266 Rp_TreeNode parent, 267 const char *childName, 268 const char *childId, 269 size_t degree, 270 Rp_TreeNode *child, 271 size_t *numFound) 272 { 273 // this function is only concerned with the question: 274 // is a node with a matching name, id, and degree a 275 // child of the provided parent node? 276 // if so return it. 277 // this function does not create new nodes. 278 279 if (child == NULL) { 280 return; 281 } 282 283 if (numFound == NULL) { 284 return; 285 } 286 287 *numFound = 0; 288 *child = Rp_TreeFindChild(parent,childName); 289 if (*child == NULL) { 290 // no nodes with the name childName exist 291 return; 292 } 293 294 while (*child != NULL) { 295 if (Rp_ParserXmlNodeIdentify(p,*child,childName,childId) == 0) { 296 // found a child with the correct name and id 297 (*numFound)++; 298 if (degree == *numFound) { 299 // found a node with the correct degree 300 break; 301 } 302 } 303 304 // check the next child for the correct name and id 305 *child = Rp_TreeNextSibling(*child); 306 } 307 308 return; 309 } 310 220 311 Rp_TreeNode 221 312 Rp_ParserXmlSearch( … … 227 318 Rp_TreeNode parent = NULL; 228 319 Rp_TreeNode child = NULL; 229 size_t degree = 0;230 320 231 321 if (p == NULL) { … … 244 334 245 335 const char *childName = pathObj.type(); 246 const char *searchChildId = pathObj.id(); 247 248 child = Rp_TreeFindChild(parent,childName); 336 const char *childId = pathObj.id(); 337 size_t childDegree = pathObj.degree(); 338 339 size_t foundCnt = 0; 340 Rp_ParserXmlFindChild(p, parent, childName, childId, 341 childDegree, &child, &foundCnt); 342 249 343 if (child == NULL) { 250 344 // no nodes with the name childName exist 251 345 // FIXME: use the RPXML_CREATE flag 252 346 if (create) { 253 for (size_t i = 1; i <=pathObj.degree(); i++) {347 for (size_t i = foundCnt; i < pathObj.degree(); i++) { 254 348 child = Rp_ParserXmlCreateNode(p, parent, 255 childName, searchChildId);349 childName, childId); 256 350 if (child == NULL) { 351 // error while creating the child node 352 // signal error 257 353 break; 258 354 } 259 355 } 260 356 } else { 261 fprintf(stderr,"invalid path %s at %s\n",path,childName);357 // fprintf(stderr,"invalid path %s at %s\n",path,childName); 262 358 break; 263 359 } 264 }265 266 //FIXME: rewrite the child id search logic267 const char *id = NULL;268 Rp_TreeGetValue(p->tree,child, Rp_ParserXml_Field_ID,(void **)&id);269 while (searchChildId && id) {270 271 // check for matching child id and degree272 if ((*searchChildId == *id) &&273 (strcmp(searchChildId,id) == 0)) {274 // found child with matching id275 // check degree276 degree++;277 if (degree == pathObj.degree()) {278 // degrees match, return result279 break;280 }281 }282 283 // check the next child to see if it has the correct id284 child = Rp_TreeNextSibling(child);285 if (child == NULL) {286 // end of the sibling list287 // create new node? or return NULL pointer288 // FIXME: use the RPXML_CREATE flag289 if (create) {290 child = Rp_ParserXmlCreateNode(p, parent,291 childName, searchChildId);292 if (child == NULL) {293 break;294 }295 } else {296 // exit, child not found297 break;298 }299 }300 id = NULL;301 Rp_TreeGetValue(p->tree,child,Rp_ParserXml_Field_ID,(void **)&id);302 360 } 303 361 -
trunk/src/objects/RpParserXML.h
r1566 r1581 29 29 30 30 void Rp_ParserXmlParse(Rp_ParserXml *p, const char *xml); 31 int Rp_ParserXmlNodeIdentify(Rp_ParserXml *p, Rp_TreeNode n, 32 const char *name, const char *id); 33 void Rp_ParserXmlFindChild( Rp_ParserXml *p, Rp_TreeNode parent, 34 const char *childName, const char *childId, size_t degree, 35 Rp_TreeNode *child, size_t *numFound); 31 36 Rp_TreeNode Rp_ParserXmlSearch( Rp_ParserXml *p, const char *path, int create); 32 37 const char *Rp_ParserXmlGet(Rp_ParserXml *p, const char *path); -
trunk/src/objects/RpPath.cc
r1569 r1581 134 134 Path::__createComponent( 135 135 const char *p, 136 int start,137 int end,136 int typeStart, 137 int typeEnd, 138 138 int idOpenParen, 139 139 int idCloseParen, … … 149 149 c->degree = degree; 150 150 151 typeLen = typeEnd - typeStart; 151 152 if (idOpenParen < idCloseParen) { 152 153 // user specified an id 153 typeLen = idOpenParen - start;154 154 idLen = idCloseParen - idOpenParen - 1; 155 } else {156 // no id found157 typeLen = end - start;158 155 } 159 156 … … 183 180 if (typeLen >= 0) { 184 181 tmp = new char[typeLen+1]; 185 strncpy(tmp,(p+ start),typeLen);182 strncpy(tmp,(p+typeStart),typeLen); 186 183 tmp[typeLen] = '\0'; 187 184 c->type = tmp; … … 215 212 Path::__parse(const char *p) 216 213 { 217 int start = 0; 218 int end = 0; 214 int typeStart = 0; 215 int typeEnd = -1; // typeEnd must be less than typeStart 216 // so we can check if there was a type 217 int curr = 0; 219 218 int idOpenParen = -1; 220 219 int idCloseParen = -1; … … 229 228 } 230 229 231 while (p[end] != '\0') { 232 if (p[end] == '(') { 233 idOpenParen = end; 234 } else if (p[end] == ')') { 235 idCloseParen = end; 230 while (p[curr] != '\0') { 231 if (p[curr] == '(') { 232 idOpenParen = curr; 233 typeEnd = curr; 234 } else if (p[curr] == ')') { 235 idCloseParen = curr; 236 236 } else if ( (idOpenParen <= idCloseParen) && 237 (end != 0) && 238 (p[end] >= '0') && 239 (p[end] <= '9') ) { 240 degree = (size_t) strtod(p+end, &newEnd); 237 (curr != 0) && 238 (p[curr] >= '0') && 239 (p[curr] <= '9') ) { 240 // we are not inside the parens 241 // we are not at the start of the string 242 // the value is a digit 243 if (idOpenParen == idCloseParen) { 244 // we are before any possible parens 245 // and after the type 246 typeEnd = curr; 247 } 248 degree = (size_t) strtod(p+curr, &newEnd); 241 249 if (degree == 0) { 242 250 // interpret degree of 0 same as degree of 1 … … 247 255 newEnd -= 2; 248 256 } 249 end += newEnd - (p + end); 250 } else if (p[end] == _ifs) { 251 c = __createComponent(p,start,end,idOpenParen,idCloseParen,degree); 257 curr += newEnd - (p + curr); 258 } else if ( (p[curr] == _ifs) && 259 ((idOpenParen == idCloseParen) || 260 (idOpenParen < idCloseParen)) ) { 261 // we see the _ifs 262 // we are not inside of the parens for the id tag 263 if (typeEnd < typeStart) { 264 // we didn't come across the end 265 // of the type string, so set it here. 266 typeEnd = curr; 267 } 268 c = __createComponent(p,typeStart,typeEnd,idOpenParen,idCloseParen,degree); 252 269 if (c != NULL) { 253 270 Rp_ChainAppend(compList,c); 254 271 } 255 272 256 start = end+1;273 typeStart = curr+1; 257 274 idOpenParen = -1; 258 275 idCloseParen = -1; 259 } 260 end++; 261 } 262 263 c = __createComponent(p,start,end,idOpenParen,idCloseParen,degree); 276 degree = 1; 277 } 278 curr++; 279 } 280 281 if (typeEnd < typeStart) { 282 // < takes care of cases where there is no 283 // id and no degree, but there is still a type 284 typeEnd = curr; 285 } 286 c = __createComponent(p,typeStart,typeEnd,idOpenParen,idCloseParen,degree); 264 287 if (c != NULL) { 265 288 Rp_ChainAppend(compList,c); … … 291 314 b.append(c->type,len); 292 315 } 316 } 317 318 if (c->degree > 1) { 319 b.appendf("%i",c->degree); 293 320 } 294 321 … … 428 455 Rp_ChainLink *l = NULL; 429 456 430 /*431 tmpBuf.clear();432 433 if (_pathList == NULL) {434 tmpBuf.append("\0",1);435 return tmpBuf.bytes();436 }437 438 l = _currLink;439 440 if (l == NULL) {441 tmpBuf.append("\0",1);442 return tmpBuf.bytes();443 }444 445 componentStruct *c = (componentStruct *) Rp_ChainGetValue(l);446 447 if (c == NULL) {448 tmpBuf.append("\0",1);449 return tmpBuf.bytes();450 }451 452 if (c->type != NULL) {453 tmpBuf.appendf("%s",c->type);454 }455 456 if (c->degree != 1) {457 tmpBuf.appendf("%zu",c->degree);458 }459 460 if (c->id != NULL) {461 tmpBuf.appendf("(%s)",c->id);462 }463 464 // incase none of the above if statements are hit.465 tmpBuf.append("\0",1);466 467 return tmpBuf.bytes();468 */469 470 471 457 if (_pathList == NULL) { 472 458 return NULL; … … 571 557 { 572 558 Rp_ChainLink *l = NULL; 573 574 /*575 tmpBuf.clear();576 577 if (_pathList == NULL) {578 tmpBuf.append("\0",1);579 return tmpBuf.bytes();580 }581 582 l = _currLink;583 584 if (l == NULL) {585 tmpBuf.append("\0",1);586 return tmpBuf.bytes();587 }588 589 componentStruct *c = (componentStruct *) Rp_ChainGetValue(l);590 591 if (c == NULL) {592 tmpBuf.append("\0",1);593 return tmpBuf.bytes();594 }595 596 if (c->id) {597 tmpBuf.append(c->id);598 }599 600 tmpBuf.append("\0",1);601 602 return tmpBuf.bytes();603 */604 559 605 560 if (_pathList == NULL) { … … 664 619 Rp_ChainLink *l = NULL; 665 620 666 /*667 tmpBuf.clear();668 669 if (_pathList == NULL) {670 tmpBuf.append("\0",1);671 return tmpBuf.bytes();672 }673 674 l = _currLink;675 676 if (l == NULL) {677 tmpBuf.append("\0",1);678 return tmpBuf.bytes();679 }680 681 componentStruct *c = (componentStruct *) Rp_ChainGetValue(l);682 683 if (c == NULL) {684 tmpBuf.append("\0",1);685 return tmpBuf.bytes();686 }687 688 if (c->type) {689 tmpBuf.append(c->type);690 }691 692 tmpBuf.append("\0",1);693 694 return tmpBuf.bytes();695 */696 697 621 if (_pathList == NULL) { 698 622 return NULL; -
trunk/src/objects/RpPlot.cc
r1569 r1581 249 249 } 250 250 251 /**********************************************************************/ 252 // METHOD: configure(Rp_ParserXml *c) 253 /// construct a number object from the provided tree 254 /** 255 * construct a number object from the provided tree 256 */ 257 258 void 259 Plot::configure(size_t as, ClientData c) 260 { 261 if (as == RPCONFIG_XML) { 262 __configureFromXml(c); 263 } else if (as == RPCONFIG_TREE) { 264 __configureFromTree(c); 265 } 266 } 267 268 /**********************************************************************/ 269 // METHOD: configureFromXml(const char *xmltext) 270 /// configure the object based on Rappture1.1 xmltext 271 /** 272 * Configure the object based on the provided xml 273 */ 274 275 void 276 Plot::__configureFromXml(ClientData c) 277 { 278 const char *xmltext = (const char *) c; 279 if (xmltext == NULL) { 280 // FIXME: setup error 281 return; 282 } 283 284 Rp_ParserXml *p = Rp_ParserXmlCreate(); 285 Rp_ParserXmlParse(p, xmltext); 286 configure(RPCONFIG_TREE, p); 287 288 return; 289 } 251 252 /**********************************************************************/ 253 // METHOD: configureFromTree(ClientData p) 254 /// configure the object from a Rappture1.1 based tree 255 /** 256 * Configure the object from a Rappture1.1 based tree 257 */ 290 258 291 259 // FIXME: this is an incomplete definition of how to … … 309 277 310 278 return; 311 }312 313 /**********************************************************************/314 // METHOD: dump(size_t as, void *p)315 /// construct a number object from the provided tree316 /**317 * construct a number object from the provided tree318 */319 320 void321 Plot::dump(size_t as, ClientData c)322 {323 if (as == RPCONFIG_XML) {324 __dumpToXml(c);325 } else if (as == RPCONFIG_TREE) {326 __dumpToTree(c);327 }328 }329 330 /**********************************************************************/331 // METHOD: dumpToXml(ClientData c)332 /// configure the object based on Rappture1.1 xmltext333 /**334 * Configure the object based on the provided xml335 */336 337 void338 Plot::__dumpToXml(ClientData c)339 {340 if (c == NULL) {341 // FIXME: setup error342 return;343 }344 345 ClientDataXml *d = (ClientDataXml *) c;346 Rp_ParserXml *parser = Rp_ParserXmlCreate();347 __dumpToTree(parser);348 _tmpBuf.appendf("%s",Rp_ParserXmlXml(parser));349 d->retStr = _tmpBuf.bytes();350 Rp_ParserXmlDestroy(&parser);351 279 } 352 280 -
trunk/src/objects/RpPlot.h
r1569 r1581 42 42 Curve *getNthCurve(size_t n) const; 43 43 44 void configure(size_t as, ClientData p);45 void dump(size_t as, ClientData p);46 47 44 const int is() const; 48 45 … … 63 60 static int __curveCopyFxn(void **to, void *from); 64 61 65 void __configureFromXml(ClientData c);66 62 void __configureFromTree(ClientData c); 67 void __dumpToXml(ClientData c);68 63 void __dumpToTree(ClientData c); 69 64 };
Note: See TracChangeset
for help on using the changeset viewer.