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-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] = 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 | |
---|
30 | |
---|
31 | void |
---|
32 | mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[]) |
---|
33 | { |
---|
34 | int libIndex; |
---|
35 | int err = 1; |
---|
36 | std::string path; |
---|
37 | |
---|
38 | /* Check for proper number of arguments. */ |
---|
39 | if (nrhs != 2) { |
---|
40 | mexErrMsgTxt("wrong # of arguments: " |
---|
41 | "should be rpLibGetString(lib, path)"); |
---|
42 | } |
---|
43 | |
---|
44 | libIndex = getIntInput(prhs[0]); |
---|
45 | path = getStringInput(prhs[1]); |
---|
46 | |
---|
47 | /* Call the C subroutine. */ |
---|
48 | if ( (libIndex > 0) && (!path.empty()) ) { |
---|
49 | RpLibrary* lib; |
---|
50 | |
---|
51 | lib = (RpLibrary*)getObject_Void(libIndex); |
---|
52 | if (lib != NULL) { |
---|
53 | std::string contents; |
---|
54 | contents = lib->getString(path); |
---|
55 | |
---|
56 | mwSize dims[2]; |
---|
57 | dims[0] = 1; /* Treat as a row vector. */ |
---|
58 | dims[1] = contents.length(); |
---|
59 | plhs[0] = mxCreateCharArray(2, dims); |
---|
60 | |
---|
61 | /* Copy character array (may include NULs) into the matlab |
---|
62 | * array. */ |
---|
63 | const char *src = contents.c_str(); |
---|
64 | mxChar *dest = (mxChar *)mxGetPr(plhs[0]); |
---|
65 | for (int i = 0; i < contents.length(); i++) { |
---|
66 | dest[i] = src[i]; |
---|
67 | } |
---|
68 | plhs[1] = mxCreateDoubleScalar(0); |
---|
69 | return; |
---|
70 | } |
---|
71 | } |
---|
72 | /* Set C-style string output_buf to MATLAB mexFunction output*/ |
---|
73 | plhs[0] = mxCreateString(""); |
---|
74 | plhs[1] = mxCreateDoubleScalar(err); |
---|
75 | return; |
---|
76 | } |
---|