Changeset 1560 for trunk/src/objects/RpPath.cc
- Timestamp:
- Aug 28, 2009 5:54:24 AM (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/objects/RpPath.cc
r1528 r1560 23 23 #include "RpChainHelper.h" 24 24 #include <cstring> 25 #include <cstdlib> 25 26 26 27 using namespace Rappture; … … 60 61 _ifs = b._ifs; 61 62 63 //FIXME: i think this is broken 62 64 Rp_ChainCopy (_pathList, b._pathList, Rp_ChainCharCpyFxn); 63 65 } … … 105 107 _ifs = '.'; 106 108 _pathList = Rp_ChainCreate(); 109 _currLink = Rp_ChainFirstLink(_pathList); 107 110 return; 108 111 } … … 134 137 int end, 135 138 int idOpenParen, 136 int idCloseParen) 139 int idCloseParen, 140 size_t degree) 137 141 { 138 142 componentStruct *c = new componentStruct(); … … 143 147 c->type = NULL; 144 148 c->id = NULL; 149 c->degree = degree; 145 150 146 151 if (idOpenParen < idCloseParen) { … … 171 176 the type and id of the third component are both blank. 172 177 for the above example paths, the id field of the first 173 components, the in dexcomponent, is NULL.178 components, the input component, is NULL. 174 179 i don't think there is a way to get a NULL type right now. 175 180 */ … … 215 220 int idCloseParen = -1; 216 221 componentStruct *c = NULL; 222 size_t degree = 1; 223 char *newEnd = NULL; 217 224 218 225 Rp_Chain *compList = Rp_ChainCreate(); … … 227 234 } else if (p[end] == ')') { 228 235 idCloseParen = end; 236 } else if ( (idOpenParen <= idCloseParen) && 237 (end != 0) && 238 (p[end] >= '0') && 239 (p[end] <= '9') ) { 240 degree = (size_t) strtod(p+end, &newEnd); 241 if (degree == 0) { 242 // interpret degree of 0 same as degree of 1 243 degree = 1; 244 } 245 // check if we consumed the _ifs 246 if (*(newEnd-1) == _ifs) { 247 newEnd -= 2; 248 } 249 end += newEnd - (p + end); 229 250 } else if (p[end] == _ifs) { 230 c = __createComponent(p,start,end,idOpenParen,idCloseParen );251 c = __createComponent(p,start,end,idOpenParen,idCloseParen,degree); 231 252 if (c != NULL) { 232 253 Rp_ChainAppend(compList,c); … … 240 261 } 241 262 242 c = __createComponent(p,start,end,idOpenParen,idCloseParen );263 c = __createComponent(p,start,end,idOpenParen,idCloseParen,degree); 243 264 if (c != NULL) { 244 265 Rp_ChainAppend(compList,c); … … 335 356 } 336 357 358 bool 359 Path::eof () 360 { 361 return (_currLink == NULL); 362 } 363 364 Path& 365 Path::first () 366 { 367 _currLink = Rp_ChainFirstLink(_pathList); 368 return *this; 369 } 370 371 Path& 372 Path::prev () 373 { 374 if (_currLink) { 375 _currLink = Rp_ChainPrevLink(_currLink); 376 } 377 return *this; 378 } 379 380 Path& 381 Path::next () 382 { 383 if (_currLink) { 384 _currLink = Rp_ChainNextLink(_currLink); 385 } 386 return *this; 387 } 388 389 Path& 390 Path::last () 391 { 392 _currLink = Rp_ChainLastLink(_pathList); 393 return *this; 394 } 395 396 size_t 397 Path::count () 398 { 399 return Rp_ChainGetLength(_pathList); 400 } 401 337 402 const char * 338 403 Path::component(void) 339 404 { 340 405 Rp_ChainLink *l = NULL; 341 size_t len = 0; 342 406 407 /* 343 408 tmpBuf.clear(); 344 409 … … 348 413 } 349 414 350 l = Rp_ChainLastLink(_pathList);415 l = _currLink; 351 416 352 417 if (l == NULL) { … … 363 428 364 429 if (c->type != NULL) { 365 len = strlen(c->type); 366 if (len > 0) { 367 tmpBuf.append(c->type,len); 368 } 430 tmpBuf.appendf("%s",c->type); 431 } 432 433 if (c->degree != 1) { 434 tmpBuf.appendf("%zu",c->degree); 369 435 } 370 436 371 437 if (c->id != NULL) { 372 tmpBuf.append("(",1); 373 len = strlen(c->id); 374 if (len > 0) { 375 tmpBuf.append(c->id,len); 376 } 377 tmpBuf.append(")",1); 378 } 379 438 tmpBuf.appendf("(%s)",c->id); 439 } 440 441 // incase none of the above if statements are hit. 442 tmpBuf.append("\0",1); 443 444 return tmpBuf.bytes(); 445 */ 446 447 448 if (_pathList == NULL) { 449 return NULL; 450 } 451 452 l = _currLink; 453 454 if (l == NULL) { 455 return NULL; 456 } 457 458 componentStruct *c = (componentStruct *) Rp_ChainGetValue(l); 459 460 if (c == NULL) { 461 return NULL; 462 } 463 464 tmpBuf.clear(); 465 466 if (c->type != NULL) { 467 tmpBuf.appendf("%s",c->type); 468 } 469 470 if (c->degree != 1) { 471 tmpBuf.appendf("%zu",c->degree); 472 } 473 474 if (c->id != NULL) { 475 tmpBuf.appendf("(%s)",c->id); 476 } 477 478 // incase none of the above if statements are hit. 380 479 tmpBuf.append("\0",1); 381 480 … … 426 525 Rp_ChainDestroy(addList); 427 526 428 // remove the last component from the current path 429 l = Rp_ChainLastLink(_pathList); 527 // swap the current component from the current path 528 // with the component from the provided path. 529 l = _currLink; 430 530 431 531 if (l != NULL) { 432 532 componentStruct *last = (componentStruct *) Rp_ChainGetValue(l); 433 533 delete last; 434 Rp_ChainDeleteLink(_pathList,l); 435 } 436 437 // append the new component onto the current path 438 Rp_ChainAppend(_pathList,aLcomp); 534 Rp_ChainSetValue(l,aLcomp); 535 } else { 536 // add a new component as a link 537 // point _currLink to the new component 538 _currLink = Rp_ChainAppend(_pathList,aLcomp); 539 } 439 540 440 541 __updateBuffer(); … … 448 549 Rp_ChainLink *l = NULL; 449 550 551 /* 450 552 tmpBuf.clear(); 451 553 … … 455 557 } 456 558 457 l = Rp_ChainLastLink(_pathList);559 l = _currLink; 458 560 459 561 if (l == NULL) { … … 476 578 477 579 return tmpBuf.bytes(); 580 */ 581 582 if (_pathList == NULL) { 583 return NULL; 584 } 585 586 l = _currLink; 587 588 if (l == NULL) { 589 return NULL; 590 } 591 592 componentStruct *c = (componentStruct *) Rp_ChainGetValue(l); 593 594 if (c == NULL) { 595 return NULL; 596 } 597 598 return c->id; 478 599 } 479 600 … … 490 611 componentStruct *last = NULL; 491 612 492 // update the last component from the current path493 l = Rp_ChainLastLink(_pathList);613 // update the current component from the current path 614 l = _currLink; 494 615 495 616 if (l != NULL) { … … 499 620 // append the new component onto the current path 500 621 last = new componentStruct; 501 Rp_ChainAppend(_pathList,last);622 _currLink = Rp_ChainAppend(_pathList,last); 502 623 tmp = new char[1]; 503 624 *tmp = '\0'; … … 520 641 Rp_ChainLink *l = NULL; 521 642 643 /* 522 644 tmpBuf.clear(); 523 645 … … 527 649 } 528 650 529 l = Rp_ChainLastLink(_pathList);651 l = _currLink; 530 652 531 653 if (l == NULL) { … … 548 670 549 671 return tmpBuf.bytes(); 672 */ 673 674 if (_pathList == NULL) { 675 return NULL; 676 } 677 678 l = _currLink; 679 680 if (l == NULL) { 681 return NULL; 682 } 683 684 componentStruct *c = (componentStruct *) Rp_ChainGetValue(l); 685 686 if (c == NULL) { 687 return NULL; 688 } 689 690 return c->type; 550 691 } 551 692 … … 563 704 564 705 // update the last component from the current path 565 l = Rp_ChainLastLink(_pathList);706 l = _currLink; 566 707 567 708 if (l != NULL) { … … 571 712 // append the new component onto the current path 572 713 last = new componentStruct; 573 Rp_ChainAppend(_pathList,last);714 _currLink = Rp_ChainAppend(_pathList,last); 574 715 last->id = NULL; 575 716 } … … 593 734 tmpBuf.clear(); 594 735 595 last = Rp_ChainLastLink(_pathList);736 last = _currLink; 596 737 l = Rp_ChainFirstLink(_pathList); 597 738 while (l != last) { … … 685 826 } 686 827 828 size_t 829 Path::degree() 830 { 831 Rp_ChainLink *l = NULL; 832 833 l = _currLink; 834 835 if (l == NULL) { 836 return 0; 837 } 838 839 componentStruct *c = (componentStruct *) Rp_ChainGetValue(l); 840 841 if (c == NULL) { 842 return 0; 843 } 844 845 return c->degree; 846 } 847 848 void 849 Path::degree(size_t d) 850 { 851 if (d == 0) { 852 d = 1; 853 } 854 855 Rp_ChainLink *l = NULL; 856 componentStruct *last = NULL; 857 858 // update the current component from the current path 859 l = _currLink; 860 861 if (l != NULL) { 862 last = (componentStruct *) Rp_ChainGetValue(l); 863 } else { 864 // append the new component onto the current path 865 last = new componentStruct; 866 _currLink = Rp_ChainAppend(_pathList,last); 867 } 868 869 // adjust the degree field 870 last->degree = d; 871 872 __updateBuffer(); 873 874 return; 875 } 876 687 877 const char * 688 878 Path::path(void) … … 696 886 if (p != NULL) { 697 887 _pathList = __parse(p); 888 _currLink = Rp_ChainLastLink(_pathList); 698 889 __updateBuffer(); 699 890 }
Note: See TracChangeset
for help on using the changeset viewer.