Пример #1
0
octave_value OR_StructMatrix::to_octave()
{
  int i, row_index, column_index;
  VALUE row, cell;
  VALUE cells = rb_iv_get(ruby_val, "@cells");
  VALUE names = rb_iv_get(ruby_val, "@names");
  int number_of_keys = RARRAY(names)->len;
  int number_of_rows = FIX2INT(rb_iv_get(ruby_val, "@m"));
  int number_of_columns = FIX2INT(rb_iv_get(ruby_val, "@n"));

  string_vector keys = string_vector();
  for (i = 0; i < number_of_keys; i++) {
    keys.append(std::string(RSTRING(RARRAY(names)->ptr[i])->ptr));
  }
  
  Octave_map struct_matrix = Octave_map(dim_vector(number_of_rows, number_of_columns), Cell(keys));
  for (row_index = 0; row_index < number_of_rows; row_index++) {
    row = RARRAY(cells)->ptr[row_index];
  
    for (column_index = 0; column_index < number_of_columns; column_index++) {
      cell = RARRAY(row)->ptr[column_index];
      
      for (i = 0; i < number_of_keys; i++) {
        struct_matrix.contents(std::string(RSTRING(RARRAY(names)->ptr[i])->ptr))(row_index, column_index) = OR_Variable(rb_hash_aref(cell, rb_str_new2(RSTRING(RARRAY(names)->ptr[i])->ptr))).to_octave();
      }
    }
  }
  
  return struct_matrix;
}
Пример #2
0
octave_value OR_Hash::to_octave()
{
  int i;
  VALUE names = rb_funcall(ruby_val, rb_intern("keys"), 0);
  int number_of_keys = RARRAY_LEN(names);

  string_vector keys = string_vector();
  for (i = 0; i < number_of_keys; i++) {
    keys.append(std::string(RSTRING_PTR(RARRAY_PTR(names)[i])));
  }

  octave_map struct_matrix = octave_map(keys);
  for (i = 0; i < number_of_keys; i++) {
    struct_matrix.contents(std::string(RSTRING_PTR(RARRAY_PTR(names)[i]))) = OR_Variable(rb_hash_aref(ruby_val, rb_str_new2(RSTRING_PTR(RARRAY_PTR(names)[i])))).to_octave();
  }

  return struct_matrix;
}