source: trunk/lang/matlab/rpLibElementAsComp.cc @ 2701

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

adjusting matlab and octave bindings to use the void* bindings dictionary instead of the lib* dictionary in hopes that we can phase out the lib* dictionary.

File size: 2.2 KB
Line 
1/*
2 * ----------------------------------------------------------------------
3 *  INTERFACE: Matlab Rappture Library Source
4 *
5 *    [retStr,err] = rpLibElementAsComp(lib,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] = rpLibElementAsComp(libHandle,path)
20/// Return the component name of the element at location 'path' in 'libHandle'
21/**
22 * This method searches the Rappture Library Object 'libHandle' for the
23 * node at the location described by the path 'path' and returns its
24 * component name, a concatination of the type, id, and index.
25 * If path is an empty string, the root of the node is used. 'libHandle'
26 * is the handle representing the instance of the RpLibrary object.
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 = 0;
36    RpLibrary*  lib = NULL;
37    RpLibrary*  eleLib = NULL;
38    std::string path = "";
39    std::string retStr = "";
40
41    /* Check for proper number of arguments. */
42    if (nrhs != 2) {
43        mexErrMsgTxt("Two input required.");
44    }
45
46    libIndex = getIntInput(prhs[0]);
47    path = getStringInput(prhs[1]);
48
49    /* Call the C++ subroutine. */
50    if ( (libIndex > 0) && (!path.empty()) ) {
51        lib = (RpLibrary*) getObject_Void(libIndex);
52        if (lib) {
53            eleLib = lib->element(path);
54            if (eleLib) {
55                retStr = eleLib->nodeComp();
56                if (!retStr.empty()) {
57                    err = 0;
58                }
59            }
60        }
61    }
62
63    /* Set C-style string output_buf to MATLAB mexFunction output*/
64    plhs[0] = mxCreateString(retStr.c_str());
65    plhs[1] = mxCreateDoubleScalar(err);
66
67    return;
68}
Note: See TracBrowser for help on using the repository browser.