c++,octave,example

structure.cc: 

#include <octave/oct.h> 
#include <octave/oct-map.h> 

DEFUN_DLD (structure, args, , "quick and dirty demo") 
{ 
~  octave_value_list retval; 
~  Octave_map a (args(0).map_value()); 
~  Octave_map ab (a.contents (a.seek ("b"))(0).map_value()); 
~  ab.assign ("c", -1.0); 
~  a.assign ("b", ab); 
~  retval(0) = a; 
~  return retval; 
} 

$ mkoctfile structure.cc 

octave:1> a.a = 0; a.b.a = 1; a.b.b = 2; a 
a = 
{ 
~  a = 0 
~  b = 
~  { 
~    a = 1 
~    b = 2 
~  } 

} 

octave:2> a = structure (a) 
a = 
{ 
~  a = 0 
~  b = 
~  { 
~    a = 1 
~    b = 2 
~    c = -1 
~  } 

}

Leave a Reply