view examples/structdemo.cc @ 12312:b10ea6efdc58 release-3-4-x ss-3-3-91

version is now 3.3.91
author John W. Eaton <jwe@octave.org>
date Mon, 31 Jan 2011 08:36:58 -0500
parents 23385f2c90b7
children be41c30bcb44
line wrap: on
line source

#include <octave/oct.h>
#include <octave/ov-struct.h>

DEFUN_DLD (structdemo, args, , "Struct demo.")
{
  int nargin = args.length ();
  octave_value retval;

  if (args.length () == 2)
    {
      octave_scalar_map arg0 = args(0).scalar_map_value ();

      if (! error_state)
        {
          std::string arg1 = args(1).string_value ();

          if (! error_state)
            {
              octave_value tmp = arg0.contents (arg1);

              if (tmp.is_defined ())
                {
                  octave_scalar_map st;

                  st.assign ("selected", tmp);

                  retval = octave_value (st);
                }
              else
                error ("sruct does not contain field named '%s'\n",
                       arg1.c_str ());
            }
          else
            error ("expecting character string as second argument");
        }
      else
        error ("expecting struct as first argument");
    }
  else
    print_usage ();

  return retval;
}