Changeset 365


Ignore:
Timestamp:
Mar 14, 2006 11:38:29 PM (18 years ago)
Author:
dkearney
Message:

fixes for tcl bindings.

Location:
trunk
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/gui/apps/driver

    r158 r365  
    2626# wish executes everything from here on...
    2727
     28package require Itcl
    2829package require Rappture
    2930package require RapptureGUI
  • trunk/include/core/RpLibrary.h

    r224 r365  
    2121#include <errno.h>
    2222#include <time.h>
     23#include <iterator>
    2324
    2425#include <list>
     
    3334#define _RpLIBRARY_H
    3435
     36
    3537class RpLibrary
    3638{
     
    4749                                            std::string path);
    4850
     51        bool isNull();
    4952
    5053        // should return RpObject& but for simplicity right now it doesnt
     
    5558                                std::string type = "",
    5659                                int* childCount = NULL  );
     60
     61        RpLibrary& childCount ( std::string path,
     62                                int* childCount);
    5763
    5864        RpLibrary& copy       ( std::string toPath,
  • trunk/src/core/RpLibrary.cc

    r224 r365  
    110110    parent = scew_element_parent(node);
    111111
    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++;
    126121                }
    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                    */
    130140                }
    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        }
    147150    }
    148151
     
    173176    parent = scew_element_parent(node);
    174177
    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++;
    187186                }
    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                    }
    190195                }
    191             }
     196
     197            }
     198            else {
     199                // count == 0 ??? this state should never be reached
     200            }
     201            scew_element_list_free(siblings);
    192202
    193203        }
    194204        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        }
    204209    }
    205210
     
    781786
    782787    if (path.empty()) {
    783         // an empty path returns the current RpLibrary
    784         return this;
     788        // an empty path returns the parent of the current RpLibrary
     789        path = this->nodePath();
    785790    }
    786791
     
    945950
    946951    return retLib;
     952}
     953
     954/**********************************************************************/
     955// METHOD: children()
     956/// Returns a std::list<RpLibrary*> of all children under 'path'
     957//
     958//
     959/**
     960 */
     961
     962RpLibrary&
     963RpLibrary::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
     997bool
     998RpLibrary::isNull ()
     999{
     1000    if (this->root) {
     1001        return false;
     1002    }
     1003
     1004    return true;
    9471005}
    9481006
  • trunk/src/tcl/src/RpLibraryTclInterface.cc

    r227 r365  
    178178    std::stringstream libName;
    179179
    180     libName << "library" << libCount++;
     180    libName << "::libraryObj" << libCount++;
    181181
    182182    Tcl_CreateCommand(interp, libName.str().c_str(),
     
    232232            if (strncmp(argv[nextarg],"-as",3) == 0) {
    233233                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                    }
    238266                }
    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;
    243272                }
    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]);
    257278                    nextarg++;
    258279                }
    259280                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",
    264283                        (char*)NULL);
    265284                    return TCL_ERROR;
    266285                }
    267286            }
    268             else if (strncmp(argv[nextarg],"-type",5) == 0) {
    269                 nextarg++;
    270                 type = std::string(argv[nextarg]);
    271                 nextarg++;
    272             }
    273287            else {
    274288                Tcl_AppendResult(interp, "bad option \"", argv[nextarg],
    275                     "\": should be -as", (char*)NULL);
     289                    "\": should be -as or -type", (char*)NULL);
    276290                return TCL_ERROR;
    277291            }
     
    472486            if (strncmp(argv[nextarg],"-as",3) == 0) {
    473487                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                    }
    498520                }
    499521                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);
    505525                    return TCL_ERROR;
    506526                }
     
    515535
    516536    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) {
    518544        path = std::string(argv[nextarg++]);
    519545    }
    520546    else {
    521         Tcl_AppendResult(interp, "incorrect number of arguments \"", argv[nextarg],
    522             "\":", (char*)NULL);
    523         return TCL_ERROR;
     547        path = "";
    524548    }
    525549
     
    595619        Tcl_ResetResult(interp);
    596620        Tcl_AppendResult(interp,
    597             "wrong # args: should be \"get ?path?\"",
    598             "\":", (char*)NULL);
     621            "wrong # args: should be \"isa <objType>\"",
     622            (char*)NULL);
    599623        return TCL_ERROR;
    600624    }
     
    636660            if (strncmp(argv[nextarg],"-as",3) == 0) {
    637661                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                    }
    662694                }
    663695                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",
    668698                        (char*)NULL);
    669699                    return TCL_ERROR;
     
    683713    }
    684714    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);
    687718        return TCL_ERROR;
    688719    }
     
    730761        if (nextarg < argc && *argv[nextarg] == '-') {
    731762            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;
    735783                }
    736784            }
     
    757805    }
    758806    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);
    761810        return TCL_ERROR;
    762811    }
     
    855904    if ( argc != 3 ) {
    856905        Tcl_AppendResult(interp,
    857             "usage: ", argv[0], " <xmlobj> <path>",
     906            "wrong # args: should be \"value <xmlobj> <path>\"",
    858907            (char*)NULL);
    859908        return TCL_ERROR;
     
    920969    std::string retStr = ""; // return value of rappture get fxn
    921970
     971    if ( argc != 2 ) {
     972        Tcl_AppendResult(interp, "wrong # args: should be \"",
     973                argv[0], " xml\"", (char*)NULL);
     974        return TCL_ERROR;
     975    }
     976
    922977    // call the Rappture Library xml Function
    923978    retStr = ((RpLibrary*) cdata)->xml();
     
    944999    // parse through command line options
    9451000    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);
    9471003        return TCL_ERROR;
    9481004    }
  • trunk/test/src/RpLibrary_test.cc

    r224 r365  
    326326    lib = new RpLibrary(std::string(argv[1]));
    327327
     328    test_element(lib,"");
    328329    test_element(lib,"input.number(min)");
    329330    test_element(lib,"input.number(max)");
Note: See TracChangeset for help on using the changeset viewer.