source: trunk/lang/matlab/rpLibElementAsId.cc @ 5673

Last change on this file since 5673 was 5673, checked in by ldelgass, 9 years ago

Fix line endings, set eol-style to native on all C/C++ sources.

  • Property svn:eol-style set to native
File size: 2.2 KB
Line 
1/*
2 * ----------------------------------------------------------------------
3 *  INTERFACE: Matlab Rappture Library Source
4 *
5 *    [retStr,err] = rpLibElementAsId(lib,path)
6 *
7 * ======================================================================
8 *  AUTHOR:  Derrick Kearney, Purdue University
9 *  Copyright (c) 2004-2012  HUBzero Foundation, LLC
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] = rpLibElementAsId(libHandle,path)
20/// Return the id attribute 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 * id attribute.
25 *
26 * If path is an empty string, the root of the node is used. 'libHandle'
27 * is the handle representing the instance of the RpLibrary object.
28 * Error code, err=0 on success, anything else is failure.
29 */
30
31void mexFunction(int nlhs, mxArray *plhs[],
32                 int nrhs, const mxArray *prhs[])
33{
34    int         libIndex = 0;
35    int         retLibIndex = 0;
36    int         err = 1;
37    RpLibrary*  lib = NULL;
38    RpLibrary*  eleLib = NULL;
39    std::string path = "";
40    std::string retStr = "";
41
42    /* Check for proper number of arguments. */
43    if (nrhs != 2) {
44        mexErrMsgTxt("Two input required.");
45    }
46
47    libIndex = getIntInput(prhs[0]);
48    path = getStringInput(prhs[1]);
49
50    /* Call the C subroutine. */
51    if ( (libIndex > 0) && (!path.empty()) ) {
52        lib = (RpLibrary*) getObject_Void(libIndex);
53        if (lib) {
54            eleLib = lib->element(path);
55            if (eleLib) {
56                retStr = eleLib->nodeId();
57                // an empty id field is valid
58                err = 0;
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.