Changeset 205 for trunk


Ignore:
Timestamp:
Feb 22, 2006 9:33:10 AM (18 years ago)
Author:
dkearney
Message:

added isvalid function, but it doesnt work yet.
tested copying from one library to another
changed package name to RapptureLibrary?
adjusted related make and configure files

Location:
trunk
Files:
10 edited

Legend:

Unmodified
Added
Removed
  • trunk/include/core/RpLibrary.h

    r200 r205  
    7878        std::string nodeComp();
    7979        std::string nodePath();
     80
     81        int isvalid();
    8082
    8183        void result();
  • trunk/src/core/RpLibrary.cc

    r200 r205  
    990990}
    991991
     992/**********************************************************************/
     993// METHOD: isvalid()
     994/// Returns true if the library is a valid Rappture Object with a document root
     995/**
     996 */
     997
     998int
     999RpLibrary::isvalid ()
     1000{
     1001    if (!this->root) {
     1002        // library doesn't exist, return false;
     1003        return 0;
     1004    }
     1005
     1006    return 1;
     1007}
     1008
    9921009/*
    9931010 * ----------------------------------------------------------------------
  • trunk/src/tcl/library/Makefile.in

    r204 r205  
    1111#========================================================================
    1212
    13 lib_BINARIES=$(RapptureExt_LIB_FILE)
     13lib_BINARIES=$(RapptureLibrary_LIB_FILE)
    1414BINARIES=$(lib_BINARIES)
    1515
     
    1919#========================================================================
    2020
    21 RapptureExt_SOURCES = \
     21RapptureLibrary_SOURCES = \
    2222  src/RpLibraryTclInterface.cc
    23 SOURCES = $(RapptureExt_SOURCES)
     23SOURCES = $(RapptureLibrary_SOURCES)
    2424
    2525#========================================================================
     
    3030#========================================================================
    3131
    32 RapptureExt_OBJECTS = \
     32RapptureLibrary_OBJECTS = \
    3333  RpLibraryTclInterface.$(OBJEXT)
    34 OBJECTS = $(RapptureExt_OBJECTS)
    35 
    36 #========================================================================
    37 # The substitution of "RapptureExt_LIB_FILE" into the variable name below
     34OBJECTS = $(RapptureLibrary_OBJECTS)
     35
     36#========================================================================
     37# The substitution of "RapptureLibrary_LIB_FILE" into the variable name below
    3838# let's us refer to the objects for the library without knowing the name
    3939# of the library in advance.  It also lets us use the "$@" variable in
     
    4242#========================================================================
    4343
    44 RapptureExt_LIB_FILE = @RapptureExt_LIB_FILE@
    45 $(RapptureExt_LIB_FILE)_OBJECTS = $(RapptureExt_OBJECTS)
     44RapptureLibrary_LIB_FILE = @RapptureLibrary_LIB_FILE@
     45$(RapptureLibrary_LIB_FILE)_OBJECTS = $(RapptureLibrary_OBJECTS)
    4646
    4747#========================================================================
     
    228228# above.
    229229#
    230 # $(RapptureExt_LIB_FILE) should be listed as part of the BINARIES variable
     230# $(RapptureLibrary_LIB_FILE) should be listed as part of the BINARIES variable
    231231# at the top of the Makefile.  That will ensure that this target is built
    232232# when you run "make binaries".
     
    236236#========================================================================
    237237
    238 $(RapptureExt_LIB_FILE): $(RapptureExt_OBJECTS)
    239         -rm -f $(RapptureExt_LIB_FILE)
     238$(RapptureLibrary_LIB_FILE): $(RapptureLibrary_OBJECTS)
     239        -rm -f $(RapptureLibrary_LIB_FILE)
    240240        @MAKE_LIB@  -lrappture
    241         $(RANLIB) $(RapptureExt_LIB_FILE) -lrappture
     241        $(RANLIB) $(RapptureLibrary_LIB_FILE) -lrappture
    242242
    243243#========================================================================
     
    320320          else :; fi; \
    321321        done
    322         $(mkinstalldirs) $(pkglibdir)/scripts
    323         @for i in $(srcdir)/scripts/*.tcl; do \
    324             echo "Installing $$i" ; \
    325             $(INSTALL_DATA) $$i $(DESTDIR)$(pkglibdir)/scripts ; \
    326         done;
    327         $(TCLSH_PROG) $(srcdir)/cf/mkindex.tcl $(DESTDIR)$(pkglibdir)/scripts
    328         $(mkinstalldirs) $(pkglibdir)/scripts/images
    329         @for i in $(srcdir)/scripts/images/*.gif; do \
    330             echo "Installing $$i" ; \
    331             $(INSTALL_DATA) $$i $(DESTDIR)$(pkglibdir)/scripts/images ; \
    332         done;
    333322        $(INSTALL_DATA) pkgIndex.tcl $(DESTDIR)$(pkglibdir)/pkgIndex.tcl
    334323        $(INSTALL_DATA) init.tcl $(DESTDIR)$(pkglibdir)/init.tcl
  • trunk/src/tcl/library/README

    r204 r205  
    11to compile:
    22./configure CC=g++ --prefix=/opt/rappture --with-tcl=/opt/rappture/lib --with-tclinclude=/opt/rappture/include
    3 make
     3make all install
    44
    55within tclsh
    6     package require BLT
    7     load libRapptureExt1.0.so
    8 
     6    package require RapptureLibrary
  • trunk/src/tcl/library/configure

    r204 r205  
    273273
    274274ac_unique_file="src/RpLibraryTclInterface.cc"
    275 ac_subst_vars='SHELL PATH_SEPARATOR PACKAGE_NAME PACKAGE_TARNAME PACKAGE_VERSION PACKAGE_STRING PACKAGE_BUGREPORT exec_prefix prefix program_transform_name bindir sbindir libexecdir datadir sysconfdir sharedstatedir localstatedir libdir includedir oldincludedir infodir mandir build_alias host_alias target_alias DEFS ECHO_C ECHO_N ECHO_T LIBS CXX CXXFLAGS LDFLAGS CPPFLAGS ac_ct_CXX EXEEXT OBJEXT INSTALL_PROGRAM INSTALL_SCRIPT INSTALL_DATA SET_MAKE RANLIB ac_ct_RANLIB build build_cpu build_vendor build_os host host_cpu host_vendor host_os CYGPATH TCL_INCLUDES TCL_BIN_DIR TCL_SRC_DIR TCL_LIB_FILE TCL_LIBS TCL_DEFS TCL_SHLIB_LD_LIBS TCL_EXTRA_CFLAGS TCL_LD_FLAGS TCL_STUB_LIB_FILE TCL_LIB_SPEC TCL_BUILD_LIB_SPEC TCL_STUB_LIB_SPEC TCL_BUILD_STUB_LIB_SPEC CLEANFILES CC CFLAGS ac_ct_CC CFLAGS_DEBUG CFLAGS_OPTIMIZE STLIB_LD SHLIB_LD SHLIB_CFLAGS SHLIB_LDFLAGS TCL_DBGX CFLAGS_DEFAULT LDFLAGS_DEFAULT MAKE_LIB MAKE_SHARED_LIB MAKE_STATIC_LIB RapptureExt_LIB_FILE SHLIB_LD_LIBS TCLSH_PROG PACKAGE VERSION PATCHLEVEL EXACT_VERSION NODOT_VERSION LIBOBJS LTLIBOBJS'
     275ac_subst_vars='SHELL PATH_SEPARATOR PACKAGE_NAME PACKAGE_TARNAME PACKAGE_VERSION PACKAGE_STRING PACKAGE_BUGREPORT exec_prefix prefix program_transform_name bindir sbindir libexecdir datadir sysconfdir sharedstatedir localstatedir libdir includedir oldincludedir infodir mandir build_alias host_alias target_alias DEFS ECHO_C ECHO_N ECHO_T LIBS CXX CXXFLAGS LDFLAGS CPPFLAGS ac_ct_CXX EXEEXT OBJEXT INSTALL_PROGRAM INSTALL_SCRIPT INSTALL_DATA SET_MAKE RANLIB ac_ct_RANLIB build build_cpu build_vendor build_os host host_cpu host_vendor host_os CYGPATH TCL_INCLUDES TCL_BIN_DIR TCL_SRC_DIR TCL_LIB_FILE TCL_LIBS TCL_DEFS TCL_SHLIB_LD_LIBS TCL_EXTRA_CFLAGS TCL_LD_FLAGS TCL_STUB_LIB_FILE TCL_LIB_SPEC TCL_BUILD_LIB_SPEC TCL_STUB_LIB_SPEC TCL_BUILD_STUB_LIB_SPEC CLEANFILES CC CFLAGS ac_ct_CC CFLAGS_DEBUG CFLAGS_OPTIMIZE STLIB_LD SHLIB_LD SHLIB_CFLAGS SHLIB_LDFLAGS TCL_DBGX CFLAGS_DEFAULT LDFLAGS_DEFAULT MAKE_LIB MAKE_SHARED_LIB MAKE_STATIC_LIB RapptureLibrary_LIB_FILE SHLIB_LD_LIBS TCLSH_PROG PACKAGE VERSION PATCHLEVEL EXACT_VERSION NODOT_VERSION LIBOBJS LTLIBOBJS'
    276276ac_subst_files=''
    277277
     
    13041304#--------------------------------------------------------------------
    13051305
    1306 PACKAGE=RapptureExt
     1306PACKAGE=RapptureLibrary
    13071307
    13081308MAJOR_VERSION=1
     
    42814281s,@MAKE_SHARED_LIB@,$MAKE_SHARED_LIB,;t t
    42824282s,@MAKE_STATIC_LIB@,$MAKE_STATIC_LIB,;t t
    4283 s,@RapptureExt_LIB_FILE@,$RapptureExt_LIB_FILE,;t t
     4283s,@RapptureLibrary_LIB_FILE@,$RapptureLibrary_LIB_FILE,;t t
    42844284s,@SHLIB_LD_LIBS@,$SHLIB_LD_LIBS,;t t
    42854285s,@TCLSH_PROG@,$TCLSH_PROG,;t t
  • trunk/src/tcl/library/configure.in

    r204 r205  
    2424#--------------------------------------------------------------------
    2525
    26 PACKAGE=RapptureExt
     26PACKAGE=RapptureLibrary
    2727
    2828MAJOR_VERSION=1
     
    316316#--------------------------------------------------------------------
    317317
    318 AC_SUBST(RapptureExt_LIB_FILE)
     318AC_SUBST(RapptureLibrary_LIB_FILE)
    319319AC_SUBST(SHLIB_LD_LIBS)
    320320
  • trunk/src/tcl/library/init.tcl.in

    r204 r205  
    11# ----------------------------------------------------------------------
    2 #  RapptureGUI - scripts and C extensions required for Rappture GUI
     2#  RapptureLibrary - Tcl extensions to C++ core Rappture Library
    33# ----------------------------------------------------------------------
    44#  This file initializes the package when it is loaded by "package
     
    66#  for other scripts.
    77# ======================================================================
    8 #  AUTHOR:  Michael McLennan, Purdue University
    9 #  Copyright (c) 2004-2006  Purdue Research Foundation
     8#  AUTHOR:  Derrick Kearney, Purdue University
     9#  Copyright (c) 2005-2006  Purdue Research Foundation
    1010#
    1111#  See the file "license.terms" for information on usage and
    1212#  redistribution of this file, and for a DISCLAIMER OF ALL WARRANTIES.
    1313# ======================================================================
    14 proc RapptureGUI_init {} {
     14proc RapptureLibrary_init {} {
    1515    global auto_path
    1616    global rappture_library
     
    1919
    2020    set dir [file dirname [info script]]
    21    
    22     set rappture_library [file join $dir scripts]
    23     lappend auto_path $rappture_library
     21
     22    # set rappture_library [file join $dir scripts]
     23    # lappend auto_path $rappture_library
    2424
    2525    set suffix [info sharedlibextension]
    26     set library [file join $dir .. libRapptureGUI@VERSION@${suffix}]
    27     load $library RapptureGUI
     26    set library [file join $dir .. libRapptureLibrary@VERSION@${suffix}]
     27    load $library
    2828
    2929    namespace eval Rappture {
    30         variable version @EXACT_VERSION@
    31         variable patchlevel @PATCHLEVEL@
     30        variable version @EXACT_VERSION@
     31        variable patchlevel @PATCHLEVEL@
    3232    }
    3333
    34     package provide RapptureGUI @VERSION@
    35     rename RapptureGUI_init ""   
     34    package provide RapptureLibrary @VERSION@
     35    rename RapptureLibrary_init ""
    3636}
    37 RapptureGUI_init
     37RapptureLibrary_init
  • trunk/src/tcl/library/pkgIndex.tcl.in

    r204 r205  
    1 # this file identifies RapptureGUI as a Tcl package
    2 package ifneeded RapptureGUI @VERSION@ [list source [file join $dir init.tcl]]
     1# this file identifies RapptureLibrary as a Tcl package
     2package ifneeded RapptureLibrary @VERSION@ [list source [file join $dir init.tcl]]
  • trunk/src/tcl/library/src/RpLibraryTclInterface.cc

    r204 r205  
    1616 */
    1717#include <tcl.h>
     18#include <stdexcept>
     19// #include <typeinfo.h>
    1820#include "core/RpLibrary.h"
    1921
     
    2426#include "bltInt.h"
    2527
    26 EXTERN int Rapptureext_Init _ANSI_ARGS_((Tcl_Interp * interp));
     28EXTERN int Rappturelibrary_Init _ANSI_ARGS_((Tcl_Interp * interp));
    2729
    2830static int RpLibraryCmd   _ANSI_ARGS_((   ClientData cdata, Tcl_Interp *interp,
     
    3234                                        int argc, const char* argv[]    ));
    3335
     36static int RpTclLibChild  _ANSI_ARGS_(( ClientData cdata, Tcl_Interp *interp,
     37                                        int argc, const char *argv[]    ));
     38static int RpTclLibCopy   _ANSI_ARGS_(( ClientData cdata, Tcl_Interp *interp,
     39                                        int argc, const char *argv[]    ));
    3440static int RpTclLibElem   _ANSI_ARGS_(( ClientData cdata, Tcl_Interp *interp,
    3541                                        int argc, const char *argv[]    ));
     42static int RpTclLibGet    _ANSI_ARGS_(( ClientData cdata, Tcl_Interp *interp,
     43                                        int argc, const char *argv[]    ));
    3644static int RpTclLibParent _ANSI_ARGS_(( ClientData cdata, Tcl_Interp *interp,
    3745                                        int argc, const char *argv[]    ));
    38 static int RpTclLibChild  _ANSI_ARGS_(( ClientData cdata, Tcl_Interp *interp,
    39                                         int argc, const char *argv[]    ));
    40 static int RpTclLibGet    _ANSI_ARGS_(( ClientData cdata, Tcl_Interp *interp,
    41                                         int argc, const char *argv[]    ));
    4246static int RpTclLibPut    _ANSI_ARGS_(( ClientData cdata, Tcl_Interp *interp,
    4347                                        int argc, const char *argv[]    ));
    44 static int RpTclLibCopy   _ANSI_ARGS_(( ClientData cdata, Tcl_Interp *interp,
    45                                         int argc, const char *argv[]    ));
    4648static int RpTclLibRemove _ANSI_ARGS_(( ClientData cdata, Tcl_Interp *interp,
     49                                        int argc, const char *argv[]    ));
     50static int RpTclLibResult _ANSI_ARGS_(( ClientData cdata, Tcl_Interp *interp,
    4751                                        int argc, const char *argv[]    ));
    4852static int RpTclLibXml    _ANSI_ARGS_(( ClientData cdata, Tcl_Interp *interp,
     
    5256static std::string rpLib2command _ANSI_ARGS_(( Tcl_Interp *interp,
    5357                                               RpLibrary* newRpLibObj   ));
    54 static int print_library_howto _ANSI_ARGS_((const char** argv));
    55 static int print_libcmds_howto _ANSI_ARGS_((const char** argv));
    5658
    5759// member function, function pointer mainly used in 'element' implementation
     
    6870    {"put", 2, (Blt_Op)RpTclLibPut, 2, 8,
    6971        "?-append yes? ?-id num? ?<path>? <string>",},
    70     {"remove", 1, (Blt_Op)RpTclLibRemove, 2, 3, "?<path>?",},
     72    {"remove", 3, (Blt_Op)RpTclLibRemove, 2, 3, "?<path>?",},
     73    {"result", 3, (Blt_Op)RpTclLibResult, 2, 2, "",},
    7174    {"xml", 1, (Blt_Op)RpTclLibXml, 2, 2, "",},
    7275};
     
    8891
    8992int
    90 Rapptureext_Init(Tcl_Interp *interp)
    91 {
    92 
    93     Tcl_CreateCommand(interp, "::Rappture::library_test",
     93Rappturelibrary_Init(Tcl_Interp *interp)
     94{
     95
     96    Tcl_CreateCommand(interp, "::Rappture::library",
    9497        RpLibraryCmd, (ClientData)NULL, (Tcl_CmdDeleteProc*)NULL);
    9598
    9699    return TCL_OK;
    97100}
     101
     102/*
     103 *
     104 * USAGE: library <file>
     105 * USAGE: library standard
     106 * USAGE: library isvalid <object>
     107 *
     108 */
    98109
    99110int
     
    104115{
    105116    RpLibrary *rpptr = NULL;
    106     std::string libName = "";;
     117    RpLibrary *testObj = NULL;
     118    std::string libName = "";
     119    int noerr = 0;
     120    Tcl_CmdInfo* infoPtr = NULL;  // pointer to the command info
     121
     122    if ( (argc > 2) && (strncmp(argv[1],"isvalid",7) == 0) ) {
     123        if (argc != 3) {
     124            std::cout << "wrong # args: should be \"" << argv[0]
     125                << " isvalid object\"" << std::endl;
     126            return TCL_ERROR;
     127        }
     128
     129        libName = std::string(argv[2]);
     130        std::cout << "argv[2] = " << argv[2] << std::endl;
     131        std::cout << "interp = " << interp << std::endl;
     132        noerr = Tcl_GetCommandInfo(interp, libName.c_str(), infoPtr);
     133        std::cout << "interp = " << interp << std::endl;
     134        if (noerr && infoPtr) {
     135            testObj = (RpLibrary*) (infoPtr->clientData);
     136            // if ( (testObj) && (typeid(RpLibrary) == typeid(testObj)) ) {
     137            if (testObj) {
     138                // return testObj->isvalid();
     139                // need a way to try this and catch any errors
     140                try {
     141                    testObj->isvalid();
     142                    return 1; // return true
     143                }
     144                catch (const std::exception& e) {
     145                    return 0; // return false
     146                }
     147            }
     148            else {
     149                return 0; // return false
     150            }
     151        }
     152        else {
     153            return 0; // return false
     154        }
     155    }
    107156
    108157    if (argc != 2) {
    109         print_library_howto(argv);
    110         return TCL_ERROR;
    111     }
    112 
     158        std::cout << "usage: " << argv[0] << " <xmlfile>" << std::endl;
     159        return TCL_ERROR;
     160    }
     161
     162    // create a new command
    113163    rpptr = new RpLibrary(argv[1]);
    114164
     
    144194
    145195    if (argc < 2) {
    146         print_libcmds_howto(argv);
     196        std::cout <<"usage: "<< argv[0] <<" <command> <arg-list>"<< std::endl;
    147197        return TCL_ERROR;
    148198    }
     
    158208}
    159209
    160 int print_library_howto (const char **argv)
    161 {
    162     std::cout << "usage: " << argv[0] << " <xmlfile>" << std::endl;
    163     return TCL_OK;
    164 }
    165 
    166 int print_libcmds_howto (const char **argv)
    167 {
    168     std::cout << "usage: " << argv[0] << " <command> <arg-list>" << std::endl;
    169 
    170     return TCL_OK;
    171 }
    172 
    173 int
    174 RpTclLibElem    (   ClientData cdata,
     210int
     211RpTclLibChild   (   ClientData cdata,
    175212                    Tcl_Interp *interp,
    176213                    int argc,
     
    178215{
    179216    std::string path   = "";    // path of where to place data inside xml tree
     217    std::string type   = "";    // type of nodes to be returned
    180218    std::string retStr = "";    // path of where to place data inside xml tree
    181219    int nextarg        = 2;     // start parsing using the '2'th argument
    182     int opt_argc       = 1;     // max number of optional parameters
     220    int opt_argc       = 2;     // max number of optional parameters
    183221    int argsLeft       = 0;     // temp variable for calculation
    184222
     
    225263                }
    226264            }
     265            else if (strncmp(argv[nextarg],"-type",5) == 0) {
     266                nextarg++;
     267                type = std::string(argv[nextarg]);
     268                nextarg++;
     269            }
    227270            else {
    228271                Tcl_AppendResult(interp, "bad option \"", argv[nextarg],
     
    243286    }
    244287
    245     // call the rappture library element function
    246     node = ((RpLibrary*) cdata)->element(path);
    247     if (node) {
    248 
    249         // clear any previous result in the interpreter
    250         Tcl_ResetResult(interp);
    251 
    252         if (asProc) {
    253             // evaluate the "-as" flag on the returned node
    254             retStr = (node->*asProc)();
    255         }
    256         else {
    257             // create a new command for the new rappture object
    258             retStr = rpLib2command(interp, node);
    259         }
    260         // store the new result string in the interpreter
    261         Tcl_AppendResult(interp, retStr.c_str(), (char*)NULL);
    262     }
    263 
    264 
    265     return TCL_OK;
    266 }
    267 
    268 int
    269 RpTclLibParent  (   ClientData cdata,
    270                     Tcl_Interp *interp,
    271                     int argc,
    272                     const char *argv[]  )
    273 {
    274 
     288    // call the rappture library children function
     289    while ( (node = ((RpLibrary*) cdata)->children(path,node,type)) ) {
     290        if (node) {
     291
     292            // clear any previous result in the interpreter
     293            // Tcl_ResetResult(interp);
     294
     295            if (asProc) {
     296                // evaluate the "-as" flag on the returned node
     297                retStr = (node->*asProc)();
     298            }
     299            else {
     300                // create a new command for the new rappture object
     301                retStr = rpLib2command(interp, node);
     302            }
     303
     304            // store the new result string in the interpreter
     305            Tcl_AppendElement(interp,retStr.c_str());
     306        }
     307    }
     308
     309    return TCL_OK;
     310}
     311
     312int
     313RpTclLibCopy    (   ClientData cdata,
     314                    Tcl_Interp *interp,
     315                    int argc,
     316                    const char *argv[]  )
     317{
     318    std::string fromPath = "";    // path of where to copy data from
     319    std::string toPath   = "";    // path of where to copy data to
     320    std::string from     = "";    // string that should == "from"
     321    std::string fromObjStr = "";  // string that represents the
     322                                  // string name of the object
     323    RpLibrary* fromObj   = NULL;
     324    int nextarg          = 2;     // start parsing using the '2'th argument
     325    int argsLeft         = 0;     // temp variable for calculation
     326    int noerr              = 0;     // err flag for Tcl_GetCommandInfo
     327    Tcl_CmdInfo* infoPtr = NULL;  // pointer to the command info
     328
     329    toPath = std::string(argv[nextarg++]);
     330    from = std::string(argv[nextarg++]);
     331
     332    argsLeft = (argc-nextarg);
     333    if (argsLeft == 2) {
     334        fromObjStr = std::string(argv[nextarg++]);
     335        noerr = Tcl_GetCommandInfo(interp, fromObjStr.c_str(), infoPtr);
     336        if (noerr && infoPtr) {
     337            fromObj = (RpLibrary*) (infoPtr->clientData);
     338        }
     339        fromObj = NULL; // gotta figure out how to get the actual lib here
     340        fromPath = std::string(argv[nextarg++]);
     341    }
     342    else if (argsLeft == 1) {
     343        fromPath = std::string(argv[nextarg++]);
     344    }
     345    else {
     346        Tcl_AppendResult(interp,
     347            "wrong # args: should be \"copy path from ?xmlobj? path\"",
     348            (char*)NULL);
     349        return TCL_ERROR;
     350    }
     351
     352    if (from != "from") {
     353        Tcl_AppendResult(interp,
     354            "bad syntax: should be \"copy path from ?xmlobj? path\"",
     355            (char*)NULL);
     356        return TCL_ERROR;
     357    }
     358
     359    // call the rappture library copy function
     360    ((RpLibrary*) cdata)->copy(toPath, fromPath, fromObj);
     361
     362    // clear any previous result in the interpreter
     363    // store the new result in the interpreter
     364    Tcl_ResetResult(interp);
     365    Tcl_AppendResult(interp, "", (char*)NULL);
     366
     367    return TCL_OK;
     368}
     369
     370int
     371RpTclLibElem    (   ClientData cdata,
     372                    Tcl_Interp *interp,
     373                    int argc,
     374                    const char *argv[]  )
     375{
    275376    std::string path   = "";    // path of where to place data inside xml tree
    276377    std::string retStr = "";    // path of where to place data inside xml tree
     
    339440    }
    340441
    341     // call the rappture library parent function
    342     node = ((RpLibrary*) cdata)->parent(path);
     442    // call the rappture library element function
     443    node = ((RpLibrary*) cdata)->element(path);
    343444    if (node) {
    344445
     
    356457        // store the new result string in the interpreter
    357458        Tcl_AppendResult(interp, retStr.c_str(), (char*)NULL);
    358 
    359     }
    360 
    361 
    362     return TCL_OK;
    363 }
    364 
    365 int
    366 RpTclLibChild   (   ClientData cdata,
    367                     Tcl_Interp *interp,
    368                     int argc,
    369                     const char *argv[]  )
    370 {
     459    }
     460
     461
     462    return TCL_OK;
     463}
     464
     465int
     466RpTclLibGet     (   ClientData cdata,
     467                    Tcl_Interp *interp,
     468                    int argc,
     469                    const char *argv[]  )
     470{
     471
     472    std::string retStr = ""; // return value of rappture get fxn
     473    std::string path = "";
     474
     475    if (argc > 2) {
     476        path = std::string(argv[2]);
     477    }
     478
     479    // call the Rappture Library Get Function
     480    retStr = ((RpLibrary*) cdata)->getString(path);
     481
     482    // clear any previous result in the interpreter
     483    // store the new result in the interpreter
     484    Tcl_ResetResult(interp);
     485    Tcl_AppendResult(interp, retStr.c_str(), (char*)NULL);
     486
     487    return TCL_OK;
     488}
     489
     490int
     491RpTclLibParent  (   ClientData cdata,
     492                    Tcl_Interp *interp,
     493                    int argc,
     494                    const char *argv[]  )
     495{
     496
    371497    std::string path   = "";    // path of where to place data inside xml tree
    372     std::string type   = "";    // type of nodes to be returned
    373498    std::string retStr = "";    // path of where to place data inside xml tree
    374499    int nextarg        = 2;     // start parsing using the '2'th argument
    375     int opt_argc       = 2;     // max number of optional parameters
     500    int opt_argc       = 1;     // max number of optional parameters
    376501    int argsLeft       = 0;     // temp variable for calculation
    377502
     
    418543                }
    419544            }
    420             else if (strncmp(argv[nextarg],"-type",5) == 0) {
    421                 nextarg++;
    422                 type = std::string(argv[nextarg]);
    423                 nextarg++;
    424             }
    425545            else {
    426546                Tcl_AppendResult(interp, "bad option \"", argv[nextarg],
     
    441561    }
    442562
    443     // call the rappture library children function
    444     while ( (node = ((RpLibrary*) cdata)->children(path,node,type)) ) {
    445         if (node) {
    446 
    447             // clear any previous result in the interpreter
    448             // Tcl_ResetResult(interp);
    449 
    450             if (asProc) {
    451                 // evaluate the "-as" flag on the returned node
    452                 retStr = (node->*asProc)();
    453             }
    454             else {
    455                 // create a new command for the new rappture object
    456                 retStr = rpLib2command(interp, node);
    457             }
    458 
    459             // store the new result string in the interpreter
    460             Tcl_AppendElement(interp,retStr.c_str());
    461         }
    462     }
    463 
    464     return TCL_OK;
    465 }
    466 
    467 int
    468 RpTclLibGet     (   ClientData cdata,
    469                     Tcl_Interp *interp,
    470                     int argc,
    471                     const char *argv[]  )
    472 {
    473 
    474     std::string retStr = ""; // return value of rappture get fxn
    475     std::string path = "";
    476 
    477     if (argc > 2) {
    478         path = std::string(argv[2]);
    479     }
    480 
    481     // call the Rappture Library Get Function
    482     retStr = ((RpLibrary*) cdata)->getString(path);
    483 
    484     // clear any previous result in the interpreter
    485     // store the new result in the interpreter
    486     Tcl_ResetResult(interp);
    487     Tcl_AppendResult(interp, retStr.c_str(), (char*)NULL);
     563    // call the rappture library parent function
     564    node = ((RpLibrary*) cdata)->parent(path);
     565    if (node) {
     566
     567        // clear any previous result in the interpreter
     568        Tcl_ResetResult(interp);
     569
     570        if (asProc) {
     571            // evaluate the "-as" flag on the returned node
     572            retStr = (node->*asProc)();
     573        }
     574        else {
     575            // create a new command for the new rappture object
     576            retStr = rpLib2command(interp, node);
     577        }
     578        // store the new result string in the interpreter
     579        Tcl_AppendResult(interp, retStr.c_str(), (char*)NULL);
     580
     581    }
     582
    488583
    489584    return TCL_OK;
     
    552647
    553648int
    554 RpTclLibCopy    (   ClientData cdata,
    555                     Tcl_Interp *interp,
    556                     int argc,
    557                     const char *argv[]  )
    558 {
    559     std::string fromPath = "";    // path of where to copy data from
    560     std::string toPath   = "";    // path of where to copy data to
    561     std::string from     = "";    // string that should == "from"
    562     std::string fromObjStr = "";  // string that represents the
    563                                   // string name of the object
    564     RpLibrary* fromObj   = NULL;
    565     int nextarg          = 2;     // start parsing using the '2'th argument
    566     int argsLeft         = 0;     // temp variable for calculation
    567 
    568     toPath = std::string(argv[nextarg++]);
    569     from = std::string(argv[nextarg++]);
    570 
    571     argsLeft = (argc-nextarg);
    572     if (argsLeft == 2) {
    573         fromObjStr = std::string(argv[nextarg++]);
    574         fromObj = NULL; // gotta figure out how to get the actual lib here
    575         fromPath = std::string(argv[nextarg++]);
    576     }
    577     else if (argsLeft == 1) {
    578         fromPath = std::string(argv[nextarg++]);
     649RpTclLibRemove  (   ClientData cdata,
     650                    Tcl_Interp *interp,
     651                    int argc,
     652                    const char *argv[]  )
     653{
     654
     655    std::string path = std::string("");    // path of where to copy data from
     656    int nextarg = 2;
     657
     658
     659    if (argc == 2) {
     660        path = std::string("");
     661    }
     662    else if (argc == 3) {
     663        path = std::string(argv[nextarg]);
    579664    }
    580665    else {
    581666        Tcl_AppendResult(interp,
    582             "wrong # args: should be \"copy path from ?xmlobj? path\"",
     667            "wrong # args: should be \"remove ?path?\"",
    583668            (char*)NULL);
    584669        return TCL_ERROR;
    585670    }
    586671
    587     if (from != "from") {
    588         Tcl_AppendResult(interp,
    589             "bad syntax: should be \"copy path from ?xmlobj? path\"",
    590             (char*)NULL);
    591         return TCL_ERROR;
    592     }
    593 
    594 
    595 
    596     // call the rappture library put function
    597     ((RpLibrary*) cdata)->copy(toPath, fromPath,fromObj);
     672    // call the rappture library remove function
     673    ((RpLibrary*) cdata)->remove(path);
    598674
    599675    // clear any previous result in the interpreter
     
    606682
    607683int
    608 RpTclLibRemove  (   ClientData cdata,
    609                     Tcl_Interp *interp,
    610                     int argc,
    611                     const char *argv[]  )
    612 {
    613 
    614     std::string path = std::string("");    // path of where to copy data from
    615     int nextarg = 2;
    616 
    617 
    618     if (argc == 2) {
    619         path = std::string("");
    620     }
    621     else if (argc == 3) {
    622         path = std::string(argv[nextarg]);
     684RpTclLibResult  (   ClientData cdata,
     685                    Tcl_Interp *interp,
     686                    int argc,
     687                    const char *argv[]  )
     688{
     689    if (argc == 1) {
     690        // call the rappture library result function
     691        ((RpLibrary*) cdata)->result();
    623692    }
    624693    else {
    625694        Tcl_AppendResult(interp,
    626             "wrong # args: should be \"remove ?path?\"",
     695            "wrong # args: should be \"result \"",
    627696            (char*)NULL);
    628697        return TCL_ERROR;
    629698    }
    630699
    631     // call the rappture library put function
    632     ((RpLibrary*) cdata)->remove(path);
    633700
    634701    // clear any previous result in the interpreter
     
    649716    std::string retStr = ""; // return value of rappture get fxn
    650717
    651     // call the Rappture Library Get Function
     718    // call the Rappture Library xml Function
    652719    retStr = ((RpLibrary*) cdata)->xml();
    653720
  • trunk/src/tcl/library/tcl_test.tcl

    r204 r205  
    1 package require BLT
    2 load libRapptureExt1.0.so
     1package require RapptureLibrary
    32
    4 Rappture::library_test "rplib_test.xml"
     3Rappture::library "rplib_test.xml"
    54
    65puts [library0 get input.(max).current]
     
    7069puts "Printing XML"
    7170puts [library0 xml]
     71
     72puts "opening new library"
     73set libObj1 [Rappture::library "rplib_test.xml"]
     74set libObj2 [Rappture::library "rplib_test.xml"]
     75puts "libObj1 = "
     76puts $libObj1
     77
     78puts "COPYING BETWEEN LIBS"
     79$libObj1 copy "input.test" from libObj2 "input.(max)"
     80puts [$libObj1 xml]
     81
     82#puts [$libObj xml]
     83puts "isvalid test1: "
     84# puts [Rappture::library isvalid $libObj1]
     85puts "isvalid test2: "
     86# puts [Rappture::library isvalid library0]
Note: See TracChangeset for help on using the changeset viewer.