Recursively build cell array in MEX? c/c++
Show older comments
Hi, before I even attempt to do this, I wanted to ask if anyone else (including Mathworks staff) has tried to recursively build a cell array? I have to deal with a library (hiredis) that may return nested results in a reply struct. I have to examine the reply type, and if it is a certain type, then I have to traverse all the child replies and examine each of them, etc.
Hiredis sets an arbitrary max nesting level, which I am also going to enforce. I set it to 7, which matches hiredis.
My mind is boggling a bit at what might be involved with recursively adding to the cell array which holds all the results. This is the last major task in writing my redis wrapper and I wish I could just ignore this but there are many redis commands which return replies of a type called "Multi Bulk" which can be arbitrarily nested.
I thought it would be better to ask for help in advance instead of posting a bunch of garbage asking "why I get error".
thx George
Answers (1)
James Tursa
on 7 Mar 2013
1 vote
Generally, you can pretty much build and/or examine "nested" cell or struct mxArray variables in the mex environment using the mxSetCell, mxGetCell, mxSetField, mxGetField etc API functions recursively. If you could provide a short descriptive sample (i.e., pseudo-code) of what you are trying to do we can probably advise how to go about it in C/C++.
3 Comments
George Coles
on 7 Mar 2013
Edited: George Coles
on 8 Mar 2013
George Coles
on 18 Mar 2013
Jan
on 18 Mar 2013
In general the code looks ok. There are two strong testers on your computer: 1. let the compiler parse the input, 2. let the code run and test the results with your expectations.
Btw., this is not C-code, but C++, because the later allows to declare variables inside the code. But as long as the compiler accept this, this is a cosmethical aspect only.
Categories
Find more on Write C Functions Callable from MATLAB (MEX Files) in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!