source: trunk/src/matlab/rpLibChildrenByType.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.7 KB
Line 
1/*
2 * ----------------------------------------------------------------------
3 *  INTERFACE: Matlab Rappture Library Source
4 *
5 *    [nodeHandle,err] = rpLibChildrenByType(libHandle,path,prevNodeHandle,type)
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: [nodeHandle,err] = rpLibChildrenByType(libHandle,path,prevNodeHandle,type)
20/// Retrieve the children of the node described by 'path' of type 'type'
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 * children that match the type 'type'. If 'prevNodeHandle' = 0, then the`
25 * first child is returned, else, the next child is retrieved.
26 * If 'prevNodeHandle' is an invalid child handle, an error will be returned.
27 * Subsequent calls to rpLibChildrenByType() should use previously`
28 * returned 'nodeHandle's for it 'prevNodeHandle' argument.
29 * Error code, err=0 on success, anything else is failure.
30 */
31
32
33void mexFunction(int nlhs, mxArray *plhs[],
34                 int nrhs, const mxArray *prhs[])
35{
36    int         libIndex = 0;
37    int         childIndex = 0;
38    int         retLibIndex = 0;
39    int         err = 1;
40    RpLibrary*  lib = NULL;
41    RpLibrary*  child = NULL;
42    RpLibrary*  retLib = NULL;
43    char*       path = NULL;
44    char*       type = NULL;
45
46    /* Check for proper number of arguments. */
47    if (nrhs != 4)
48        mexErrMsgTxt("Four input required.");
49    else if (nlhs > 2)
50        mexErrMsgTxt("Too many output arguments.");
51
52    libIndex = getIntInput(prhs[0]);
53    path = getStringInput(prhs[1]);
54    childIndex = getIntInput(prhs[2]);
55    type = getStringInput(prhs[3]);
56
57    /* Call the C subroutine. */
58    if ( (libIndex > 0) && (path) && (type) ) {
59        lib = getObject_Lib(libIndex);
60
61        if (childIndex > 0) {
62            child = getObject_Lib(childIndex);
63        }
64
65        if (lib) {
66            retLib = rpChildrenByType(lib,path,child,type);
67            retLibIndex = storeObject_Lib(retLib);
68            if (retLibIndex) {
69                err = 0;
70            }
71        }
72    }
73
74    /* Set double scalar node handle to MATLAB mexFunction output*/
75    plhs[0] = mxCreateDoubleScalar(retLibIndex);
76    plhs[1] = mxCreateDoubleScalar(err);
77
78    return;
79}
Note: See TracBrowser for help on using the repository browser.