114 | | <a name="l00053"></a>00053 mat val = mxArray2mat ( value ); |
115 | | <a name="l00054"></a>00054 <span class="keywordflow">if</span> ( ( val.rows() == 1 ) && ( val.cols() == 1 ) ) { |
116 | | <a name="l00055"></a>00055 Setting &child = ( key == <span class="stringliteral">""</span> ) ? setting.add ( Setting::TypeFloat ) |
117 | | <a name="l00056"></a>00056 : setting.add ( key, Setting::TypeFloat ); |
118 | | <a name="l00057"></a>00057 child = val ( 0, 0 ); |
119 | | <a name="l00058"></a>00058 } <span class="keywordflow">else</span> { |
120 | | <a name="l00059"></a>00059 Setting &child = ( key == <span class="stringliteral">""</span> ) ? setting.add ( Setting::TypeList ) |
121 | | <a name="l00060"></a>00060 : setting.add ( key, Setting::TypeList ); |
122 | | <a name="l00061"></a>00061 Setting &label = child.add ( Setting::TypeString ); |
123 | | <a name="l00062"></a>00062 label = <span class="stringliteral">"matrix"</span>; |
124 | | <a name="l00063"></a>00063 Setting &rows = child.add ( Setting::TypeInt ); |
125 | | <a name="l00064"></a>00064 Setting &cols = child.add ( Setting::TypeInt ); |
126 | | <a name="l00065"></a>00065 Setting &elements = child.add ( Setting::TypeArray ); |
127 | | <a name="l00066"></a>00066 cols = val.cols(); |
128 | | <a name="l00067"></a>00067 rows = val.rows(); |
129 | | <a name="l00068"></a>00068 <span class="keywordflow">for</span> ( <span class="keywordtype">int</span> i = 0; i < val.rows(); i++ ) { |
130 | | <a name="l00069"></a>00069 <span class="keywordflow">for</span> ( <span class="keywordtype">int</span> j = 0; j < val.cols(); j++ ) { |
131 | | <a name="l00070"></a>00070 Setting &el = elements.add ( Setting::TypeFloat ); |
132 | | <a name="l00071"></a>00071 el = val ( i, j ); |
133 | | <a name="l00072"></a>00072 } |
134 | | <a name="l00073"></a>00073 } |
135 | | <a name="l00074"></a>00074 } |
136 | | <a name="l00075"></a>00075 } |
137 | | <a name="l00076"></a>00076 |
138 | | <a name="l00077"></a>00077 <span class="keywordtype">void</span> fillGroup ( Setting &setting, <span class="keyword">const</span> mxArray *mxarray ) { |
139 | | <a name="l00078"></a>00078 <span class="keywordflow">if</span> ( !mxIsStruct ( mxarray ) ) { |
140 | | <a name="l00079"></a>00079 mexErrMsgTxt ( <span class="stringliteral">"Given mxArray is not a struct."</span> ); |
141 | | <a name="l00080"></a>00080 }; |
142 | | <a name="l00081"></a>00081 <span class="keywordflow">for</span> ( <span class="keywordtype">int</span> i = 0; i < mxGetNumberOfFields ( mxarray ); i++ ) { |
143 | | <a name="l00082"></a>00082 <span class="keyword">const</span> <span class="keywordtype">char</span> *key = mxGetFieldNameByNumber ( mxarray, i ); |
144 | | <a name="l00083"></a>00083 mxArray *value = mxGetField ( mxarray, 0, key ); |
145 | | <a name="l00084"></a>00084 <span class="keywordflow">if</span> ( mxIsChar ( value ) ) { |
146 | | <a name="l00085"></a>00085 Setting &child = setting.add ( key, Setting::TypeString ); |
147 | | <a name="l00086"></a>00086 child = mxArray2string ( value ); |
148 | | <a name="l00087"></a>00087 } |
149 | | <a name="l00088"></a>00088 <span class="keywordflow">if</span> ( mxIsLogical ( value ) ) { |
150 | | <a name="l00089"></a>00089 Setting &child = setting.add ( key, Setting::TypeBoolean ); |
151 | | <a name="l00090"></a>00090 child = ( bool ) mxArray2bin ( value ); |
| 114 | <a name="l00053"></a>00053 <span class="comment">//treat empty matrices independently</span> |
| 115 | <a name="l00054"></a>00054 mat val; |
| 116 | <a name="l00055"></a>00055 <span class="keywordflow">if</span> (mxGetM(value)>0) { |
| 117 | <a name="l00056"></a>00056 val = mxArray2mat ( value ); |
| 118 | <a name="l00057"></a>00057 } |
| 119 | <a name="l00058"></a>00058 <span class="keywordflow">if</span> ( ( val.rows() == 1 ) && ( val.cols() == 1 ) ) { |
| 120 | <a name="l00059"></a>00059 Setting &child = ( key == <span class="stringliteral">""</span> ) ? setting.add ( Setting::TypeFloat ) |
| 121 | <a name="l00060"></a>00060 : setting.add ( key, Setting::TypeFloat ); |
| 122 | <a name="l00061"></a>00061 child = val ( 0, 0 ); |
| 123 | <a name="l00062"></a>00062 } <span class="keywordflow">else</span> { |
| 124 | <a name="l00063"></a>00063 Setting &child = ( key == <span class="stringliteral">""</span> ) ? setting.add ( Setting::TypeList ) |
| 125 | <a name="l00064"></a>00064 : setting.add ( key, Setting::TypeList ); |
| 126 | <a name="l00065"></a>00065 Setting &label = child.add ( Setting::TypeString ); |
| 127 | <a name="l00066"></a>00066 label = <span class="stringliteral">"matrix"</span>; |
| 128 | <a name="l00067"></a>00067 Setting &rows = child.add ( Setting::TypeInt ); |
| 129 | <a name="l00068"></a>00068 Setting &cols = child.add ( Setting::TypeInt ); |
| 130 | <a name="l00069"></a>00069 Setting &elements = child.add ( Setting::TypeArray ); |
| 131 | <a name="l00070"></a>00070 cols = val.cols(); |
| 132 | <a name="l00071"></a>00071 rows = val.rows(); |
| 133 | <a name="l00072"></a>00072 <span class="keywordflow">for</span> ( <span class="keywordtype">int</span> i = 0; i < val.rows(); i++ ) { |
| 134 | <a name="l00073"></a>00073 <span class="keywordflow">for</span> ( <span class="keywordtype">int</span> j = 0; j < val.cols(); j++ ) { |
| 135 | <a name="l00074"></a>00074 Setting &el = elements.add ( Setting::TypeFloat ); |
| 136 | <a name="l00075"></a>00075 el = val ( i, j ); |
| 137 | <a name="l00076"></a>00076 } |
| 138 | <a name="l00077"></a>00077 } |
| 139 | <a name="l00078"></a>00078 } |
| 140 | <a name="l00079"></a>00079 } |
| 141 | <a name="l00080"></a>00080 |
| 142 | <a name="l00081"></a>00081 <span class="keywordtype">void</span> fillGroup ( Setting &setting, <span class="keyword">const</span> mxArray *mxarray ) { |
| 143 | <a name="l00082"></a>00082 <span class="keywordflow">if</span> ( !mxIsStruct ( mxarray ) ) { |
| 144 | <a name="l00083"></a>00083 mexErrMsgTxt ( <span class="stringliteral">"Given mxArray is not a struct."</span> ); |
| 145 | <a name="l00084"></a>00084 }; |
| 146 | <a name="l00085"></a>00085 <span class="keywordflow">for</span> ( <span class="keywordtype">int</span> i = 0; i < mxGetNumberOfFields ( mxarray ); i++ ) { |
| 147 | <a name="l00086"></a>00086 <span class="keyword">const</span> <span class="keywordtype">char</span> *key = mxGetFieldNameByNumber ( mxarray, i ); |
| 148 | <a name="l00087"></a>00087 mxArray *value = mxGetField ( mxarray, 0, key ); |
| 149 | <a name="l00088"></a>00088 <span class="keywordflow">if</span> ( mxIsChar ( value ) ) { |
| 150 | <a name="l00089"></a>00089 Setting &child = setting.add ( key, Setting::TypeString ); |
| 151 | <a name="l00090"></a>00090 child = mxArray2string ( value ); |
161 | | <a name="l00100"></a>00100 <span class="keywordflow">if</span> ( mxIsNumeric ( value ) ) { |
162 | | <a name="l00101"></a>00101 storeNumeric ( setting, value, ( <span class="keywordtype">string</span> ) key ); |
163 | | <a name="l00102"></a>00102 } |
164 | | <a name="l00103"></a>00103 } |
165 | | <a name="l00104"></a>00104 } |
166 | | <a name="l00105"></a>00105 |
167 | | <a name="l00106"></a>00106 <span class="keywordtype">void</span> fillList ( Setting &setting, <span class="keyword">const</span> mxArray *mxarray ) { |
168 | | <a name="l00107"></a>00107 <span class="keywordflow">if</span> ( !mxIsCell ( mxarray ) ) { |
169 | | <a name="l00108"></a>00108 mexErrMsgTxt ( <span class="stringliteral">"Given mxArray is not a cell."</span> ); |
170 | | <a name="l00109"></a>00109 }; |
171 | | <a name="l00110"></a>00110 <span class="keywordflow">for</span> ( <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> i = 0; i < (<span class="keywordtype">unsigned</span> int) mxGetNumberOfElements ( mxarray ); i++ ) { |
172 | | <a name="l00111"></a>00111 mxArray *value = mxGetCell ( mxarray, i ); |
173 | | <a name="l00112"></a>00112 <span class="keywordflow">if</span> ( mxIsChar ( value ) ) { |
174 | | <a name="l00113"></a>00113 Setting &child = setting.add ( Setting::TypeString ); |
175 | | <a name="l00114"></a>00114 child = mxArray2string ( value ); |
176 | | <a name="l00115"></a>00115 } |
177 | | <a name="l00116"></a>00116 <span class="keywordflow">if</span> ( mxIsLogical ( value ) ) { |
178 | | <a name="l00117"></a>00117 Setting &child = setting.add ( Setting::TypeBoolean ); |
179 | | <a name="l00118"></a>00118 child = ( bool ) mxArray2bin ( value ); |
| 161 | <a name="l00100"></a>00100 <span class="keywordflow">if</span> ( mxIsCell ( value ) ) { |
| 162 | <a name="l00101"></a>00101 Setting &child = setting.add ( key, Setting::TypeList ); |
| 163 | <a name="l00102"></a>00102 fillList ( child, value ); |
| 164 | <a name="l00103"></a>00103 } |
| 165 | <a name="l00104"></a>00104 <span class="keywordflow">if</span> ( mxIsNumeric ( value ) ) { |
| 166 | <a name="l00105"></a>00105 storeNumeric ( setting, value, ( <span class="keywordtype">string</span> ) key ); |
| 167 | <a name="l00106"></a>00106 } |
| 168 | <a name="l00107"></a>00107 } |
| 169 | <a name="l00108"></a>00108 } |
| 170 | <a name="l00109"></a>00109 |
| 171 | <a name="l00110"></a>00110 <span class="keywordtype">void</span> fillList ( Setting &setting, <span class="keyword">const</span> mxArray *mxarray ) { |
| 172 | <a name="l00111"></a>00111 <span class="keywordflow">if</span> ( !mxIsCell ( mxarray ) ) { |
| 173 | <a name="l00112"></a>00112 mexErrMsgTxt ( <span class="stringliteral">"Given mxArray is not a cell."</span> ); |
| 174 | <a name="l00113"></a>00113 }; |
| 175 | <a name="l00114"></a>00114 <span class="keywordflow">for</span> ( <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> i = 0; i < (<span class="keywordtype">unsigned</span> int) mxGetNumberOfElements ( mxarray ); i++ ) { |
| 176 | <a name="l00115"></a>00115 mxArray *value = mxGetCell ( mxarray, i ); |
| 177 | <a name="l00116"></a>00116 <span class="keywordflow">if</span> ( mxIsChar ( value ) ) { |
| 178 | <a name="l00117"></a>00117 Setting &child = setting.add ( Setting::TypeString ); |
| 179 | <a name="l00118"></a>00118 child = mxArray2string ( value ); |
189 | | <a name="l00128"></a>00128 <span class="keywordflow">if</span> ( mxIsNumeric ( value ) ) { |
190 | | <a name="l00129"></a>00129 storeNumeric ( setting, value ); |
191 | | <a name="l00130"></a>00130 } |
192 | | <a name="l00131"></a>00131 } |
193 | | <a name="l00132"></a>00132 } |
194 | | <a name="l00133"></a>00133 }; |
195 | | <a name="l00134"></a>00134 |
196 | | <a name="l00135"></a>00135 <span class="preprocessor">#endif //MXPARSE_H</span> |
| 189 | <a name="l00128"></a>00128 <span class="keywordflow">if</span> ( mxIsCell ( value ) ) { |
| 190 | <a name="l00129"></a>00129 Setting &child = setting.add ( Setting::TypeList ); |
| 191 | <a name="l00130"></a>00130 fillList ( child, value ); |
| 192 | <a name="l00131"></a>00131 } |
| 193 | <a name="l00132"></a>00132 <span class="keywordflow">if</span> ( mxIsNumeric ( value ) ) { |
| 194 | <a name="l00133"></a>00133 storeNumeric ( setting, value ); |
| 195 | <a name="l00134"></a>00134 } |
| 196 | <a name="l00135"></a>00135 } |
| 197 | <a name="l00136"></a>00136 } |
| 198 | <a name="l00137"></a>00137 }; |
| 199 | <a name="l00138"></a>00138 |
| 200 | <a name="l00139"></a>00139 <span class="preprocessor">#endif //MXPARSE_H</span> |