Changeset 365
- Timestamp:
- Mar 14, 2006, 11:38:29 PM (19 years ago)
- Location:
- trunk
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/gui/apps/driver
r158 r365 26 26 # wish executes everything from here on... 27 27 28 package require Itcl 28 29 package require Rappture 29 30 package require RapptureGUI -
trunk/include/core/RpLibrary.h
r224 r365 21 21 #include <errno.h> 22 22 #include <time.h> 23 #include <iterator> 23 24 24 25 #include <list> … … 33 34 #define _RpLIBRARY_H 34 35 36 35 37 class RpLibrary 36 38 { … … 47 49 std::string path); 48 50 51 bool isNull(); 49 52 50 53 // should return RpObject& but for simplicity right now it doesnt … … 55 58 std::string type = "", 56 59 int* childCount = NULL ); 60 61 RpLibrary& childCount ( std::string path, 62 int* childCount); 57 63 58 64 RpLibrary& copy ( std::string toPath, -
trunk/src/core/RpLibrary.cc
r224 r365 110 110 parent = scew_element_parent(node); 111 111 112 // if (name == NULL) { 113 if (name.empty()) { 114 siblings = scew_element_list(parent, type, &count); 115 if (count > 0) { 116 tmpCount = count; 117 while ((index < tmpCount) && (siblings[index] != node)) { 118 index++; 119 } 120 121 if (index < tmpCount) { 122 123 if (index > 0) { 124 125 retVal << type << --index; 112 if (parent) { 113 114 // if (name == NULL) { 115 if (name.empty()) { 116 siblings = scew_element_list(parent, type, &count); 117 if (count > 0) { 118 tmpCount = count; 119 while ((index < tmpCount) && (siblings[index] != node)) { 120 index++; 126 121 } 127 else { 128 129 retVal << type; 122 123 if (index < tmpCount) { 124 125 if (index > 0) { 126 127 retVal << type << --index; 128 } 129 else { 130 131 retVal << type; 132 } 133 134 /* 135 if (retVal == NULL) { 136 // error with allocating space 137 return NULL; 138 } 139 */ 130 140 } 131 132 /* 133 if (retVal == NULL) { 134 // error with allocating space 135 return NULL; 136 } 137 */ 138 } 139 } 140 141 scew_element_list_free(siblings); 142 143 } 144 else { 145 146 retVal << name; 141 } 142 143 scew_element_list_free(siblings); 144 145 } 146 else { 147 148 retVal << name; 149 } 147 150 } 148 151 … … 173 176 parent = scew_element_parent(node); 174 177 175 if (name.empty()) { 176 siblings = scew_element_list(parent, type, &count); 177 if (count > 0) { 178 tmpCount = count; 179 // figure out what the index value should be 180 while ((index < tmpCount) && (siblings[index] != node)) { 181 index++; 182 } 183 184 if (index < tmpCount) { 185 if (index > 0) { 186 retVal << type << --index; 178 if (parent) { 179 if (name.empty()) { 180 siblings = scew_element_list(parent, type, &count); 181 if (count > 0) { 182 tmpCount = count; 183 // figure out what the index value should be 184 while ((index < tmpCount) && (siblings[index] != node)) { 185 index++; 187 186 } 188 else { 189 retVal << type; 187 188 if (index < tmpCount) { 189 if (index > 0) { 190 retVal << type << --index; 191 } 192 else { 193 retVal << type; 194 } 190 195 } 191 } 196 197 } 198 else { 199 // count == 0 ??? this state should never be reached 200 } 201 scew_element_list_free(siblings); 192 202 193 203 } 194 204 else { 195 // count == 0 ??? this state should never be reached 196 } 197 scew_element_list_free(siblings); 198 199 } 200 else { 201 // node has attribute id 202 retVal << type << "(" << name << ")"; 203 205 // node has attribute id 206 retVal << type << "(" << name << ")"; 207 208 } 204 209 } 205 210 … … 781 786 782 787 if (path.empty()) { 783 // an empty path returns the current RpLibrary784 return this;788 // an empty path returns the parent of the current RpLibrary 789 path = this->nodePath(); 785 790 } 786 791 … … 945 950 946 951 return retLib; 952 } 953 954 /**********************************************************************/ 955 // METHOD: children() 956 /// Returns a std::list<RpLibrary*> of all children under 'path' 957 // 958 // 959 /** 960 */ 961 962 RpLibrary& 963 RpLibrary::childCount ( std::string path, 964 int* childCount) 965 { 966 scew_element* parentNode; 967 int myChildCount = 0; 968 969 if (this->root) { 970 971 if (path.empty()) { 972 // an empty path uses the current RpLibrary as parent 973 parentNode = this->root; 974 } 975 976 if (parentNode) { 977 myChildCount = scew_element_count(parentNode); 978 } 979 980 if (childCount) { 981 *childCount = myChildCount; 982 } 983 984 } 985 986 return *this; 987 } 988 989 /**********************************************************************/ 990 // METHOD: isNull() 991 /// returns whether this RpLibrary is a valid library node 992 // 993 // 994 /** 995 */ 996 997 bool 998 RpLibrary::isNull () 999 { 1000 if (this->root) { 1001 return false; 1002 } 1003 1004 return true; 947 1005 } 948 1006 -
trunk/src/tcl/src/RpLibraryTclInterface.cc
r227 r365 178 178 std::stringstream libName; 179 179 180 libName << " library" << libCount++;180 libName << "::libraryObj" << libCount++; 181 181 182 182 Tcl_CreateCommand(interp, libName.str().c_str(), … … 232 232 if (strncmp(argv[nextarg],"-as",3) == 0) { 233 233 nextarg++; 234 if ( (*argv[nextarg] == 'c') && 235 (strncmp(argv[nextarg],"component",9) == 0) ) { 236 asProc = &RpLibrary::nodeComp; 237 nextarg++; 234 if (nextarg < argc) { 235 if ( (*argv[nextarg] == 'c') && 236 (strncmp(argv[nextarg],"component",9) == 0) ) { 237 asProc = &RpLibrary::nodeComp; 238 nextarg++; 239 } 240 else if ((*argv[nextarg] == 'i') && 241 (strncmp(argv[nextarg],"id",2) == 0 ) ) { 242 asProc = &RpLibrary::nodeId; 243 nextarg++; 244 } 245 else if ((*argv[nextarg] == 't') && 246 (strncmp(argv[nextarg],"type",4) == 0 ) ) { 247 asProc = &RpLibrary::nodeType; 248 nextarg++; 249 } 250 else if ((*argv[nextarg] == 'p') && 251 (strncmp(argv[nextarg],"path",4) == 0 ) ) { 252 asProc = &RpLibrary::nodePath; 253 nextarg++; 254 } 255 else if ((*argv[nextarg] == 'o') && 256 (strncmp(argv[nextarg],"object",6) == 0 ) ) { 257 asProc = NULL; 258 nextarg++; 259 } 260 else { 261 Tcl_AppendResult(interp, "bad flavor \"", argv[nextarg], 262 "\": should be component, id, type, path, object", 263 (char*)NULL); 264 return TCL_ERROR; 265 } 238 266 } 239 else if ((*argv[nextarg] == 'i') && 240 (strncmp(argv[nextarg],"id",2) == 0 ) ) { 241 asProc = &RpLibrary::nodeId; 242 nextarg++; 267 else { 268 Tcl_AppendResult(interp, "bad flavor \"", argv[nextarg], 269 "\": should be component, id, type, path, object", 270 (char*)NULL); 271 return TCL_ERROR; 243 272 } 244 else if ((*argv[nextarg] == 't') && 245 (strncmp(argv[nextarg],"type",4) == 0 ) ) { 246 asProc = &RpLibrary::nodeType; 247 nextarg++; 248 } 249 else if ((*argv[nextarg] == 'p') && 250 (strncmp(argv[nextarg],"path",4) == 0 ) ) { 251 asProc = &RpLibrary::nodePath; 252 nextarg++; 253 } 254 else if ((*argv[nextarg] == 'o') && 255 (strncmp(argv[nextarg],"object",6) == 0 ) ) { 256 asProc = NULL; 273 } 274 else if (strncmp(argv[nextarg],"-type",5) == 0) { 275 nextarg++; 276 if (argc > nextarg) { 277 type = std::string(argv[nextarg]); 257 278 nextarg++; 258 279 } 259 280 else { 260 Tcl_AppendResult(interp, "bad option \"", argv[nextarg], 261 "\": should be -as <fval> where <fval> is ", 262 "\'component\', \'id\', \'type\',", 263 "\'path\', \'object\'", 281 Tcl_AppendResult(interp, "bad flavor \"empty type\"", 282 "\": should be a type of node within the xml", 264 283 (char*)NULL); 265 284 return TCL_ERROR; 266 285 } 267 286 } 268 else if (strncmp(argv[nextarg],"-type",5) == 0) {269 nextarg++;270 type = std::string(argv[nextarg]);271 nextarg++;272 }273 287 else { 274 288 Tcl_AppendResult(interp, "bad option \"", argv[nextarg], 275 "\": should be -as ", (char*)NULL);289 "\": should be -as or -type", (char*)NULL); 276 290 return TCL_ERROR; 277 291 } … … 472 486 if (strncmp(argv[nextarg],"-as",3) == 0) { 473 487 nextarg++; 474 if ( (*argv[nextarg] == 'c') && 475 (strncmp(argv[nextarg],"component",9) == 0) ) { 476 asProc = &RpLibrary::nodeComp; 477 nextarg++; 478 } 479 else if ((*argv[nextarg] == 'i') && 480 (strncmp(argv[nextarg],"id",2) == 0 ) ) { 481 asProc = &RpLibrary::nodeId; 482 nextarg++; 483 } 484 else if ((*argv[nextarg] == 't') && 485 (strncmp(argv[nextarg],"type",4) == 0 ) ) { 486 asProc = &RpLibrary::nodeType; 487 nextarg++; 488 } 489 else if ((*argv[nextarg] == 'p') && 490 (strncmp(argv[nextarg],"path",4) == 0 ) ) { 491 asProc = &RpLibrary::nodePath; 492 nextarg++; 493 } 494 else if ((*argv[nextarg] == 'o') && 495 (strncmp(argv[nextarg],"object",6) == 0 ) ) { 496 asProc = NULL; 497 nextarg++; 488 if (nextarg < argc) { 489 if ( (*argv[nextarg] == 'c') && 490 (strncmp(argv[nextarg],"component",9) == 0) ) { 491 asProc = &RpLibrary::nodeComp; 492 nextarg++; 493 } 494 else if ((*argv[nextarg] == 'i') && 495 (strncmp(argv[nextarg],"id",2) == 0 ) ) { 496 asProc = &RpLibrary::nodeId; 497 nextarg++; 498 } 499 else if ((*argv[nextarg] == 't') && 500 (strncmp(argv[nextarg],"type",4) == 0 ) ) { 501 asProc = &RpLibrary::nodeType; 502 nextarg++; 503 } 504 else if ((*argv[nextarg] == 'p') && 505 (strncmp(argv[nextarg],"path",4) == 0 ) ) { 506 asProc = &RpLibrary::nodePath; 507 nextarg++; 508 } 509 else if ((*argv[nextarg] == 'o') && 510 (strncmp(argv[nextarg],"object",6) == 0 ) ) { 511 asProc = NULL; 512 nextarg++; 513 } 514 else { 515 Tcl_AppendResult(interp, "bad flavor \"", argv[nextarg], 516 "\" for -as: should be component, id, type, path, object", 517 (char*)NULL); 518 return TCL_ERROR; 519 } 498 520 } 499 521 else { 500 Tcl_AppendResult(interp, "bad option \"", argv[nextarg], 501 "\": should be -as <fval> where <fval> is ", 502 "\'component\', \'id\', \'type\',", 503 "\'path\', \'object\'", 504 (char*)NULL); 522 Tcl_AppendResult(interp, "bad flavor \"\" for -as:", 523 " should be component, id, type, path, object", 524 (char*)NULL); 505 525 return TCL_ERROR; 506 526 } … … 515 535 516 536 argsLeft = (argc-nextarg); 517 if (argsLeft == 1) { 537 if (argsLeft > 1) { 538 Tcl_AppendResult(interp, 539 "wrong # args: should be \"element ?-as <fval>? ?<path>?\"", 540 (char*)NULL); 541 return TCL_ERROR; 542 } 543 else if (argsLeft == 1) { 518 544 path = std::string(argv[nextarg++]); 519 545 } 520 546 else { 521 Tcl_AppendResult(interp, "incorrect number of arguments \"", argv[nextarg], 522 "\":", (char*)NULL); 523 return TCL_ERROR; 547 path = ""; 524 548 } 525 549 … … 595 619 Tcl_ResetResult(interp); 596 620 Tcl_AppendResult(interp, 597 "wrong # args: should be \" get ?path?\"",598 "\":",(char*)NULL);621 "wrong # args: should be \"isa <objType>\"", 622 (char*)NULL); 599 623 return TCL_ERROR; 600 624 } … … 636 660 if (strncmp(argv[nextarg],"-as",3) == 0) { 637 661 nextarg++; 638 if ( (*argv[nextarg] == 'c') && 639 (strncmp(argv[nextarg],"component",9) == 0) ) { 640 asProc = &RpLibrary::nodeComp; 641 nextarg++; 642 } 643 else if ((*argv[nextarg] == 'i') && 644 (strncmp(argv[nextarg],"id",2) == 0 ) ) { 645 asProc = &RpLibrary::nodeId; 646 nextarg++; 647 } 648 else if ((*argv[nextarg] == 't') && 649 (strncmp(argv[nextarg],"type",4) == 0 ) ) { 650 asProc = &RpLibrary::nodeType; 651 nextarg++; 652 } 653 else if ((*argv[nextarg] == 'p') && 654 (strncmp(argv[nextarg],"path",4) == 0 ) ) { 655 asProc = &RpLibrary::nodePath; 656 nextarg++; 657 } 658 else if ((*argv[nextarg] == 'o') && 659 (strncmp(argv[nextarg],"object",6) == 0 ) ) { 660 asProc = NULL; 661 nextarg++; 662 if (nextarg < argc) { 663 if ( (*argv[nextarg] == 'c') && 664 (strncmp(argv[nextarg],"component",9) == 0) ) { 665 asProc = &RpLibrary::nodeComp; 666 nextarg++; 667 } 668 else if ((*argv[nextarg] == 'i') && 669 (strncmp(argv[nextarg],"id",2) == 0 ) ) { 670 asProc = &RpLibrary::nodeId; 671 nextarg++; 672 } 673 else if ((*argv[nextarg] == 't') && 674 (strncmp(argv[nextarg],"type",4) == 0 ) ) { 675 asProc = &RpLibrary::nodeType; 676 nextarg++; 677 } 678 else if ((*argv[nextarg] == 'p') && 679 (strncmp(argv[nextarg],"path",4) == 0 ) ) { 680 asProc = &RpLibrary::nodePath; 681 nextarg++; 682 } 683 else if ((*argv[nextarg] == 'o') && 684 (strncmp(argv[nextarg],"object",6) == 0 ) ) { 685 asProc = NULL; 686 nextarg++; 687 } 688 else { 689 Tcl_AppendResult(interp, "bad flavor \"", argv[nextarg], 690 "\": should be component, id, type, path, object", 691 (char*)NULL); 692 return TCL_ERROR; 693 } 662 694 } 663 695 else { 664 Tcl_AppendResult(interp, "bad option \"", argv[nextarg], 665 "\": should be -as <fval> where <fval> is ", 666 "\'component\', \'id\', \'type\',", 667 "\'path\', \'object\'", 696 Tcl_AppendResult(interp, "bad flavor \"", argv[nextarg], 697 "\": should be component, id, type, path, object", 668 698 (char*)NULL); 669 699 return TCL_ERROR; … … 683 713 } 684 714 else { 685 Tcl_AppendResult(interp, "incorrect number of arguments \"", argv[nextarg], 686 "\":", (char*)NULL); 715 Tcl_AppendResult(interp, 716 "wrong # args: should be \"parent ?-as <fval>? ?<path>?\"", 717 (char*)NULL); 687 718 return TCL_ERROR; 688 719 } … … 730 761 if (nextarg < argc && *argv[nextarg] == '-') { 731 762 if (strncmp(argv[nextarg],"-append",7) == 0) { 732 if (strncmp(argv[++nextarg],"yes",3) == 0 ) { 733 append = 1; 734 nextarg++; 763 ++nextarg; 764 if (nextarg < argc) { 765 if (strncmp(argv[nextarg],"yes",3) == 0 ) { 766 append = 1; 767 nextarg++; 768 } 769 else if (strncmp(argv[nextarg],"no",2) == 0 ) { 770 append = 0; 771 nextarg++; 772 } 773 else { 774 Tcl_AppendResult(interp, "expected boolean value but got \"", 775 argv[nextarg], "\"", (char*)NULL); 776 return TCL_ERROR; 777 } 778 } 779 else { 780 Tcl_AppendResult(interp, "expected boolean value but got \"", 781 argv[nextarg], "\"", (char*)NULL); 782 return TCL_ERROR; 735 783 } 736 784 } … … 757 805 } 758 806 else { 759 Tcl_AppendResult(interp, "incorrect number of arguments \"", argv[nextarg], 760 "\":", (char*)NULL); 807 Tcl_AppendResult(interp, "wrong # args: should be ", 808 "\"put ?-append yes? ?-id num? ?<path>? <string>\"", 809 (char*)NULL); 761 810 return TCL_ERROR; 762 811 } … … 855 904 if ( argc != 3 ) { 856 905 Tcl_AppendResult(interp, 857 " usage: ", argv[0], " <xmlobj> <path>",906 "wrong # args: should be \"value <xmlobj> <path>\"", 858 907 (char*)NULL); 859 908 return TCL_ERROR; … … 920 969 std::string retStr = ""; // return value of rappture get fxn 921 970 971 if ( argc != 2 ) { 972 Tcl_AppendResult(interp, "wrong # args: should be \"", 973 argv[0], " xml\"", (char*)NULL); 974 return TCL_ERROR; 975 } 976 922 977 // call the Rappture Library xml Function 923 978 retStr = ((RpLibrary*) cdata)->xml(); … … 944 999 // parse through command line options 945 1000 if (argc != 2) { 946 Tcl_AppendResult(interp, "usage: ", argv[0], " <xmlobj>", (char*)NULL); 1001 Tcl_AppendResult(interp, "wrong # args: should be \"", 1002 argv[0], " <xmlobj>\"", (char*)NULL); 947 1003 return TCL_ERROR; 948 1004 } -
trunk/test/src/RpLibrary_test.cc
r224 r365 326 326 lib = new RpLibrary(std::string(argv[1])); 327 327 328 test_element(lib,""); 328 329 test_element(lib,"input.number(min)"); 329 330 test_element(lib,"input.number(max)");
Note: See TracChangeset
for help on using the changeset viewer.