@@ -193,6 +193,172 @@ class extractor : public argument_helper<const mxArray> {
193
193
return mxGetPr (array[pos]);
194
194
}
195
195
196
+ std::vector<nix::Value> extractFromCells (size_t pos) const {
197
+
198
+ std::vector<nix::Value> vals;
199
+
200
+ mwSize total_num_of_cells = mxGetNumberOfElements (array[pos]);
201
+ for (mwIndex index = 0 ; index<total_num_of_cells; index++) {
202
+ const mxArray *cell_element_ptr = mxGetCell (array[pos], index);
203
+
204
+ nix::Value currVal;
205
+
206
+ switch (mxGetClassID (cell_element_ptr)) {
207
+ case mxLOGICAL_CLASS:
208
+ {
209
+ const mxLogical *curr = mxGetLogicals (cell_element_ptr);
210
+ currVal.set (curr[0 ]); break ; }
211
+ case mxDOUBLE_CLASS:
212
+ {
213
+ double curr;
214
+ const void *data = mxGetData (cell_element_ptr);
215
+ memcpy (&curr, data, sizeof (double ));
216
+ currVal.set (curr); break ; }
217
+ case mxUINT32_CLASS:
218
+ {
219
+ uint32_t curr;
220
+ const void *data = mxGetData (cell_element_ptr);
221
+ memcpy (&curr, data, sizeof (uint32_t ));
222
+ currVal.set (curr); break ; }
223
+ case mxINT32_CLASS:
224
+ {
225
+ int32_t curr;
226
+ const void *data = mxGetData (cell_element_ptr);
227
+ memcpy (&curr, data, sizeof (int32_t ));
228
+ currVal.set (curr); break ; }
229
+ case mxUINT64_CLASS:
230
+ {
231
+ uint64_t curr;
232
+ const void *data = mxGetData (cell_element_ptr);
233
+ memcpy (&curr, data, sizeof (uint64_t ));
234
+ currVal.set (curr); break ; }
235
+ case mxINT64_CLASS:
236
+ {
237
+ int64_t curr;
238
+ const void *data = mxGetData (cell_element_ptr);
239
+ memcpy (&curr, data, sizeof (int64_t ));
240
+ currVal.set (curr); break ; }
241
+
242
+ case mxCHAR_CLASS:
243
+ {
244
+ char *tmp = mxArrayToString (cell_element_ptr);
245
+ std::string curr_string = tmp;
246
+ currVal.set (curr_string);
247
+ mxFree (tmp);
248
+ break ;
249
+ }
250
+ case mxUNKNOWN_CLASS:
251
+ { mexWarnMsgTxt (" Unknown class." ); break ; }
252
+ default :
253
+ { mexWarnMsgTxt (" Unsupported class." ); break ; }
254
+ }
255
+ vals.push_back (currVal);
256
+ }
257
+ return vals;
258
+ }
259
+
260
+ std::vector<nix::Value> extractFromStruct (size_t pos) const {
261
+
262
+ // Note: nix::Value is not able to its attributes "uncertainty"
263
+ // "checksum", "filename", "encoder" or "reference" at the moment.
264
+ // The setters are implemented and the attribute values are
265
+ // correctly set to the nix::Value entity, but they will not
266
+ // actually be written to the nix file. Once this issue has been
267
+ // fixed on the nix side, the current implementation should work
268
+ // fine.
269
+
270
+ std::vector<nix::Value> vals;
271
+
272
+ mwSize total_num_of_cells = mxGetNumberOfElements (array[pos]);
273
+ for (mwIndex index = 0 ; index<total_num_of_cells; index++) {
274
+ const mxArray *cell_element_ptr = mxGetCell (array[pos], index);
275
+
276
+ if (mxGetClassID (cell_element_ptr) == mxSTRUCT_CLASS){
277
+
278
+ nix::Value currVal;
279
+
280
+ mwSize total_num_of_elements = mxGetNumberOfElements (cell_element_ptr);
281
+ int number_of_fields = mxGetNumberOfFields (cell_element_ptr);
282
+
283
+ for (mwIndex struct_idx = 0 ; struct_idx < total_num_of_elements; struct_idx++) {
284
+ for (int field_index = 0 ; field_index < number_of_fields; field_index++) {
285
+ const char *field_name = mxGetFieldNameByNumber (cell_element_ptr, field_index);
286
+ const mxArray *field_array_ptr = mxGetFieldByNumber (cell_element_ptr, struct_idx, field_index);
287
+
288
+ if (field_array_ptr != nullptr ) {
289
+ if (strcmp (field_name, " value" ) == 0 ){
290
+ if (mxGetClassID (field_array_ptr) == mxDOUBLE_CLASS){
291
+ double curr;
292
+ const void *data = mxGetData (field_array_ptr);
293
+ memcpy (&curr, data, sizeof (double ));
294
+ currVal.set (curr);
295
+ }
296
+ else if (mxGetClassID (field_array_ptr) == mxLOGICAL_CLASS){
297
+ const mxLogical *curr = mxGetLogicals (field_array_ptr);
298
+ currVal.set (curr[0 ]);
299
+ }
300
+ else if (mxGetClassID (field_array_ptr) == mxCHAR_CLASS){
301
+ char *tmp = mxArrayToString (field_array_ptr);
302
+ std::string curr_string = tmp;
303
+ currVal.set (curr_string);
304
+ mxFree (tmp);
305
+ }
306
+ else { mexPrintf (" Unsupported value data type\n " ); }
307
+
308
+ }
309
+ else if (strcmp (field_name, " uncertainty" ) == 0 ){
310
+ if (mxGetClassID (field_array_ptr) == mxDOUBLE_CLASS){
311
+ double curr;
312
+ const void *data = mxGetData (field_array_ptr);
313
+ memcpy (&curr, data, sizeof (double ));
314
+ currVal.uncertainty = curr;
315
+ }
316
+ }
317
+ else if (strcmp (field_name, " checksum" ) == 0 ){
318
+ if (mxGetClassID (field_array_ptr) == mxCHAR_CLASS){
319
+ char *tmp = mxArrayToString (field_array_ptr);
320
+ std::string curr_string = tmp;
321
+ currVal.checksum = curr_string;
322
+ mxFree (tmp);
323
+ }
324
+ }
325
+ else if (strcmp (field_name, " encoder" ) == 0 ){
326
+ if (mxGetClassID (field_array_ptr) == mxCHAR_CLASS){
327
+ char *tmp = mxArrayToString (field_array_ptr);
328
+ std::string curr_string = tmp;
329
+ currVal.encoder = curr_string;
330
+ mxFree (tmp);
331
+ }
332
+ }
333
+ else if (strcmp (field_name, " filename" ) == 0 ){
334
+ if (mxGetClassID (field_array_ptr) == mxCHAR_CLASS){
335
+ char *tmp = mxArrayToString (field_array_ptr);
336
+ std::string curr_string = tmp;
337
+ currVal.filename = curr_string;
338
+ mxFree (tmp);
339
+ }
340
+ }
341
+ else if (strcmp (field_name, " reference" ) == 0 ){
342
+ if (mxGetClassID (field_array_ptr) == mxCHAR_CLASS){
343
+ char *tmp = mxArrayToString (field_array_ptr);
344
+ std::string curr_string (tmp);
345
+ currVal.reference = tmp;
346
+ mxFree (tmp);
347
+ }
348
+ }
349
+ }
350
+ }
351
+ }
352
+ vals.push_back (currVal);
353
+ }
354
+ else
355
+ {
356
+ mexWarnMsgTxt (" Unsupported value wrapper data type" );
357
+ }
358
+ }
359
+ return vals;
360
+ }
361
+
196
362
private:
197
363
};
198
364
@@ -214,4 +380,4 @@ class infusor : public argument_helper<mxArray> {
214
380
private:
215
381
};
216
382
217
- #endif
383
+ #endif
0 commit comments