octave-maintainers
[Top][All Lists]
Advanced

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

OOP and load/save


From: John W. Eaton
Subject: OOP and load/save
Date: Wed, 22 Apr 2009 21:35:21 -0400

On 22-Apr-2009, Robert T. Short wrote:

| I have no idea how to cause the constructor to
| be parsed and executed, but I am sure I can figure this out.

Something like this should work:

DEFUN (doit, args, , "")
{
  octave_value retval;

  if (args.length () == 1)
    {
      std::string cname = args(0).string_value ();

      octave_value ctor = symbol_table::find_method (cname, cname);

      if (ctor.is_defined ())
        {
          octave_value_list result = feval (ctor, 1);

          if (result.length () == 1)
            {
              octave_value object  = result(0);

              // do something with the newly constructed object...
              retval = object;
            }
          else
            error ("call to constructor for class %s failed", cname.c_str ());
        }
      else
        error ("no constructor for class %s", cname.c_str ());
    }
  else
    print_usage ();

  return retval;
}

Play with it as is, or extract what you need...

jwe


reply via email to

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