help-octave
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Using structures in octave C++ DLD functions


From: Geraint Paul Bevan
Subject: Re: Using structures in octave C++ DLD functions
Date: Wed, 30 Jun 2004 14:44:21 +0100
User-agent: Mozilla Thunderbird 0.5 (X11/20040306)

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Federico Zenith wrote on 06/30/04 11:18:
| Hi,
| I am working on a C++ DLD function, and I would find it practical to use
| structures. I have not found on the Wiki how structures are handled in C++
| when writing for Octave.
|

|
| So, how do I operate with structures from Octave? How are they passed
to C++?
|
| -Federico


You can use the Octave_map class to get access to the elements of a
structure. Below is an example of how you could add an element "a.b.c"
with a value of -1 to a structure "a" defined in the Octave workspace.

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
~  }

}



- --
Geraint Bevan
http://www.mech.gla.ac.uk/~gbevan

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.4 (GNU/Linux)

iEYEARECAAYFAkDiw7UACgkQcXV3N50QmNN2PACfUOJphgYWzVGQ394/VLs54zlh
6mcAn2gubpqoRwpaglNf5jWm0TVrgJKD
=gla5
-----END PGP SIGNATURE-----



-------------------------------------------------------------
Octave is freely available under the terms of the GNU GPL.

Octave's home on the web:  http://www.octave.org
How to fund new projects:  http://www.octave.org/funding.html
Subscription information:  http://www.octave.org/archive.html
-------------------------------------------------------------



reply via email to

[Prev in Thread] Current Thread [Next in Thread]