[97] | 1 | /* |
---|
| 2 | * ---------------------------------------------------------------------- |
---|
| 3 | * INTERFACE: Matlab Rappture Library Source |
---|
| 4 | * |
---|
[154] | 5 | * [retStr,err] = rpLibGetString(libHandle,path) |
---|
[97] | 6 | * |
---|
| 7 | * ====================================================================== |
---|
| 8 | * AUTHOR: Derrick Kearney, Purdue University |
---|
[3177] | 9 | * Copyright (c) 2004-2012 HUBzero Foundation, LLC |
---|
[115] | 10 | * |
---|
| 11 | * See the file "license.terms" for information on usage and |
---|
| 12 | * redistribution of this file, and for a DISCLAIMER OF ALL WARRANTIES. |
---|
[97] | 13 | * ====================================================================== |
---|
| 14 | */ |
---|
| 15 | |
---|
| 16 | #include "RpMatlabInterface.h" |
---|
| 17 | |
---|
[154] | 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 | |
---|
[97] | 30 | void mexFunction(int nlhs, mxArray *plhs[], |
---|
| 31 | int nrhs, const mxArray *prhs[]) |
---|
| 32 | { |
---|
| 33 | int libIndex = 0; |
---|
| 34 | int retLibIndex = 0; |
---|
[154] | 35 | int err = 1; |
---|
[97] | 36 | RpLibrary* lib = NULL; |
---|
[162] | 37 | std::string path = ""; |
---|
| 38 | std::string retStr = ""; |
---|
[97] | 39 | |
---|
| 40 | /* Check for proper number of arguments. */ |
---|
[162] | 41 | if (nrhs != 2) { |
---|
[97] | 42 | mexErrMsgTxt("Two input required."); |
---|
[162] | 43 | } |
---|
[97] | 44 | |
---|
| 45 | libIndex = getIntInput(prhs[0]); |
---|
| 46 | path = getStringInput(prhs[1]); |
---|
| 47 | |
---|
| 48 | /* Call the C subroutine. */ |
---|
[162] | 49 | if ( (libIndex > 0) && (!path.empty()) ) { |
---|
[1085] | 50 | lib = (RpLibrary*) getObject_Void(libIndex); |
---|
[97] | 51 | |
---|
| 52 | if (lib) { |
---|
[162] | 53 | retStr = lib->getString(path); |
---|
| 54 | err = 0; |
---|
[97] | 55 | } |
---|
| 56 | } |
---|
| 57 | |
---|
| 58 | /* Set C-style string output_buf to MATLAB mexFunction output*/ |
---|
[162] | 59 | plhs[0] = mxCreateString(retStr.c_str()); |
---|
[154] | 60 | plhs[1] = mxCreateDoubleScalar(err); |
---|
[97] | 61 | |
---|
| 62 | return; |
---|
| 63 | } |
---|