@@ -195,15 +195,11 @@ class extractor : public argument_helper<const mxArray> {
195
195
196
196
std::vector<nix::Value> extractFromCells (size_t pos) const {
197
197
198
- mwSize total_num_of_cells;
199
- mwIndex index;
200
- const mxArray *cell_element_ptr;
201
-
202
198
std::vector<nix::Value> vals;
203
199
204
- total_num_of_cells = mxGetNumberOfElements (array[pos]);
205
- for (index = 0 ; index<total_num_of_cells; index++) {
206
- cell_element_ptr = mxGetCell (array[pos], index);
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);
207
203
208
204
nix::Value currVal;
209
205
@@ -246,7 +242,7 @@ class extractor : public argument_helper<const mxArray> {
246
242
case mxCHAR_CLASS:
247
243
{
248
244
char *tmp = mxArrayToString (cell_element_ptr);
249
- std::string curr_string ( tmp) ;
245
+ std::string curr_string = tmp;
250
246
currVal.set (curr_string);
251
247
mxFree (tmp);
252
248
break ;
@@ -263,136 +259,90 @@ class extractor : public argument_helper<const mxArray> {
263
259
264
260
std::vector<nix::Value> extractFromStruct (size_t pos) const {
265
261
266
- mwSize total_num_of_cells;
267
- mwIndex index;
268
- const mxArray *cell_element_ptr;
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
269
270
270
std::vector<nix::Value> vals;
271
271
272
- total_num_of_cells = mxGetNumberOfElements (array[pos]);
273
- for (index = 0 ; index<total_num_of_cells; index++) {
274
- cell_element_ptr = mxGetCell (array[pos], index);
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
275
276
276
if (mxGetClassID (cell_element_ptr) == mxSTRUCT_CLASS){
277
277
278
278
nix::Value currVal;
279
279
280
- mwSize total_num_of_elements;
281
- mwIndex struct_idx;
282
- int number_of_fields;
283
- int field_index;
284
-
285
- total_num_of_elements = mxGetNumberOfElements (cell_element_ptr);
286
- number_of_fields = mxGetNumberOfFields (cell_element_ptr);
287
-
288
- mexPrintf (" numEl: %d, numField: %d\n " , total_num_of_elements, number_of_fields);
289
-
290
- for (struct_idx = 0 ; struct_idx < total_num_of_elements; struct_idx++) {
291
- for (field_index = 0 ; field_index < number_of_fields; field_index++) {
292
- const char *field_name;
293
- const mxArray *field_array_ptr;
294
- field_name = mxGetFieldNameByNumber (cell_element_ptr, field_index);
295
- field_array_ptr = mxGetFieldByNumber (cell_element_ptr, struct_idx, field_index);
296
- mexPrintf (" \n .%s, %d, %d\n " , field_name, struct_idx, field_index);
297
- if (field_array_ptr == NULL ) {
298
- mexPrintf (" \t Empty Field\n " );
299
- }
300
- else
301
- {
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 ) {
302
289
if (strcmp (field_name, " value" ) == 0 ){
303
- mexPrintf (" class: %d\n " , mxGetClassID (field_array_ptr));
304
- mexPrintf (" 1 field: %s, value: " , field_name);
305
290
if (mxGetClassID (field_array_ptr) == mxDOUBLE_CLASS){
306
- mexPrintf (" double\n " );
307
291
double curr;
308
292
const void *data = mxGetData (field_array_ptr);
309
293
memcpy (&curr, data, sizeof (double ));
310
294
currVal.set (curr);
311
- mexPrintf (" %d\n " , currVal.get <double >());
312
295
}
313
296
else if (mxGetClassID (field_array_ptr) == mxLOGICAL_CLASS){
314
- mexPrintf (" logical\n " );
315
297
const mxLogical *curr = mxGetLogicals (field_array_ptr);
316
298
currVal.set (curr[0 ]);
317
299
}
318
300
else if (mxGetClassID (field_array_ptr) == mxCHAR_CLASS){
319
- mexPrintf (" string\n " );
320
301
char *tmp = mxArrayToString (field_array_ptr);
321
- if (*tmp != NULL )
322
- {
323
- std::string curr_string (tmp);
324
- currVal.set (curr_string);
325
- }
302
+ std::string curr_string = tmp;
303
+ currVal.set (curr_string);
326
304
mxFree (tmp);
327
- mexPrintf (" %s\n " , currVal.get <std::string>());
328
- }
329
- else {
330
- mexPrintf (" sometyhing else\n " );
331
305
}
306
+ else { mexPrintf (" Unsupported value data type\n " ); }
332
307
333
308
}
334
309
else if (strcmp (field_name, " uncertainty" ) == 0 ){
335
- mexPrintf (" 2 field: %s, value: " , field_name);
336
310
if (mxGetClassID (field_array_ptr) == mxDOUBLE_CLASS){
337
311
double curr;
338
312
const void *data = mxGetData (field_array_ptr);
339
313
memcpy (&curr, data, sizeof (double ));
340
314
currVal.uncertainty = curr;
341
- mexPrintf (" %d, %d\n " , curr, currVal.uncertainty );
342
315
}
343
316
}
344
317
else if (strcmp (field_name, " checksum" ) == 0 ){
345
- mexPrintf (" 3 field: %s, value: \n " , field_name);
346
318
if (mxGetClassID (field_array_ptr) == mxCHAR_CLASS){
347
319
char *tmp = mxArrayToString (field_array_ptr);
348
- if (tmp != NULL )
349
- {
350
- mexPrintf (" get %s string, " , field_name);
351
- std::string curr_string (tmp);
352
- mexPrintf (" set value %s\n " , curr_string);
353
- currVal.checksum = curr_string;
354
- }
320
+ std::string curr_string = tmp;
321
+ currVal.checksum = curr_string;
355
322
mxFree (tmp);
356
323
}
357
324
}
358
325
else if (strcmp (field_name, " encoder" ) == 0 ){
359
- mexPrintf (" 4 field: %s, value: \n " , field_name);
360
326
if (mxGetClassID (field_array_ptr) == mxCHAR_CLASS){
361
327
char *tmp = mxArrayToString (field_array_ptr);
362
- if (tmp != NULL )
363
- {
364
- mexPrintf (" get %s string\n " , field_name);
365
- std::string curr_string (tmp);
366
- currVal.encoder = curr_string;
367
- }
328
+ std::string curr_string = tmp;
329
+ currVal.encoder = curr_string;
368
330
mxFree (tmp);
369
331
}
370
332
}
371
333
else if (strcmp (field_name, " filename" ) == 0 ){
372
- mexPrintf (" 5 field: %s, value: \n " , field_name);
373
334
if (mxGetClassID (field_array_ptr) == mxCHAR_CLASS){
374
335
char *tmp = mxArrayToString (field_array_ptr);
375
- if (tmp != NULL )
376
- {
377
- mexPrintf (" get %s string\n " , field_name);
378
- std::string curr_string (tmp);
379
- currVal.filename = curr_string;
380
- }
336
+ std::string curr_string = tmp;
337
+ currVal.filename = curr_string;
381
338
mxFree (tmp);
382
339
}
383
340
}
384
341
else if (strcmp (field_name, " reference" ) == 0 ){
385
- mexPrintf (" 6 field: %s, value: \n " , field_name);
386
342
if (mxGetClassID (field_array_ptr) == mxCHAR_CLASS){
387
343
char *tmp = mxArrayToString (field_array_ptr);
388
- if (tmp != NULL )
389
- {
390
- mexPrintf (" get %s string, set value %s" , field_name, tmp);
391
- // std::string curr_string(tmp);
392
- // mexPrintf("set value %s\n", curr_string);
393
- currVal.reference = *tmp;
394
- mexPrintf (" get %s string, get value %s" , field_name, currVal.reference );
395
- }
344
+ std::string curr_string (tmp);
345
+ currVal.reference = tmp;
396
346
mxFree (tmp);
397
347
}
398
348
}
@@ -403,7 +353,7 @@ class extractor : public argument_helper<const mxArray> {
403
353
}
404
354
else
405
355
{
406
- mexWarnMsgTxt (" Unsupported value wrapper type" );
356
+ mexWarnMsgTxt (" Unsupported value wrapper data type" );
407
357
}
408
358
}
409
359
return vals;
0 commit comments