source: trunk/src/matlab/rpLibGetString.cc @ 154

Last change on this file since 154 was 154, checked in by dkearney, 16 years ago

modified matlab bindings and tests.
includes all popular functions available in RpLibrary? and RpUnits
compile and run, but not all tests work as they should
some of these functions will be removed soon because the id field is
no longer a valid argument. path ids should be incorporated in paths from now on.

File size: 2.0 KB
Line 
1/*
2 * ----------------------------------------------------------------------
3 *  INTERFACE: Matlab Rappture Library Source
4 *
5 *    [retStr,err] = rpLibGetString(libHandle,path)
6 *
7 * ======================================================================
8 *  AUTHOR:  Derrick Kearney, Purdue University
9 *  Copyright (c) 2004-2005  Purdue Research Foundation
10 *
11 *  See the file "license.terms" for information on usage and
12 *  redistribution of this file, and for a DISCLAIMER OF ALL WARRANTIES.
13 * ======================================================================
14 */
15
16#include "RpMatlabInterface.h"
17
18/**********************************************************************/
19// METHOD: [retStr,err] = rpLibGetString(libHandle,path)
20/// Query the value of a node.
21/**
22 * Clients use this to query the value of a node.  If the path
23 * is not specified, it returns the value associated with the
24 * root node.  Otherwise, it returns the value for the element
25 * specified by the path. Values are returned as strings.
26 *
27 * Error code, err=0 on success, anything else is failure.
28 */
29
30void mexFunction(int nlhs, mxArray *plhs[],
31                 int nrhs, const mxArray *prhs[])
32{
33    int         libIndex    = 0;
34    int         retLibIndex = 0;
35    int         err         = 1;
36    RpLibrary*  lib         = NULL;
37    char*       path        = NULL;
38    const char* retString   = NULL;
39
40    /* Check for proper number of arguments. */
41    if (nrhs != 2)
42        mexErrMsgTxt("Two input required.");
43    else if (nlhs > 2)
44        mexErrMsgTxt("Too many output arguments.");
45
46    libIndex = getIntInput(prhs[0]);
47    path = getStringInput(prhs[1]);
48
49    /* Call the C subroutine. */
50    if ( (libIndex > 0) && (path) ) {
51        lib = getObject_Lib(libIndex);
52
53        if (lib) {
54            retString = rpGetString(lib,path);
55            if (retString) {
56                err = 0;
57            }
58        }
59    }
60
61    /* Set C-style string output_buf to MATLAB mexFunction output*/
62    plhs[0] = mxCreateString(retString);
63    plhs[1] = mxCreateDoubleScalar(err);
64
65    return;
66}
Note: See TracBrowser for help on using the repository browser.