Changeset 3629
- Timestamp:
- Apr 12, 2013 4:10:38 PM (11 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/1.2/lang/matlab/rpLibGetString.cc
r3177 r3629 28 28 */ 29 29 30 void mexFunction(int nlhs, mxArray *plhs[], 31 int nrhs, const mxArray *prhs[]) 30 31 void 32 mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[]) 32 33 { 33 int libIndex = 0; 34 int retLibIndex = 0; 35 int err = 1; 36 RpLibrary* lib = NULL; 37 std::string path = ""; 38 std::string retStr = ""; 34 int libIndex; 35 int err = 1; 36 std::string path; 39 37 40 38 /* Check for proper number of arguments. */ 41 39 if (nrhs != 2) { 42 mexErrMsgTxt("Two input required."); 40 mexErrMsgTxt("wrong # of arguments: " 41 "should be rpLibGetString(lib, path)"); 43 42 } 44 43 … … 48 47 /* Call the C subroutine. */ 49 48 if ( (libIndex > 0) && (!path.empty()) ) { 50 lib = (RpLibrary*) getObject_Void(libIndex);49 RpLibrary* lib; 51 50 52 if (lib) { 53 retStr = lib->getString(path); 54 err = 0; 55 } 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 } 56 71 } 57 58 72 /* Set C-style string output_buf to MATLAB mexFunction output*/ 59 plhs[0] = mxCreateString( retStr.c_str());73 plhs[0] = mxCreateString(""); 60 74 plhs[1] = mxCreateDoubleScalar(err); 61 62 75 return; 63 76 }
Note: See TracChangeset
for help on using the changeset viewer.