- Timestamp:
- Feb 20, 2006, 2:37:44 PM (19 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/core/RpLibrary.cc
r192 r200 62 62 63 63 // listLen should be the highest index + 1 64 for ( pos = path.find(".", 0);64 for ( pos = path.find(".",NO_CREATE_PATH); 65 65 (pos != std::string::npos) || (index >= listLen); 66 66 pos = path.find(".",pos) ) … … 405 405 406 406 if (node == NULL) { 407 if (create == 0) {407 if (create == NO_CREATE_PATH) { 408 408 // break out instead of returning because we still need to 409 409 // free the list variable … … 413 413 } 414 414 else { 415 // create == 1415 // create == CREATE_PATH 416 416 // we should create the rest of the path 417 417 … … 469 469 /// Search the path of a xml tree and return a RpLibrary node. 470 470 /** 471 * It is the user's responsibility to delete the object when 472 * they are finished using it?, else i need to make this static 471 473 */ 472 474 … … 476 478 RpLibrary* retLib = NULL; 477 479 scew_element* retNode = NULL; 480 481 if (!this->root) { 482 // library doesn't exist, do nothing; 483 return NULL; 484 } 478 485 479 486 if (path.empty()) { … … 483 490 484 491 // get the node located at path 485 retNode = _find(path, 0);492 retNode = _find(path,NO_CREATE_PATH); 486 493 487 494 // if the node exists, create a rappture library object for it. … … 497 504 /// Search the path of a xml tree and return its parent. 498 505 /** 506 * It is the user's responsibility to delete the object when 507 * they are finished using it?, else i need to make this static 499 508 */ 500 509 … … 506 515 std::string::size_type pos = 0; 507 516 scew_element* retNode = NULL; 517 518 if (!this->root) { 519 // library doesn't exist, do nothing; 520 return NULL; 521 } 508 522 509 523 if (path.empty()) { … … 520 534 521 535 // search for hte parent's node 522 retNode = _find(parentPath, 0);536 retNode = _find(parentPath,NO_CREATE_PATH); 523 537 524 538 if (retNode) { … … 544 558 { 545 559 RpLibrary* value = NULL; 560 561 if (!this->root) { 562 // library doesn't exist, do nothing; 563 return *this; 564 } 546 565 547 566 if (fromObj == NULL) { … … 581 600 scew_element* childNode = NULL; 582 601 std::string childName = ""; 602 603 if (!this->root) { 604 // library doesn't exist, do nothing; 605 return NULL; 606 } 583 607 584 608 … … 601 625 // we need to search for a new parentNode 602 626 else { 603 parentNode = _find(path, 0);627 parentNode = _find(path,NO_CREATE_PATH); 604 628 if (parentNode == NULL) { 605 629 // node not found … … 685 709 RpLibrary::getString (std::string path) 686 710 { 687 scew_element* retNode = _find(path,0);711 scew_element* retNode = NULL; 688 712 XML_Char const* retCStr = NULL; 713 714 if (!this->root) { 715 // library doesn't exist, do nothing; 716 return std::string(""); 717 } 718 719 retNode = _find(path,NO_CREATE_PATH); 689 720 690 721 if (retNode == NULL) { … … 714 745 double retValDbl = 0; 715 746 747 if (!this->root) { 748 // library doesn't exist, do nothing; 749 return retValDbl; 750 } 751 716 752 retValStr = this->getString(path); 717 753 // think about changing this to strtod() … … 737 773 const char* contents = NULL; 738 774 739 // if (! path.empty()) { 740 retNode = _find(path,1); 741 742 if (retNode) { 743 744 if (append) { 745 if ( (contents = scew_element_contents(retNode)) ) { 746 tmpVal = std::string(contents); 747 } 748 value = tmpVal + value; 749 } 750 751 scew_element_set_contents(retNode,value.c_str()); 752 } 753 // } 775 if (!this->root) { 776 // library doesn't exist, do nothing; 777 return *this; 778 } 779 780 retNode = _find(path,CREATE_PATH); 781 782 if (retNode) { 783 784 if (append) { 785 if ( (contents = scew_element_contents(retNode)) ) { 786 tmpVal = std::string(contents); 787 } 788 value = tmpVal + value; 789 } 790 791 scew_element_set_contents(retNode,value.c_str()); 792 } 754 793 755 794 return *this; … … 766 805 { 767 806 std::stringstream valStr; 807 808 if (!this->root) { 809 // library doesn't exist, do nothing; 810 return *this; 811 } 768 812 769 813 valStr << value; … … 786 830 int retVal = 1; 787 831 788 retNode = _find(path,1); 789 790 if (value) { 832 if (!this->root) { 833 // library doesn't exist, do nothing; 834 return *this; 835 } 836 837 // you cannot put a null RpLibrary into the tree 838 if (!value) { 791 839 // need to send back an error saying that user specified a null value 792 840 return *this; 793 841 } 842 843 retNode = _find(path,CREATE_PATH); 794 844 795 845 if (retNode) { … … 805 855 806 856 807 /* 808 RpLibrary& 857 /**********************************************************************/ 858 // METHOD: remove() 859 /// Remove the provided path from this RpLibrary 860 /** 861 */ 862 863 RpLibrary* 809 864 RpLibrary::remove ( std::string path ) 810 865 { 811 scew_element* ele = _find(path,0); 812 RpLibrary* retLib; 866 scew_element* ele = NULL; 867 int setNULL = 0; 868 RpLibrary* retLib = NULL; 869 870 if (!this->root) { 871 // library doesn't exist, do nothing; 872 return NULL; 873 } 874 875 if ( !path.empty() ) { 876 ele = _find(path,NO_CREATE_PATH); 877 } 878 else { 879 // telling this function to remove "" is essentially destroying 880 // the object. most functions will fail after a call like this. 881 ele = this->root; 882 setNULL++; 883 } 884 813 885 if (ele) { 814 retLib = new RpLibrary(ele) 815 } 816 817 return *retLib 818 } 819 */ 886 scew_element_free(ele); 887 if (setNULL) { 888 // this is the case where user specified an empty path. 889 // the object is useless, and will be deleted. 890 this->root = NULL; 891 delete this; 892 retLib = NULL; 893 } 894 else { 895 retLib = this; 896 } 897 } 898 899 return retLib; 900 } 820 901 821 902 /**********************************************************************/ … … 830 911 std::stringstream outString; 831 912 913 if (!this->root) { 914 // library doesn't exist, do nothing; 915 return std::string(""); 916 } 917 832 918 outString << "<?xml version=\"1.0\"?>\n"; 833 919 print_element(this->root, 0, outString); … … 845 931 RpLibrary::nodeType () 846 932 { 933 if (!this->root) { 934 // library doesn't exist, do nothing; 935 return std::string(""); 936 } 937 847 938 return std::string(scew_element_name(root)); 848 939 } … … 857 948 RpLibrary::nodeId () 858 949 { 950 if (!this->root) { 951 // library doesn't exist, do nothing; 952 return std::string(""); 953 } 954 859 955 return _node2name(root); 860 956 } … … 869 965 RpLibrary::nodeComp () 870 966 { 967 if (!this->root) { 968 // library doesn't exist, do nothing; 969 return std::string(""); 970 } 971 871 972 return _node2comp(root); 872 973 } … … 881 982 RpLibrary::nodePath () 882 983 { 984 if (!this->root) { 985 // library doesn't exist, do nothing; 986 return std::string(""); 987 } 988 883 989 return _node2path(root); 884 990 } … … 905 1011 time_t t = 0; 906 1012 907 outputFile << "run" << (int)time(&t) << ".xml"; 908 file.open(outputFile.str().c_str(),std::ios::out); 909 910 if ( file.is_open() ) { 911 xmlText = xml(); 912 if (!xmlText.empty()) { 913 file << xmlText; 914 } 915 } 916 std::cout << "=RAPPTURE-RUN=>" << outputFile.str() << std::endl; 1013 if (this->root) { 1014 outputFile << "run" << (int)time(&t) << ".xml"; 1015 file.open(outputFile.str().c_str(),std::ios::out); 1016 1017 if ( file.is_open() ) { 1018 xmlText = xml(); 1019 if (!xmlText.empty()) { 1020 file << xmlText; 1021 } 1022 } 1023 std::cout << "=RAPPTURE-RUN=>" << outputFile.str() << std::endl; 1024 } 917 1025 } 918 1026
Note: See TracChangeset
for help on using the changeset viewer.