Changeset 1581 for trunk/src/objects/RpObject.cc
- Timestamp:
- Oct 17, 2009 9:01:23 PM (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
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
Note: See TracChangeset
for help on using the changeset viewer.