96 | | <a name="l00032"></a>00032 Setting &cols = child.add( Setting::TypeInt ); |
97 | | <a name="l00033"></a>00033 Setting &rows = child.add( Setting::TypeInt ); |
98 | | <a name="l00034"></a>00034 Setting &elements = child.add( Setting::TypeArray ); |
99 | | <a name="l00035"></a>00035 cols = val.cols(); |
100 | | <a name="l00036"></a>00036 rows = val.rows(); |
101 | | <a name="l00037"></a>00037 <span class="keywordflow">for</span> (<span class="keywordtype">int</span> i=0; i<val.rows(); i++) { |
102 | | <a name="l00038"></a>00038 <span class="keywordflow">for</span> (<span class="keywordtype">int</span> j=0; j<val.cols(); j++) { |
103 | | <a name="l00039"></a>00039 Setting &el = elements.add(Setting::TypeFloat); |
104 | | <a name="l00040"></a>00040 el = val(i,j); |
105 | | <a name="l00041"></a>00041 } |
106 | | <a name="l00042"></a>00042 } |
107 | | <a name="l00043"></a>00043 } |
108 | | <a name="l00044"></a>00044 } |
109 | | <a name="l00045"></a>00045 |
110 | | <a name="l00046"></a>00046 <span class="keywordtype">void</span> fillGroup(Setting &setting, <span class="keyword">const</span> mxArray *mxarray) { |
111 | | <a name="l00047"></a>00047 <span class="keywordflow">if</span> (!mxIsStruct(mxarray)) { mexErrMsgTxt(<span class="stringliteral">"Given mxArray is not a struct."</span>); }; |
112 | | <a name="l00048"></a>00048 <span class="keywordflow">for</span>(<span class="keywordtype">int</span> i=0; i < mxGetNumberOfFields(mxarray); i++) { |
113 | | <a name="l00049"></a>00049 <span class="keyword">const</span> <span class="keywordtype">char</span> *key = mxGetFieldNameByNumber(mxarray, i); |
114 | | <a name="l00050"></a>00050 mxArray *value = mxGetField(mxarray, 0, key); |
115 | | <a name="l00051"></a>00051 <span class="keywordflow">if</span> (mxIsChar(value)) { |
116 | | <a name="l00052"></a>00052 Setting &child = setting.add(key, Setting::TypeString); |
117 | | <a name="l00053"></a>00053 child = mxArray2string(value); |
118 | | <a name="l00054"></a>00054 } |
119 | | <a name="l00055"></a>00055 <span class="keywordflow">if</span> (mxIsLogical(value)) { |
120 | | <a name="l00056"></a>00056 Setting &child = setting.add(key, Setting::TypeBoolean); |
121 | | <a name="l00057"></a>00057 child = (bool) mxArray2bin(value); |
122 | | <a name="l00058"></a>00058 } |
123 | | <a name="l00059"></a>00059 <span class="keywordflow">if</span> (mxIsStruct(value)) { |
124 | | <a name="l00060"></a>00060 Setting &child = setting.add(key, Setting::TypeGroup); |
125 | | <a name="l00061"></a>00061 fillGroup(child, value); |
126 | | <a name="l00062"></a>00062 } |
127 | | <a name="l00063"></a>00063 <span class="keywordflow">if</span> (mxIsCell(value)) { |
128 | | <a name="l00064"></a>00064 Setting &child = setting.add(key, Setting::TypeList); |
129 | | <a name="l00065"></a>00065 fillList(child, value); |
130 | | <a name="l00066"></a>00066 } |
131 | | <a name="l00067"></a>00067 <span class="keywordflow">if</span> (mxIsNumeric(value)) { |
132 | | <a name="l00068"></a>00068 storeNumeric(setting, value, (<span class="keywordtype">string</span>)key); |
133 | | <a name="l00069"></a>00069 } |
134 | | <a name="l00070"></a>00070 } |
135 | | <a name="l00071"></a>00071 } |
136 | | <a name="l00072"></a>00072 |
137 | | <a name="l00073"></a>00073 <span class="keywordtype">void</span> fillList(Setting &setting, <span class="keyword">const</span> mxArray *mxarray) { |
138 | | <a name="l00074"></a>00074 <span class="keywordflow">if</span> (!mxIsCell(mxarray)) { mexErrMsgTxt(<span class="stringliteral">"Given mxArray is not a cell."</span>); }; |
139 | | <a name="l00075"></a>00075 <span class="keywordflow">for</span>(<span class="keywordtype">int</span> i=0; i < mxGetNumberOfElements(mxarray); i++) { |
140 | | <a name="l00076"></a>00076 mxArray *value = mxGetCell(mxarray, i); |
141 | | <a name="l00077"></a>00077 <span class="keywordflow">if</span> (mxIsChar(value)) { |
142 | | <a name="l00078"></a>00078 Setting &child = setting.add(Setting::TypeString); |
143 | | <a name="l00079"></a>00079 child = mxArray2string(value); |
144 | | <a name="l00080"></a>00080 } |
145 | | <a name="l00081"></a>00081 <span class="keywordflow">if</span> (mxIsLogical(value)) { |
146 | | <a name="l00082"></a>00082 Setting &child = setting.add(Setting::TypeBoolean); |
147 | | <a name="l00083"></a>00083 child = (bool) mxArray2bin(value); |
148 | | <a name="l00084"></a>00084 } |
149 | | <a name="l00085"></a>00085 <span class="keywordflow">if</span> (mxIsStruct(value)) { |
150 | | <a name="l00086"></a>00086 Setting &child = setting.add(Setting::TypeGroup); |
151 | | <a name="l00087"></a>00087 fillGroup(child, value); |
152 | | <a name="l00088"></a>00088 } |
153 | | <a name="l00089"></a>00089 <span class="keywordflow">if</span> (mxIsCell(value)) { |
154 | | <a name="l00090"></a>00090 Setting &child = setting.add(Setting::TypeList); |
155 | | <a name="l00091"></a>00091 fillList(child, value); |
156 | | <a name="l00092"></a>00092 } |
157 | | <a name="l00093"></a>00093 <span class="keywordflow">if</span> (mxIsNumeric(value)) { |
158 | | <a name="l00094"></a>00094 storeNumeric(setting, value); |
159 | | <a name="l00095"></a>00095 } |
160 | | <a name="l00096"></a>00096 } |
161 | | <a name="l00097"></a>00097 } |
162 | | <a name="l00098"></a>00098 }; |
| 96 | <a name="l00032"></a>00032 Setting &label = child.add(Setting::TypeString); |
| 97 | <a name="l00033"></a>00033 label = <span class="stringliteral">"matrix"</span>; |
| 98 | <a name="l00034"></a>00034 Setting &cols = child.add( Setting::TypeInt ); |
| 99 | <a name="l00035"></a>00035 Setting &rows = child.add( Setting::TypeInt ); |
| 100 | <a name="l00036"></a>00036 Setting &elements = child.add( Setting::TypeArray ); |
| 101 | <a name="l00037"></a>00037 cols = val.cols(); |
| 102 | <a name="l00038"></a>00038 rows = val.rows(); |
| 103 | <a name="l00039"></a>00039 <span class="keywordflow">for</span> (<span class="keywordtype">int</span> i=0; i<val.rows(); i++) { |
| 104 | <a name="l00040"></a>00040 <span class="keywordflow">for</span> (<span class="keywordtype">int</span> j=0; j<val.cols(); j++) { |
| 105 | <a name="l00041"></a>00041 Setting &el = elements.add(Setting::TypeFloat); |
| 106 | <a name="l00042"></a>00042 el = val(i,j); |
| 107 | <a name="l00043"></a>00043 } |
| 108 | <a name="l00044"></a>00044 } |
| 109 | <a name="l00045"></a>00045 } |
| 110 | <a name="l00046"></a>00046 } |
| 111 | <a name="l00047"></a>00047 |
| 112 | <a name="l00048"></a>00048 <span class="keywordtype">void</span> fillGroup(Setting &setting, <span class="keyword">const</span> mxArray *mxarray) { |
| 113 | <a name="l00049"></a>00049 <span class="keywordflow">if</span> (!mxIsStruct(mxarray)) { mexErrMsgTxt(<span class="stringliteral">"Given mxArray is not a struct."</span>); }; |
| 114 | <a name="l00050"></a>00050 <span class="keywordflow">for</span>(<span class="keywordtype">int</span> i=0; i < mxGetNumberOfFields(mxarray); i++) { |
| 115 | <a name="l00051"></a>00051 <span class="keyword">const</span> <span class="keywordtype">char</span> *key = mxGetFieldNameByNumber(mxarray, i); |
| 116 | <a name="l00052"></a>00052 mxArray *value = mxGetField(mxarray, 0, key); |
| 117 | <a name="l00053"></a>00053 <span class="keywordflow">if</span> (mxIsChar(value)) { |
| 118 | <a name="l00054"></a>00054 Setting &child = setting.add(key, Setting::TypeString); |
| 119 | <a name="l00055"></a>00055 child = mxArray2string(value); |
| 120 | <a name="l00056"></a>00056 } |
| 121 | <a name="l00057"></a>00057 <span class="keywordflow">if</span> (mxIsLogical(value)) { |
| 122 | <a name="l00058"></a>00058 Setting &child = setting.add(key, Setting::TypeBoolean); |
| 123 | <a name="l00059"></a>00059 child = (bool) mxArray2bin(value); |
| 124 | <a name="l00060"></a>00060 } |
| 125 | <a name="l00061"></a>00061 <span class="keywordflow">if</span> (mxIsStruct(value)) { |
| 126 | <a name="l00062"></a>00062 Setting &child = setting.add(key, Setting::TypeGroup); |
| 127 | <a name="l00063"></a>00063 fillGroup(child, value); |
| 128 | <a name="l00064"></a>00064 } |
| 129 | <a name="l00065"></a>00065 <span class="keywordflow">if</span> (mxIsCell(value)) { |
| 130 | <a name="l00066"></a>00066 Setting &child = setting.add(key, Setting::TypeList); |
| 131 | <a name="l00067"></a>00067 fillList(child, value); |
| 132 | <a name="l00068"></a>00068 } |
| 133 | <a name="l00069"></a>00069 <span class="keywordflow">if</span> (mxIsNumeric(value)) { |
| 134 | <a name="l00070"></a>00070 storeNumeric(setting, value, (<span class="keywordtype">string</span>)key); |
| 135 | <a name="l00071"></a>00071 } |
| 136 | <a name="l00072"></a>00072 } |
| 137 | <a name="l00073"></a>00073 } |
| 138 | <a name="l00074"></a>00074 |
| 139 | <a name="l00075"></a>00075 <span class="keywordtype">void</span> fillList(Setting &setting, <span class="keyword">const</span> mxArray *mxarray) { |
| 140 | <a name="l00076"></a>00076 <span class="keywordflow">if</span> (!mxIsCell(mxarray)) { mexErrMsgTxt(<span class="stringliteral">"Given mxArray is not a cell."</span>); }; |
| 141 | <a name="l00077"></a>00077 <span class="keywordflow">for</span>(<span class="keywordtype">int</span> i=0; i < mxGetNumberOfElements(mxarray); i++) { |
| 142 | <a name="l00078"></a>00078 mxArray *value = mxGetCell(mxarray, i); |
| 143 | <a name="l00079"></a>00079 <span class="keywordflow">if</span> (mxIsChar(value)) { |
| 144 | <a name="l00080"></a>00080 Setting &child = setting.add(Setting::TypeString); |
| 145 | <a name="l00081"></a>00081 child = mxArray2string(value); |
| 146 | <a name="l00082"></a>00082 } |
| 147 | <a name="l00083"></a>00083 <span class="keywordflow">if</span> (mxIsLogical(value)) { |
| 148 | <a name="l00084"></a>00084 Setting &child = setting.add(Setting::TypeBoolean); |
| 149 | <a name="l00085"></a>00085 child = (bool) mxArray2bin(value); |
| 150 | <a name="l00086"></a>00086 } |
| 151 | <a name="l00087"></a>00087 <span class="keywordflow">if</span> (mxIsStruct(value)) { |
| 152 | <a name="l00088"></a>00088 Setting &child = setting.add(Setting::TypeGroup); |
| 153 | <a name="l00089"></a>00089 fillGroup(child, value); |
| 154 | <a name="l00090"></a>00090 } |
| 155 | <a name="l00091"></a>00091 <span class="keywordflow">if</span> (mxIsCell(value)) { |
| 156 | <a name="l00092"></a>00092 Setting &child = setting.add(Setting::TypeList); |
| 157 | <a name="l00093"></a>00093 fillList(child, value); |
| 158 | <a name="l00094"></a>00094 } |
| 159 | <a name="l00095"></a>00095 <span class="keywordflow">if</span> (mxIsNumeric(value)) { |
| 160 | <a name="l00096"></a>00096 storeNumeric(setting, value); |
| 161 | <a name="l00097"></a>00097 } |
| 162 | <a name="l00098"></a>00098 } |
| 163 | <a name="l00099"></a>00099 } |
| 164 | <a name="l00100"></a>00100 }; |