Changeset 125


Ignore:
Timestamp:
Nov 4, 2005, 3:19:11 PM (19 years ago)
Author:
dkearney
Message:

1) removed "as" string from c++'s element() function because
the function does not have the capacity to return anything
other than RpLibrary? Instances
2) changed get() functions in library module to return strings.
this change was propagated to matlab, octave, c, fortran, c++
bindings.
3) fixed rpFreeLibrary inside of c interface, now function accepts
a pointer to a pointer to RpLibrary? (lib) and sets *lib equal to
null
4) added doxygen target to makefile. (make docs), to get graphics
you need the program named dot (debian: apt-get install graphviz)
otherwise you will get errors for the portion of the proceedure
where it is trying to create the graphics.

Location:
trunk
Files:
1 added
15 edited

Legend:

Unmodified
Added
Removed
  • trunk/examples/c-example/plotc.c

    r115 r125  
    106106
    107107    // free the rappture library
    108     rpFreeLibrary(lib);
     108    rpFreeLibrary(&lib);
    109109
    110110    // exit program
  • trunk/examples/c-example/tool.xml

    r90 r125  
    44        <title>SIN(x) Graph</title>
    55        <about>Press Simulate to view results.</about>
    6         <command> @tool/plotc @driver</command>
     6        <command> @tool/plot @driver</command>
    77    </tool>
    88    <input>
  • trunk/include/cee/RpLibraryCInterface.h

    r115 r125  
    2222//
    2323RpLibrary*  rpLibrary             (const char* path);
    24 void rpFreeLibrary                (RpLibrary* lib);
     24void rpFreeLibrary                (RpLibrary** lib);
    2525
    2626// RpLibrary member functions
     
    5353 */
    5454
    55 RpLibrary* rpGet                 (RpLibrary* lib, const char* path);
     55const char* rpGet                 (RpLibrary* lib, const char* path);
    5656const char* rpGetString           (RpLibrary* lib, const char* path);
    5757double      rpGetDouble           (RpLibrary* lib, const char* path);
  • trunk/include/core/RpLibrary.h

    r115 r125  
    3434        // users member fxns
    3535
    36         RpLibrary* element (std::string path = "", std::string as = "object");
     36        RpLibrary* element (std::string path = "");
    3737
    3838        // should return RpObject& but for simplicity right now it doesnt
    3939        // RpObject will either be an Array, RpString, RpNumber ...
    4040
    41         RpLibrary*  children ( std::string path = "",
     41        RpLibrary*  children  ( std::string path = "",
    4242                                RpLibrary* rpChildNode = NULL,
    4343                                std::string type = "",
    4444                                int* childCount = NULL  );
    4545
    46         RpLibrary*  get (std::string path = "");
    47         std::string getString (std::string path = "");
    48         double      getDouble (std::string path = "");
     46        std::string get       ( std::string path = "");
     47        std::string getString ( std::string path = "");
     48        double      getDouble ( std::string path = "");
    4949
    5050        RpLibrary& put (    std::string path,
     
    6767
    6868        void result();
    69         const char* nodeTypeC();
    70         const char* nodeIdC();
    71         const char* nodeCompC();
    7269
    7370        // no arg constructor
     
    139136
    140137        // copy constructor
    141         // for some reason making this a const gives me problems when calling xml()
     138        // for some reason making this a const gives me problems
     139        // when calling xml()
    142140        // need help looking into this
    143141        // RpLibrary ( const RpLibrary& other )
     
    199197        }// end copy constructor
    200198
    201         // for some reason making this a const gives me problems when calling xml()
     199        // copy assignment operator
     200        // for some reason making this a const gives me problems
     201        // when calling xml()
    202202        // need help looking into this
    203203        // RpLibrary& operator= (const RpLibrary& other) {
     
    224224
    225225                // Loads the XML from other
    226                 // the length cannot be 0 because xml() should not be returning
    227                 // empty strings
     226                // the length cannot be 0 because xml()
     227                // should not be returning empty strings
    228228                buffer = other.xml();
    229229                buffLen = buffer.length();
  • trunk/include/fortran/RpLibraryFInterface.h

    r119 r125  
    5353
    5454void rp_lib_get (           int* handle,
     55                            char* path,
     56                            char* retText,
     57                            int path_len,
     58                            int retText_len );
     59
     60void rp_lib_get_str (       int* handle,
    5561                            char* path,
    5662                            char* retText,
  • trunk/include/fortran/RpLibraryFStubs.h

    r119 r125  
    6464                            int retText_len );
    6565
     66void rp_lib_get_str_ (      int* handle,
     67                            char* path,
     68                            char* retText,
     69                            int path_len,
     70                            int retText_len );
     71
    6672double rp_lib_get_double_ ( int* handle,
    6773                            char* path,
     
    173179                            int retText_len );
    174180
     181void rp_lib_get_str__ (     int* handle,
     182                            char* path,
     183                            char* retText,
     184                            int path_len,
     185                            int retText_len );
     186
    175187double rp_lib_get_double__ (int* handle,
    176188                            char* path,
     
    283295                            int retText_len );
    284296
     297void RP_LIB_GET_STR (       int* handle,
     298                            char* path,
     299                            char* retText,
     300                            int path_len,
     301                            int retText_len );
     302
    285303double RP_LIB_GET_DOUBLE (  int* handle,
    286304                            char* path,
  • trunk/src/Makefile

    r122 r125  
    292292        $(OCT) $(OCTAVE_SRC)/rpXml.cc              $(OCTAVE_COMP_ARGS)
    293293
    294 
     294docs:
     295        if test ! -d docs; then \
     296                mkdir docs; \
     297        fi
     298        if test ! -d docs/doxygen; then \
     299                mkdir docs/doxygen; \
     300        fi
     301        doxygen
    295302
    296303#### CLEAN UP ############################################################
  • trunk/src/cee/RpLibraryCInterface.cc

    r115 r125  
    2626
    2727    void
    28     rpFreeLibrary (RpLibrary* lib)
    29     {
    30         delete lib;
    31         lib = NULL;
     28    rpFreeLibrary (RpLibrary** lib)
     29    {
     30        if (lib && (*lib)) {
     31            delete (*lib);
     32            (*lib) = NULL;
     33        }
    3234    }
    3335
     
    99101    }
    100102
    101     RpLibrary*
     103    const char*
    102104    rpGet (RpLibrary* lib, const char* path)
    103105    {
    104         return lib->get(path);
     106        static std::string retStr = "";
     107        retStr = lib->getString(path);
     108        return retStr.c_str();
    105109    }
    106110
     
    202206    rpResult (RpLibrary* lib)
    203207    {
     208        // signal the processing is complete
    204209        lib->result();
    205210    }
  • trunk/src/core/RpLibrary.cc

    r121 r125  
    448448
    449449RpLibrary*
    450 RpLibrary::element (std::string path, std::string as)
     450RpLibrary::element (std::string path)
    451451{
    452452    RpLibrary* retLib;
     
    566566}
    567567
    568 
    569568/**********************************************************************/
    570569// METHOD: get()
    571 /// Return the RpLibrary object held at location 'path'
    572 /**
    573  */
    574 
    575 RpLibrary*
     570/// Return the string value of the object held at location 'path'
     571/**
     572 */
     573
     574std::string
    576575RpLibrary::get (std::string path)
    577576{
    578     RpLibrary* retVal;
    579 
    580     scew_element* retNode = _find(path,0);
    581 
    582     if (retNode == NULL) {
    583         // need to raise error
    584         return NULL;
    585     }
    586 
    587     retVal = new RpLibrary(retNode);
    588 
    589     //who delete's this memory?
    590     return retVal;
    591 }
    592 
    593 /**********************************************************************/
    594 // METHOD: getString()
    595 /// Return the string value of the object held at location 'path'
    596 /**
    597  */
    598 
    599 std::string
    600 RpLibrary::getString (std::string path)
    601 {
    602     // std::string retVal;
    603 
    604     /*
    605     if (path.empty()) {
    606         return "";
    607     }
    608     */
    609 
    610577    scew_element* retNode = _find(path,0);
    611578
     
    615582    }
    616583
    617     // retVal = std::string(scew_element_contents(retNode));
    618     // return retVal;
     584    return std::string(scew_element_contents(retNode));
     585}
     586
     587/**********************************************************************/
     588// METHOD: getString()
     589/// Return the string value of the object held at location 'path'
     590/**
     591 */
     592
     593std::string
     594RpLibrary::getString (std::string path)
     595{
     596    scew_element* retNode = _find(path,0);
     597
     598    if (retNode == NULL) {
     599        // need to raise error
     600        return "";
     601    }
    619602
    620603    return std::string(scew_element_contents(retNode));
  • trunk/src/fortran/RpLibraryFInterface.cc

    r122 r125  
    462462
    463463        if (lib) {
     464            xmlText = lib->get(inPath);
     465            if (!xmlText.empty()) {
     466                fortranify(xmlText.c_str(),retText,retText_len);
     467            }
     468
     469        }
     470    }
     471}
     472
     473/**********************************************************************/
     474// FUNCTION: rp_lib_get_str()
     475/// Get data located at 'path' and return it as a string value.
     476/**
     477 */
     478void rp_lib_get_str( int* handle, /* integer handle of library */
     479                   char* path,      /* null terminated path */
     480                   char* retText,   /* return text buffer for fortran*/
     481                   int path_len,
     482                   int retText_len /* length of return text buffer */
     483                 )
     484{
     485    std::string xmlText = "";
     486
     487    RpLibrary* lib = NULL;
     488
     489    std::string inPath = "";
     490
     491    inPath = null_terminate_str(path,path_len);
     492
     493    if ((handle) && (*handle != 0)) {
     494        lib = getObject_Lib(*handle);
     495
     496        if (lib) {
    464497            xmlText = lib->getString(inPath);
    465498            if (!xmlText.empty()) {
     
    470503    }
    471504}
     505
    472506
    473507/**********************************************************************/
  • trunk/src/fortran/RpLibraryFStubs.c

    r119 r125  
    238238}
    239239
     240void
     241rp_lib_get_str_ (       int* handle,
     242                        char* path,
     243                        char* retText,
     244                        int path_len,
     245                        int retText_len ) {
     246
     247    return rp_lib_get_str(handle,path,retText,path_len,retText_len);
     248}
     249
     250void
     251rp_lib_get_str__ (      int* handle,
     252                        char* path,
     253                        char* retText,
     254                        int path_len,
     255                        int retText_len ) {
     256
     257    return rp_lib_get_str(handle,path,retText,path_len,retText_len);
     258}
     259
     260void
     261RP_LIB_GET_STR  (       int* handle,
     262                        char* path,
     263                        char* retText,
     264                        int path_len,
     265                        int retText_len ) {
     266
     267    return rp_lib_get_str(handle,path,retText,path_len,retText_len);
     268}
     269
    240270double
    241271rp_lib_get_double_ (    int* handle,
  • trunk/src/matlab/rpGet.cc

    r115 r125  
    33 *  INTERFACE: Matlab Rappture Library Source
    44 *
    5  *    nodeHandle = rpGet(libHandle,path)
     5 *    retStr = rpGet(libHandle,path)
    66 *
    77 * ======================================================================
     
    1919                 int nrhs, const mxArray *prhs[])
    2020{
    21     int         libIndex = 0;
     21    int         libIndex    = 0;
    2222    int         retLibIndex = 0;
    23     RpLibrary*  lib = NULL;
    24     RpLibrary*  retLib = NULL;
    25     char*       path = NULL;
     23    RpLibrary*  lib         = NULL;
     24    char*       path        = NULL;
     25    const char* retString  = NULL;
    2626
    2727    /* Check for proper number of arguments. */
     
    3939
    4040        if (lib) {
    41             retLib = rpGet(lib,path);
    42             retLibIndex = storeObject_Lib(retLib);
     41            retString = rpGet(lib,path);
    4342        }
    4443    }
    4544
    46     /* Set double scalar node handle to MATLAB mexFunction output*/
    47     plhs[0] = mxCreateDoubleScalar(retLibIndex);
     45    /* Set C-style string output_buf to MATLAB mexFunction output*/
     46    plhs[0] = mxCreateString(retString);
    4847
    4948    return;
  • trunk/src/octave/rpGet.cc

    r122 r125  
    6262
    6363                if (lib) {
    64                     retStr = lib->getString(path);
     64                    retStr = lib->get(path);
    6565                    err = 0;
    6666                }
  • trunk/test/src/RpLibraryF_test.f

    r115 r125  
    3232      END SUBROUTINE  test_element
    3333
     34      SUBROUTINE  test_get(lib,path)
     35        integer lib
     36        character*100 path, retText
     37
     38        print *,"TESTING GET       : path = ",path
     39
     40        call rp_lib_get(lib, path, retText)
     41
     42        print *,"retText = ",retText
     43      END SUBROUTINE  test_get
     44
    3445      SUBROUTINE  test_get_str(lib,path)
    3546        integer lib
    3647        character*100 path, retText
    3748
    38         print *,"TESTING GET: path = ",path
     49        print *,"TESTING GET STRING: path = ",path
    3950
    40         call rp_lib_get(lib, path, retText)
     51        call rp_lib_get_str(lib, path, retText)
    4152
    4253        print *,"retText = ",retText
     
    4657        integer lib
    4758        double precision rslt, rp_lib_get_double
    48         character*100 path, retText
     59        character*100 path
    4960
    50         print *,"TESTING GET: path = ",path
     61        print *,"TESTING GET DOUBLE: path = ",path
    5162
    5263        rslt = rp_lib_get_double(lib, path)
     
    5869        IMPLICIT NONE
    5970
    60         integer rp_lib, rp_units_convert_dbl, rp_units_add_presets
    61         integer rp_lib_element_obj
     71        integer rp_lib
    6272
    63         integer driver, ok
    64         double precision T, Ef, kT, Emin, Emax, dE, f, E
    65         CHARACTER*100 inFile, strVal, path
    66         character*40 xy
     73        integer driver
     74        CHARACTER*100 inFile, path
    6775
    6876        call getarg(1,inFile)
     
    7078        ! print *,"dict key = ",driver
    7179
    72         ok = rp_units_add_presets("all")
    73 
    7480        ! TESTING ELEMENT
    75         !call test_element(driver, "input.number(min)")
    7681        path = "input.number(min)"
    7782        call test_element(driver, path)
    78         !call rp_lib_get(driver, path, strVal)
    79         !print *,"strVal = ",strVal
     83
     84        ! TESTING GET
     85        path = "input.number(min).current"
     86        call test_get(driver, path)
    8087
    8188        ! TESTING GET STRING
  • trunk/test/src/RpLibrary_test.cc

    r115 r125  
    1616int test_element (RpLibrary* lib, std::string path );
    1717int test_get (RpLibrary* lib, std::string path );
     18int test_getString (RpLibrary* lib, std::string path );
     19int test_getDouble (RpLibrary* lib, std::string path );
    1820
    1921int test_element (RpLibrary* lib, std::string path )
     
    3234        std::cout << "searchEle   id = :" << searchEle->nodeId()   << ":" << std::endl;
    3335        std::cout << "searchEle type = :" << searchEle->nodeType() << ":" << std::endl;
     36        retVal = 0;
     37    }
     38
     39    return retVal;
     40}
     41
     42int test_get (RpLibrary* lib, std::string path )
     43{
     44    int retVal = 1;
     45    std::string searchVal = lib->get(path);
     46
     47    std::cout << "TESTING GET       : path = " << path << std::endl;
     48
     49    if (searchVal.empty()) {
     50        std::cout << "searchVal is EMPTY STRING" << std::endl;
     51        retVal = 1;
     52    }
     53    else {
     54        std::cout << "searchVal = :" << searchVal << ":" << std::endl;
    3455        retVal = 0;
    3556    }
     
    135156    RpLibrary lib2;
    136157
    137     if (argc < 3)
     158    if (argc < 2)
    138159    {
    139         printf("usage: RpLibrary_test infile.xml outfile.xml\n");
     160        printf("usage: RpLibrary_test infile.xml\n");
    140161        return EXIT_FAILURE;
    141162    }
     
    152173    test_getString(lib, "output.curve.about.label");
    153174
     175    lib->put("input.number(test_one).default", "3000");
     176    test_get(lib, "input.number(test_one).default");
    154177    lib->put("input.number(test).default", "1000");
    155178    test_getString(lib, "input.number(test).default");
Note: See TracChangeset for help on using the changeset viewer.