PageRenderTime 45ms CodeModel.GetById 13ms app.highlight 13ms RepoModel.GetById 2ms app.codeStats 0ms

/trunk/Lib/octave/octrun.swg

#
Unknown | 1489 lines | 1283 code | 206 blank | 0 comment | 0 complexity | fe5886f2f7bab8dc0869efc16754510e MD5 | raw file
   1
   2#include <octave/version.h>
   3#ifndef OCTAVE_API_VERSION_NUMBER
   4
   5  // Hack to distinguish between Octave 3.2 and earlier versions before OCTAVE_API_VERSION_NUMBER existed
   6  #define ComplexLU __ignore
   7  #include <octave/CmplxLU.h>
   8  #undef ComplexLU
   9  #ifdef octave_Complex_LU_h
  10  # define OCTAVE_API_VERSION_NUMBER 36
  11  #else
  12  # define OCTAVE_API_VERSION_NUMBER 37
  13  #endif
  14
  15#endif
  16
  17SWIGRUNTIME bool SWIG_check_num_args(const char *func_name, int num_args, int max_args, int min_args, int varargs) {
  18  if (num_args > max_args && !varargs)
  19    error("function %s takes at most %i arguments", func_name, max_args);
  20  else if (num_args < min_args)
  21    error("function %s requires at least %i arguments", func_name, min_args);
  22  else
  23    return true;
  24  return false;
  25}
  26
  27SWIGRUNTIME octave_value_list *SWIG_Octave_AppendOutput(octave_value_list *ovl, const octave_value &ov) {
  28  ovl->append(ov);
  29  return ovl;
  30}
  31
  32SWIGRUNTIME octave_value SWIG_ErrorType(int code) {
  33  switch (code) {
  34  case SWIG_MemoryError:
  35    return "SWIG_MemoryError";
  36  case SWIG_IOError:
  37    return "SWIG_IOError";
  38  case SWIG_RuntimeError:
  39    return "SWIG_RuntimeError";
  40  case SWIG_IndexError:
  41    return "SWIG_IndexError";
  42  case SWIG_TypeError:
  43    return "SWIG_TypeError";
  44  case SWIG_DivisionByZero:
  45    return "SWIG_DivisionByZero";
  46  case SWIG_OverflowError:
  47    return "SWIG_OverflowError";
  48  case SWIG_SyntaxError:
  49    return "SWIG_SyntaxError";
  50  case SWIG_ValueError:
  51    return "SWIG_ValueError";
  52  case SWIG_SystemError:
  53    return "SWIG_SystemError";
  54  case SWIG_AttributeError:
  55    return "SWIG_AttributeError";
  56  }
  57  return "SWIG unknown error";
  58}
  59
  60SWIGRUNTIME octave_value SWIG_Error(int code, const char *msg) {
  61  octave_value type(SWIG_ErrorType(code));
  62  std::string r = msg;
  63  r += " (" + type.string_value() + ")";
  64  error(r.c_str());
  65  return octave_value(r);
  66}
  67
  68#define SWIG_fail                                       goto fail
  69
  70#define SWIG_Octave_ConvertPtr(obj, pptr, type, flags)  SWIG_Octave_ConvertPtrAndOwn(obj, pptr, type, flags, 0)
  71#define SWIG_ConvertPtr(obj, pptr, type, flags)         SWIG_Octave_ConvertPtr(obj, pptr, type, flags)
  72#define SWIG_ConvertPtrAndOwn(obj,pptr,type,flags,own)  SWIG_Octave_ConvertPtrAndOwn(obj, pptr, type, flags, own)
  73#define SWIG_ConvertPtr(obj, pptr, type, flags)         SWIG_Octave_ConvertPtr(obj, pptr, type, flags)
  74#define SWIG_NewPointerObj(ptr, type, flags)            SWIG_Octave_NewPointerObj(ptr, type, flags)
  75#define swig_owntype                                    int
  76
  77#define SWIG_ConvertPacked(obj, ptr, sz, ty)            SWIG_Octave_ConvertPacked(obj, ptr, sz, ty)
  78#define SWIG_NewPackedObj(ptr, sz, type)                SWIG_Octave_NewPackedObj(ptr, sz, type)
  79
  80#define SWIG_ConvertFunctionPtr(obj, pptr, type)        SWIG_ConvertPtr(obj, pptr, type, 0)
  81#define SWIG_NewFunctionPtrObj(ptr, type)               SWIG_NewPointerObj(ptr, type, 0)
  82
  83#define SWIG_ConvertMember(obj, ptr, sz, ty)            SWIG_Octave_ConvertPacked(obj, ptr, sz, ty)
  84#define SWIG_NewMemberObj(ptr, sz, type)                SWIG_Octave_NewPackedObj(ptr, sz, type)
  85
  86#define SWIG_GetModule(clientdata) SWIG_Octave_GetModule(clientdata)
  87#define SWIG_SetModule(clientdata, pointer) SWIG_Octave_SetModule(clientdata,pointer);
  88#define SWIG_MODULE_CLIENTDATA_TYPE void*
  89
  90#define Octave_Error_Occurred() 0
  91#define SWIG_Octave_AddErrorMsg(msg) {;}
  92
  93SWIGRUNTIME swig_module_info *SWIG_Octave_GetModule(void *clientdata);
  94SWIGRUNTIME void SWIG_Octave_SetModule(void *clientdata, swig_module_info *pointer);
  95
  96// For backward compatibility only
  97#define SWIG_POINTER_EXCEPTION  0
  98#define SWIG_arg_fail(arg)      0
  99
 100// Runtime API implementation
 101
 102#include <map>
 103#include <vector>
 104#include <string>
 105
 106typedef octave_value_list(*octave_func) (const octave_value_list &, int);
 107class octave_swig_type;
 108
 109# define SWIG_DIRECTOR_CAST(ARG) dynamic_cast<Swig::Director *>(ARG)
 110
 111namespace Swig {
 112  class Director;
 113
 114  //SWIGRUNTIME void swig_register_director(octave_swig_type *self, void *ptr, Director *d);
 115  SWIGRUNTIME void swig_director_destroyed(octave_swig_type *self, Director *d);
 116  SWIGRUNTIME void swig_director_set_self(Director *d, octave_swig_type *self);
 117
 118  SWIGRUNTIME octave_base_value *swig_value_ref(octave_swig_type *ost);
 119  SWIGRUNTIME octave_swig_type *swig_value_deref(octave_value ov);
 120  SWIGRUNTIME octave_swig_type *swig_value_deref(const octave_base_value &ov);
 121
 122  typedef std::map < void *, Director * > rtdir_map;
 123
 124  SWIGINTERN rtdir_map* get_rtdir_map() {
 125    static swig_module_info *module = 0;
 126    if (!module)
 127      module = SWIG_GetModule(0);
 128    if (!module)
 129      return 0;
 130    if (!module->clientdata)
 131      module->clientdata = new rtdir_map;
 132    return (rtdir_map *) module->clientdata;
 133  }
 134
 135  SWIGINTERNINLINE void set_rtdir(void *vptr, Director *d) {
 136    rtdir_map* rm = get_rtdir_map();
 137    if (rm)
 138      (*rm)[vptr] = d;
 139  }
 140
 141  SWIGINTERNINLINE void erase_rtdir(void *vptr) {
 142    rtdir_map* rm = get_rtdir_map();
 143    if (rm)
 144      (*rm).erase(vptr);
 145  }
 146
 147  SWIGINTERNINLINE Director *get_rtdir(void *vptr) {
 148    rtdir_map* rm = get_rtdir_map();
 149    if (!rm)
 150      return 0;
 151    rtdir_map::const_iterator pos = rm->find(vptr);
 152    Director *rtdir = (pos != rm->end())? pos->second : 0;
 153    return rtdir;
 154  }
 155}
 156
 157  struct swig_octave_member {
 158    const char *name;
 159    octave_func method;
 160    octave_func get_method;
 161    octave_func set_method;
 162    int flags;			// 1 static, 2 global
 163    const char *doc;
 164    bool is_static() const {
 165      return flags &1;
 166    } bool is_global() const {
 167      return flags &2;
 168    }
 169  };
 170
 171  struct swig_octave_class {
 172    const char *name;
 173    swig_type_info **type;
 174    int director;
 175    octave_func constructor;
 176    const char *constructor_doc;
 177    octave_func destructor;
 178    const swig_octave_member *members;
 179    const char **base_names;
 180    const swig_type_info **base;
 181  };
 182
 183  // octave_swig_type plays the role of both the shadow class and the class 
 184  // representation within Octave, since there is no support for classes.
 185  //
 186  // These should really be decoupled, with the class support added to Octave
 187  // and the shadow class given by an m-file script. That would dramatically 
 188  // reduce the runtime complexity, and be more in line w/ other modules.
 189
 190  class octave_swig_type:public octave_base_value {
 191    struct cpp_ptr {
 192      void *ptr;
 193      bool destroyed;
 194      cpp_ptr(void *_ptr):ptr(_ptr), destroyed(false) {
 195      }};
 196    typedef std::pair < const swig_type_info *, cpp_ptr > type_ptr_pair;
 197
 198    mutable swig_module_info *module;
 199
 200    const swig_type_info *construct_type;	// type of special type object
 201    std::vector < type_ptr_pair > types;	// our c++ base classes
 202    int own;			// whether we call c++ destructors when we die
 203
 204    typedef std::pair < const swig_octave_member *, octave_value > member_value_pair;
 205    typedef std::map < std::string, member_value_pair > member_map;
 206    member_map members;
 207    bool always_static;
 208
 209    const swig_octave_member *find_member(const swig_type_info *type, const std::string &name) {
 210      if (!type->clientdata)
 211	return 0;
 212      swig_octave_class *c = (swig_octave_class *) type->clientdata;
 213      const swig_octave_member *m;
 214      for (m = c->members; m->name; ++m)
 215	if (m->name == name)
 216	  return m;
 217      for (int j = 0; c->base_names[j]; ++j) {
 218	if (!c->base[j]) {
 219	  if (!module)
 220	    module = SWIG_GetModule(0);
 221	  assert(module);
 222	  c->base[j] = SWIG_MangledTypeQueryModule(module, module, c->base_names[j]);
 223	}
 224	if (!c->base[j])
 225	  return 0;
 226	if ((m = find_member(c->base[j], name)))
 227	  return m;
 228      }
 229      return 0;
 230    }
 231
 232    member_value_pair *find_member(const std::string &name, bool insert_if_not_found) {
 233      member_map::iterator it = members.find(name);
 234      if (it != members.end())
 235	return &it->second;
 236      const swig_octave_member *m;
 237      for (unsigned int j = 0; j < types.size(); ++j)
 238	if ((m = find_member(types[j].first, name)))
 239	  return &members.insert(std::make_pair(name, std::make_pair(m, octave_value()))).first->second;
 240      if (!insert_if_not_found)
 241	return 0;
 242      return &members[name];
 243    }
 244
 245    const swig_type_info *find_base(const std::string &name, const swig_type_info *base) {
 246      if (!base) {
 247	for (unsigned int j = 0; j < types.size(); ++j) {
 248	  assert(types[j].first->clientdata);
 249	  swig_octave_class *cj = (swig_octave_class *) types[j].first->clientdata;
 250	  if (cj->name == name)
 251	    return types[j].first;
 252	}
 253	return 0;
 254      }
 255      assert(base->clientdata);
 256      swig_octave_class *c = (swig_octave_class *) base->clientdata;
 257      for (int j = 0; c->base_names[j]; ++j) {
 258	if (!c->base[j]) {
 259	  if (!module)
 260	    module = SWIG_GetModule(0);
 261	  assert(module);
 262	  c->base[j] = SWIG_MangledTypeQueryModule(module, module, c->base_names[j]);
 263	}
 264	if (!c->base[j])
 265	  return 0;
 266	assert(c->base[j]->clientdata);
 267	swig_octave_class *cj = (swig_octave_class *) c->base[j]->clientdata;
 268	if (cj->name == name)
 269	  return c->base[j];
 270      }
 271      return 0;
 272    }
 273
 274    void load_members(const swig_octave_class* c,member_map& out) const {
 275      for (const swig_octave_member *m = c->members; m->name; ++m) {
 276	if (out.find(m->name) == out.end())
 277	  out.insert(std::make_pair(m->name, std::make_pair(m, octave_value())));
 278      }
 279      for (int j = 0; c->base_names[j]; ++j) {
 280	if (!c->base[j]) {
 281	  if (!module)
 282	    module = SWIG_GetModule(0);
 283	  assert(module);
 284	  c->base[j] = SWIG_MangledTypeQueryModule(module, module, c->base_names[j]);
 285	}
 286	if (!c->base[j])
 287	  continue;
 288	assert(c->base[j]->clientdata);
 289	const swig_octave_class *cj =
 290	  (const swig_octave_class *) c->base[j]->clientdata;
 291	load_members(cj,out);
 292      }
 293    }
 294
 295    void load_members(member_map& out) const {
 296      out=members;
 297      for (unsigned int j = 0; j < types.size(); ++j)
 298	if (types[j].first->clientdata)
 299	  load_members((const swig_octave_class *) types[j].first->clientdata, out);
 300    }
 301
 302    octave_value_list member_invoke(member_value_pair *m, const octave_value_list &args, int nargout) {
 303      if (m->second.is_defined())
 304	return m->second.subsref("(", std::list < octave_value_list > (1, args), nargout);
 305      else if (m->first && m->first->method)
 306	return m->first->method(args, nargout);
 307      error("member not defined or not invocable");
 308      return octave_value_list();
 309    }
 310
 311    bool dispatch_unary_op(const std::string &symbol, octave_value &ret) {
 312      member_value_pair *m = find_member(symbol, false);
 313      if (!m || m->first->is_static() || m->first->is_global())
 314	return false;
 315      octave_value_list args;
 316      args.append(as_value());
 317      octave_value_list argout(member_invoke(m, args, 1));
 318      if (argout.length() < 1)
 319	return false;
 320      ret = argout(0);
 321      return true;
 322    }
 323
 324    bool dispatch_binary_op(const std::string &symbol, const octave_base_value &rhs, octave_value &ret) {
 325      member_value_pair *m = find_member(symbol, false);
 326      if (!m || m->first->is_static() || m->first->is_global())
 327	return false;
 328      octave_value_list args;
 329      args.append(as_value());
 330      args.append(make_value_hack(rhs));
 331      octave_value_list argout(member_invoke(m, args, 1));
 332      if (argout.length() < 1)
 333	return false;
 334      ret = argout(0);
 335      return true;
 336    }
 337
 338    bool dispatch_index_op(const std::string &symbol, const octave_value_list &rhs, octave_value_list &ret) {
 339      member_value_pair *m = find_member(symbol, false);
 340      if (!m || m->first->is_static() || m->first->is_global())
 341	return false;
 342      octave_value_list args;
 343      args.append(as_value());
 344      args.append(rhs);
 345      octave_value_list argout(member_invoke(m, args, 1));
 346      if (argout.length() >= 1)
 347	ret = argout(0);
 348      return true;
 349    }
 350
 351    octave_value_list member_deref(member_value_pair *m, const octave_value_list &args) {
 352      if (m->second.is_defined())
 353	return m->second;
 354      else if (m->first) {
 355	if (m->first->get_method)
 356	  return m->first->get_method(args, 1);
 357	else if (m->first->method)
 358	  return octave_value(new octave_builtin(m->first->method));
 359      }
 360      error("undefined member");
 361      return octave_value_list();
 362    }
 363
 364    static octave_value make_value_hack(const octave_base_value &x) {
 365      ((octave_swig_type &) x).count++;
 366      return octave_value((octave_base_value *) &x);
 367    }
 368
 369    octave_swig_type(const octave_swig_type &x);
 370    octave_swig_type &operator=(const octave_swig_type &rhs);
 371  public:
 372
 373    octave_swig_type(void *_ptr = 0, const swig_type_info *_type = 0, int _own = 0,
 374		     bool _always_static = false)
 375      :	module(0), construct_type(_ptr ? 0 : _type), own(_own), 
 376      always_static(_always_static) {
 377      if (_type || _ptr)
 378	types.push_back(std::make_pair(_type, _ptr));
 379      if (_ptr) {
 380	Swig::Director *d = Swig::get_rtdir(_ptr);
 381	if (d)
 382	  Swig::swig_director_set_self(d, this);
 383      }
 384    }
 385
 386    ~octave_swig_type() {
 387      if (own) {
 388	++count;
 389	for (unsigned int j = 0; j < types.size(); ++j) {
 390	  if (!types[j].first || !types[j].first->clientdata)
 391	    continue;
 392	  swig_octave_class *c = (swig_octave_class *) types[j].first->clientdata;
 393	  if (c->destructor && !types[j].second.destroyed && types[j].second.ptr) {
 394	    c->destructor(as_value(), 0);
 395	  }
 396	}
 397      }
 398      for (unsigned int j = 0; j < types.size(); ++j)
 399	Swig::erase_rtdir(types[j].second.ptr);
 400    }
 401
 402    dim_vector dims(void) const {
 403      octave_swig_type *nc_this = const_cast < octave_swig_type *>(this);
 404      
 405      // Find the __dims__ method of this object
 406      member_value_pair *m = nc_this->find_member("__dims__", false);
 407
 408      if (!m) return dim_vector(1,1);
 409      
 410      // Call the __dims__ method of this object
 411      octave_value_list inarg;
 412      inarg.append(nc_this->as_value());
 413      octave_value_list outarg = nc_this->member_invoke(m, inarg, 1);
 414
 415      // __dims__ should return (at least) one output argument
 416      if (outarg.length() < 1) return dim_vector(1,1);
 417      
 418      octave_value & out = outarg(0);
 419
 420      // Return value should be cell or matrix of integers
 421      if (out.is_cell()) {
 422        const Cell & c=out.cell_value();
 423        int ndim = c.rows();
 424        if (ndim==1 && c.columns()!=1) ndim = c.columns();
 425
 426        dim_vector d;
 427        d.resize(ndim);
 428
 429        // Fill in dim_vector 
 430        for (int k=0;k<ndim;k++) {
 431          const octave_value& obj = c(k);
 432          d.elem(k) = obj.int_value();
 433          
 434          // __dims__ should return a cell filled with integers
 435          if (error_state) return dim_vector(1,1);
 436        }
 437        return d;
 438      } else if (out.is_matrix_type() || out.is_real_nd_array() || out.is_numeric_type() ) {
 439        if (out.rows()==1 || out.columns()==1) {
 440           Array<int> a = out.int_vector_value();
 441           if (error_state) return dim_vector(1,1);
 442           dim_vector d;
 443           d.resize(a.numel());
 444           for (int k=0;k<a.numel();k++) {
 445              d.elem(k) = a(k);
 446           }
 447           return d;
 448        } else {
 449          return dim_vector(1,1);
 450        }
 451      } else {
 452        return dim_vector(1,1);
 453      }
 454    }
 455
 456    octave_value as_value() {
 457      ++count;
 458      return Swig::swig_value_ref(this);
 459    }
 460
 461    void incref() {
 462      ++count;
 463    }
 464
 465    void decref() {
 466      if (!--count)
 467	delete this;
 468    }
 469
 470    long swig_this() const {
 471      if (!types.size())
 472	return (long) this;
 473      return (long) types[0].second.ptr;
 474    }
 475    const char* help_text() const {
 476      if (!types.size())
 477	return 0;
 478      if (!types[0].first->clientdata)
 479	return 0;
 480      swig_octave_class *c = (swig_octave_class *) types[0].first->clientdata;
 481      return c->constructor_doc;
 482    }
 483
 484    std::string swig_type_name() const {
 485      // * need some way to manually name subclasses.
 486      // * eg optional first arg to subclass(), or named_subclass()
 487      std::string ret;
 488      for (unsigned int j = 0; j < types.size(); ++j) {
 489	if (j)
 490	  ret += "_";
 491	if (types[j].first->clientdata) {
 492	  swig_octave_class *c = (swig_octave_class *) types[j].first->clientdata;
 493	  ret += c->name;
 494	} else
 495	  ret += types[j].first->name;
 496      }
 497      return ret;
 498    }
 499
 500    void merge(octave_swig_type &rhs) {
 501      rhs.own = 0;
 502      for (unsigned int j = 0; j < rhs.types.size(); ++j) {
 503	assert(!rhs.types[j].second.destroyed);
 504	Swig::Director *d = Swig::get_rtdir(rhs.types[j].second.ptr);
 505	if (d)
 506	  Swig::swig_director_set_self(d, this);
 507      }
 508      types.insert(types.end(), rhs.types.begin(), rhs.types.end());
 509      members.insert(rhs.members.begin(), rhs.members.end());
 510      rhs.types.clear();
 511      rhs.members.clear();
 512    }
 513
 514    void install_global(bool global_load) {
 515      for (member_map::const_iterator it = members.begin(); it != members.end(); ++it) {
 516        bool is_global_op = (it->first.substr(0, strlen(SWIG_op_prefix)) == SWIG_op_prefix);
 517        bool is_func_defined = (it->second.first && it->second.first->method);
 518	if (is_func_defined && (is_global_op || global_load)) {
 519	  install_builtin_function(it->second.first->method, it->first,
 520				   it->second.first->doc ? it->second.first->doc : std::string());
 521        }
 522        octave_value global_val = is_global_op ? make_fcn_handle(it->first) : it->second.second;
 523	if (global_val.is_defined() && (is_global_op || global_load)) {
 524#if OCTAVE_API_VERSION_NUMBER<37
 525	  link_to_global_variable(curr_sym_tab->lookup(it->first, true));
 526#else 
 527	  symbol_table::varref(it->first);
 528	  symbol_table::mark_global(it->first);
 529#endif
 530	  set_global_value(it->first, global_val);
 531	  
 532#if OCTAVE_API_VERSION_NUMBER<37
 533	  octave_swig_type *ost = Swig::swig_value_deref(global_val);
 534	  if (ost) {
 535	    const char* h = ost->help_text();
 536	    if (h) {
 537	      symbol_record *sr = global_sym_tab->lookup (it->first, true);
 538	      sr->document(h);
 539	    }
 540	  }
 541#endif
 542	}
 543      }
 544    }
 545
 546    void *cast(swig_type_info *type, int *_own, int flags) {
 547      if (_own)
 548	*_own = own;
 549      if (flags &SWIG_POINTER_DISOWN)
 550	own = 0;
 551      if (!type && types.size())
 552	return types[0].second.ptr;
 553      for (unsigned int j = 0; j < types.size(); ++j)
 554	if (type == types[j].first)
 555	  return types[j].second.ptr;
 556      for (unsigned int j = 0; j < types.size(); ++j) {
 557	swig_cast_info *tc = SWIG_TypeCheck(types[j].first->name, type);
 558	if (!tc)
 559	  continue;
 560	int newmemory = 0;
 561	void *vptr = SWIG_TypeCast(tc, types[j].second.ptr, &newmemory);
 562	assert(!newmemory);	// newmemory handling not yet implemented
 563	return vptr;
 564      }
 565      return 0;
 566    }
 567
 568    bool is_owned() const {
 569      return own;
 570    }
 571
 572    void director_destroyed(Swig::Director *d) {
 573      bool found = false;
 574      for (unsigned int j = 0; j < types.size(); ++j) {
 575	Swig::Director *dj = Swig::get_rtdir(types[j].second.ptr);
 576	if (dj == d) {
 577	  types[j].second.destroyed = true;
 578	  found = true;
 579	}
 580      }
 581      assert(found);
 582    }
 583
 584    void assign(const std::string &name, const octave_value &ov) {
 585      members[name] = std::make_pair((const swig_octave_member *) 0, ov);
 586    }
 587
 588    void assign(const std::string &name, const swig_octave_member *m) {
 589      members[name] = std::make_pair(m, octave_value());
 590    }
 591
 592    octave_base_value *clone() const {
 593      // pass-by-value is probably not desired, and is harder;
 594      // requires calling copy constructors of contained types etc.
 595      assert(0);
 596      *(int *) 0 = 0;
 597      return 0;
 598    }
 599
 600    octave_base_value *empty_clone() const {
 601      return new octave_swig_type();
 602    }
 603
 604    bool is_defined() const {
 605      return true;
 606    }
 607
 608    virtual bool is_map() const {
 609      return true;
 610    }
 611
 612    virtual octave_value subsref(const std::string &ops, const std::list < octave_value_list > &idx) {
 613      octave_value_list ovl = subsref(ops, idx, 1);
 614      return ovl.length()? ovl(0) : octave_value();
 615    }
 616
 617    virtual octave_value_list subsref(const std::string &ops, const std::list < octave_value_list > &idx, int nargout) {
 618      assert(ops.size() > 0);
 619      assert(ops.size() == idx.size());
 620
 621      std::list < octave_value_list >::const_iterator idx_it = idx.begin();
 622      int skip = 0;
 623      octave_value_list sub_ovl;
 624
 625      // constructor invocation
 626      if (ops[skip] == '(' && construct_type) {
 627	assert(construct_type->clientdata);
 628	swig_octave_class *c = (swig_octave_class *) construct_type->clientdata;
 629	if (!c->constructor) {
 630	  error("cannot create instance");
 631	  return octave_value_list();
 632	}
 633	octave_value_list args;
 634	if (c->director)
 635	  args.append(Swig::swig_value_ref(new octave_swig_type(this, 0, 0)));
 636	args.append(*idx_it++);
 637	++skip;
 638	sub_ovl = c->constructor(args, nargout);
 639      }
 640      // member dereference or invocation
 641      else if (ops[skip] == '.') {
 642	std::string subname;
 643	const swig_type_info *base = 0;	// eg, a.base.base_cpp_mem
 644	for (;;) {
 645	  octave_value_list subname_ovl(*idx_it++);
 646	  ++skip;
 647	  assert(subname_ovl.length() == 1 && subname_ovl(0).is_string());
 648	  subname = subname_ovl(0).string_value();
 649
 650	  const swig_type_info *next_base = find_base(subname, base);
 651	  if (!next_base || skip >= (int) ops.size() || ops[skip] != '.')
 652	    break;
 653	  base = next_base;
 654	}
 655
 656	member_value_pair tmp, *m = &tmp;
 657	if (!base || !(m->first = find_member(base, subname)))
 658	  m = find_member(subname, false);
 659	if (!m) {
 660	  error("member not found");
 661	  return octave_value_list();
 662	}
 663
 664	octave_value_list args;
 665	if (!always_static &&
 666	    (!m->first || (!m->first->is_static() && !m->first->is_global())))
 667	  args.append(as_value());
 668	if (skip < (int) ops.size() && ops[skip] == '(' && 
 669	    ((m->first && m->first->method) || m->second.is_function() || 
 670	     m->second.is_function_handle())) {
 671	  args.append(*idx_it++);
 672	  ++skip;
 673	  sub_ovl = member_invoke(m, args, nargout);
 674	} else {
 675	  sub_ovl = member_deref(m, args);
 676	}
 677      }
 678      // index operator
 679      else {
 680	if (ops[skip] == '(' || ops[skip] == '{') {
 681	  const char *op_name = ops[skip] == '(' ? "__paren__" : "__brace__";
 682	  octave_value_list args;
 683	  args.append(*idx_it++);
 684	  ++skip;
 685	  if (!dispatch_index_op(op_name, args, sub_ovl)) {
 686	    error("error evaluating index operator");
 687	    return octave_value_list();
 688	  }
 689	} else {
 690	  error("unsupported subsref");
 691	  return octave_value_list();
 692	}
 693      }
 694
 695      if (skip >= (int) ops.size())
 696	return sub_ovl;
 697      if (sub_ovl.length() < 1) {
 698	error("bad subs ref");
 699	return octave_value_list();
 700      }
 701      return sub_ovl(0).next_subsref(nargout, ops, idx, skip);
 702    }
 703
 704    octave_value subsasgn(const std::string &ops, const std::list < octave_value_list > &idx, const octave_value &rhs) {
 705      assert(ops.size() > 0);
 706      assert(ops.size() == idx.size());
 707
 708      std::list < octave_value_list >::const_iterator idx_it = idx.begin();
 709      int skip = 0;
 710
 711      if (ops.size() > 1) {
 712	std::list < octave_value_list >::const_iterator last = idx.end();
 713	--last;
 714	std::list < octave_value_list > next_idx(idx.begin(), last);
 715	octave_value next_ov = subsref(ops.substr(0, ops.size() - 1), next_idx);
 716	next_ov.subsasgn(ops.substr(ops.size() - 1), std::list < octave_value_list > (1, *last), rhs);
 717      }
 718
 719      else if (ops[skip] == '(' || ops[skip] == '{') {
 720	const char *op_name = ops[skip] == '(' ? "__paren_asgn__" : "__brace_asgn__";
 721	member_value_pair *m = find_member(op_name, false);
 722	if (m) {
 723	  octave_value_list args;
 724	  args.append(as_value());
 725	  args.append(*idx_it);
 726	  args.append(rhs);
 727	  member_invoke(m, args, 1);
 728	} else
 729	  error("%s member not found", op_name);
 730      }
 731
 732      else if (ops[skip] == '.') {
 733	octave_value_list subname_ovl(*idx_it++);
 734	++skip;
 735	assert(subname_ovl.length() == 1 &&subname_ovl(0).is_string());
 736	std::string subname = subname_ovl(0).string_value();
 737
 738	member_value_pair *m = find_member(subname, true);
 739	if (!m->first || !m->first->set_method) {
 740	  m->first = 0;
 741	  m->second = rhs;
 742	} else if (m->first->set_method) {
 743	  octave_value_list args;
 744	  if (!m->first->is_static() && !m->first->is_global())
 745	    args.append(as_value());
 746	  args.append(rhs);
 747	  m->first->set_method(args, 1);
 748	} else
 749	  error("member not assignable");
 750      } else
 751	error("unsupported subsasgn");
 752
 753      return as_value();
 754    }
 755
 756    virtual bool is_object() const {
 757      return true;
 758    }
 759
 760    virtual bool is_string() const {
 761      octave_swig_type *nc_this = const_cast < octave_swig_type *>(this);
 762      return !!nc_this->find_member("__str__", false);
 763    }
 764
 765    virtual std::string string_value(bool force = false) const {
 766      octave_swig_type *nc_this = const_cast < octave_swig_type *>(this);
 767      member_value_pair *m = nc_this->find_member("__str__", false);
 768      if (!m) {
 769	error("__str__ method not defined");
 770	return std::string();
 771      }
 772      octave_value_list outarg = nc_this->member_invoke(m, octave_value_list(nc_this->as_value()), 1);
 773      if (outarg.length() < 1 || !outarg(0).is_string()) {
 774	error("__str__ method did not return a string");
 775	return std::string();
 776      }
 777      return outarg(0).string_value();
 778    }
 779
 780#if OCTAVE_API_VERSION_NUMBER >= 40
 781    virtual octave_map map_value() const {
 782      return octave_map();
 783    }
 784#else
 785    virtual Octave_map map_value() const {
 786      return Octave_map();
 787    }
 788#endif
 789
 790    virtual string_vector map_keys() const {
 791      member_map tmp;
 792      load_members(tmp);
 793
 794      string_vector keys(tmp.size());
 795      int k = 0;
 796      for (member_map::iterator it = tmp.begin(); it != tmp.end(); ++it)
 797	keys(k++) = it->first;
 798
 799      return keys;
 800    }
 801
 802    virtual bool save_ascii (std::ostream& os) {
 803      return true;
 804    }
 805
 806    virtual bool load_ascii (std::istream& is) {
 807      return true;
 808    }
 809
 810    virtual bool save_binary (std::ostream& os, bool& save_as_floats) {
 811      return true;
 812    }
 813
 814    virtual bool load_binary (std::istream& is, bool swap, 
 815			      oct_mach_info::float_format fmt) {
 816      return true;
 817    }
 818
 819#if defined (HAVE_HDF5)
 820    virtual bool
 821      save_hdf5 (hid_t loc_id, const char *name, bool save_as_floats) {
 822      return true;
 823    }
 824
 825    virtual bool
 826      load_hdf5 (hid_t loc_id, const char *name, bool have_h5giterate_bug) {
 827      return true;
 828    }
 829#endif
 830
 831    virtual octave_value convert_to_str(bool pad = false, bool force = false, char type = '"') const {
 832      return string_value();
 833    }
 834
 835    virtual octave_value convert_to_str_internal(bool pad, bool force, char type) const {
 836      return string_value();
 837    }
 838
 839    static bool dispatch_global_op(const std::string &symbol, const octave_value_list &args, octave_value &ret) {
 840      // we assume that SWIG_op_prefix-prefixed functions are installed in global namespace
 841      // (rather than any module namespace).
 842
 843      octave_value fcn = get_global_value(symbol, true);
 844      if (!fcn.is_function() && !fcn.is_function_handle())
 845	return false;
 846      ret = fcn.subsref("(", std::list < octave_value_list > (1, args), 1);
 847      return true;
 848    }
 849
 850    static octave_value dispatch_unary_op(const octave_base_value &x, const char *op_name) {
 851      octave_swig_type *ost = Swig::swig_value_deref(x);
 852      assert(ost);
 853
 854      octave_value ret;
 855      if (ost->dispatch_unary_op(std::string("__") + op_name + std::string("__"), ret))
 856	return ret;
 857      std::string symbol = SWIG_op_prefix + ost->swig_type_name() + "_" + op_name;
 858      octave_value_list args;
 859      args.append(make_value_hack(x));
 860      if (dispatch_global_op(symbol, args, ret))
 861	return ret;
 862
 863      error("could not dispatch unary operator");
 864      return octave_value();
 865    }
 866
 867    static octave_value dispatch_binary_op(const octave_base_value &lhs, const octave_base_value &rhs, const char *op_name) {
 868      octave_swig_type *lhs_ost = Swig::swig_value_deref(lhs);
 869      octave_swig_type *rhs_ost = Swig::swig_value_deref(rhs);
 870
 871      octave_value ret;
 872      if (lhs_ost && lhs_ost->dispatch_binary_op(std::string("__") + op_name + std::string("__"), rhs, ret))
 873	return ret;
 874      if (rhs_ost) {
 875        if (strlen(op_name) == 2  && (op_name[1] == 't' || op_name[1] == 'e')) {
 876          if (op_name[0] == 'l' && rhs_ost->dispatch_binary_op(std::string("__g") + op_name[1] + std::string("__"), lhs, ret))
 877            return ret;
 878          if (op_name[0] == 'g' && rhs_ost->dispatch_binary_op(std::string("__l") + op_name[1] + std::string("__"), lhs, ret))
 879            return ret;
 880        }
 881        if (rhs_ost->dispatch_binary_op(std::string("__r") + op_name + std::string("__"), lhs, ret))
 882          return ret;
 883      }
 884
 885      std::string symbol;
 886      octave_value_list args;
 887      args.append(make_value_hack(lhs));
 888      args.append(make_value_hack(rhs));
 889
 890      symbol = SWIG_op_prefix;
 891      symbol += lhs_ost ? lhs_ost->swig_type_name() : lhs.type_name();
 892      symbol += "_";
 893      symbol += op_name;
 894      symbol += "_";
 895      symbol += rhs_ost ? rhs_ost->swig_type_name() : rhs.type_name();
 896      if (dispatch_global_op(symbol, args, ret))
 897	return ret;
 898
 899      symbol = SWIG_op_prefix;
 900      symbol += lhs_ost ? lhs_ost->swig_type_name() : lhs.type_name();
 901      symbol += "_";
 902      symbol += op_name;
 903      symbol += "_";
 904      symbol += "any";
 905      if (dispatch_global_op(symbol, args, ret))
 906	return ret;
 907
 908      symbol = SWIG_op_prefix;
 909      symbol += "any";
 910      symbol += "_";
 911      symbol += op_name;
 912      symbol += "_";
 913      symbol += rhs_ost ? rhs_ost->swig_type_name() : rhs.type_name();
 914      if (dispatch_global_op(symbol, args, ret))
 915	return ret;
 916
 917      error("could not dispatch binary operator");
 918      return octave_value();
 919    }
 920
 921    void print(std::ostream &os, bool pr_as_read_syntax = false) const {
 922      if (is_string()) {
 923	os << string_value();
 924	return;
 925      }
 926
 927      member_map tmp;
 928      load_members(tmp);
 929
 930      indent(os);
 931      os << "{"; newline(os);
 932      increment_indent_level();
 933      for (unsigned int j = 0; j < types.size(); ++j) {
 934        indent(os);
 935	if (types[j].first->clientdata) {
 936	  const swig_octave_class *c = (const swig_octave_class *) types[j].first->clientdata;
 937	  os << c->name << ", ptr = " << types[j].second.ptr; newline(os);
 938	} else {
 939	  os << types[j].first->name << ", ptr = " << types[j].second.ptr; newline(os);
 940	}
 941      }
 942      for (member_map::const_iterator it = tmp.begin(); it != tmp.end(); ++it) {
 943        indent(os);
 944	if (it->second.first) {
 945	  const char *objtype = it->second.first->method ? "method" : "variable";
 946	  const char *modifier = (it->second.first->flags &1) ? "static " : (it->second.first->flags &2) ? "global " : "";
 947	  os << it->second.first->name << " (" << modifier << objtype << ")"; newline(os);
 948	  assert(it->second.first->name == it->first);
 949	} else {
 950	  os << it->first; newline(os);
 951	}
 952      }
 953      decrement_indent_level();
 954      indent(os);
 955      os << "}"; newline(os);
 956    }
 957  };
 958
 959  // Octave tries hard to preserve pass-by-value semantics. Eg, assignments
 960  // will call clone() via make_unique() if there is more than one outstanding 
 961  // reference to the lhs, and forces the clone's reference count to 1 
 962  // (so you can't just increment your own count and return this).
 963  //
 964  // One way to fix this (without modifying Octave) is to add a level of
 965  // indirection such that clone copies ref-counted pointer and we keep 
 966  // pass-by-ref semantics (which are more natural/expected for C++ bindings).
 967  //
 968  // Supporting both pass-by-{ref,value} and toggling via %feature/option 
 969  // might be nice.
 970
 971  class octave_swig_ref:public octave_base_value {
 972    octave_swig_type *ptr;
 973  public:
 974    octave_swig_ref(octave_swig_type *_ptr = 0)
 975      :ptr(_ptr) { }
 976
 977    ~octave_swig_ref()
 978      { if (ptr) ptr->decref(); }
 979
 980    octave_swig_type *get_ptr() const
 981      { return ptr; }
 982
 983    octave_base_value *clone() const
 984      { if (ptr) ptr->incref(); return new octave_swig_ref(ptr); }
 985
 986    octave_base_value *empty_clone() const
 987      { return new octave_swig_ref(0); }
 988
 989    dim_vector dims(void) const 
 990      { return ptr->dims(); }
 991
 992    bool is_defined() const
 993      { return ptr->is_defined(); }
 994
 995    virtual bool is_map() const 
 996      { return ptr->is_map(); }
 997
 998    virtual octave_value subsref(const std::string &ops, const std::list < octave_value_list > &idx) 
 999      { return ptr->subsref(ops, idx); }
1000
1001    virtual octave_value_list subsref(const std::string &ops, const std::list < octave_value_list > &idx, int nargout)
1002      { return ptr->subsref(ops, idx, nargout); }
1003
1004    octave_value subsasgn(const std::string &ops, const std::list < octave_value_list > &idx, const octave_value &rhs)
1005      { return ptr->subsasgn(ops, idx, rhs); }
1006
1007    virtual bool is_object() const 
1008      { return ptr->is_object(); }
1009
1010    virtual bool is_string() const 
1011      { return ptr->is_string(); }
1012
1013    virtual std::string string_value(bool force = false) const 
1014      { return ptr->string_value(force); }
1015
1016#if OCTAVE_API_VERSION_NUMBER >= 40
1017    virtual octave_map map_value() const
1018      { return ptr->map_value(); }
1019#else
1020    virtual Octave_map map_value() const
1021      { return ptr->map_value(); }
1022#endif
1023
1024    virtual string_vector map_keys() const
1025      { return ptr->map_keys(); }
1026
1027    virtual bool save_ascii (std::ostream& os)
1028      { return ptr->save_ascii(os); }
1029
1030    virtual bool load_ascii (std::istream& is)
1031      { return ptr->load_ascii(is); }
1032
1033    virtual bool save_binary (std::ostream& os, bool& save_as_floats)
1034      { return ptr->save_binary(os, save_as_floats); }
1035
1036    virtual bool load_binary (std::istream& is, bool swap, 
1037			      oct_mach_info::float_format fmt)
1038      { return ptr->load_binary(is, swap, fmt); }
1039
1040#if defined (HAVE_HDF5)
1041    virtual bool
1042      save_hdf5 (hid_t loc_id, const char *name, bool save_as_floats)
1043      { return ptr->save_hdf5(loc_id, name, save_as_floats); }
1044
1045    virtual bool
1046      load_hdf5 (hid_t loc_id, const char *name, bool have_h5giterate_bug)
1047      { return ptr->load_hdf5(loc_id, name, have_h5giterate_bug); }
1048#endif
1049
1050    virtual octave_value convert_to_str(bool pad = false, bool force = false, char type = '"') const
1051      { return ptr->convert_to_str(pad, force, type); }
1052
1053    virtual octave_value convert_to_str_internal(bool pad, bool force, char type) const
1054      { return ptr->convert_to_str_internal(pad, force, type); }
1055
1056    void print(std::ostream &os, bool pr_as_read_syntax = false) const
1057      { return ptr->print(os, pr_as_read_syntax); }
1058
1059  private:
1060    DECLARE_OCTAVE_ALLOCATOR;
1061    DECLARE_OV_TYPEID_FUNCTIONS_AND_DATA;
1062  };
1063  DEFINE_OCTAVE_ALLOCATOR(octave_swig_ref);
1064  DEFINE_OV_TYPEID_FUNCTIONS_AND_DATA(octave_swig_ref, "swig_ref", "swig_ref");
1065
1066  class octave_swig_packed:public octave_base_value {
1067    swig_type_info *type;
1068    std::vector < char > buf;
1069  public:
1070
1071    octave_swig_packed(swig_type_info *_type = 0, const void *_buf = 0, size_t _buf_len = 0)
1072      :	type(_type), buf((const char*)_buf, (const char*)_buf + _buf_len) {
1073    }
1074
1075    bool copy(swig_type_info *outtype, void *ptr, size_t sz) const {
1076      if (outtype && outtype != type)
1077	return false;
1078      assert(sz <= buf.size());
1079      std::copy(buf.begin(), buf.begin()+sz, (char*)ptr);
1080      return true;
1081    }
1082
1083    octave_base_value *clone() const {
1084      return new octave_swig_packed(*this);
1085    }
1086
1087    octave_base_value *empty_clone() const {
1088      return new octave_swig_packed();
1089    }
1090
1091    bool is_defined() const {
1092      return true;
1093    }
1094
1095    void print(std::ostream &os, bool pr_as_read_syntax = false) const {
1096      indent(os);
1097      os << "swig packed type: name = " << (type ? type->name : std::string()) << ", len = " << buf.size(); newline(os);
1098    }
1099
1100
1101    virtual bool save_ascii (std::ostream& os) {
1102      return true;
1103    }
1104
1105    virtual bool load_ascii (std::istream& is) {
1106      return true;
1107    }
1108
1109    virtual bool save_binary (std::ostream& os, bool& save_as_floats) {
1110      return true;
1111    }
1112
1113    virtual bool load_binary (std::istream& is, bool swap, 
1114			      oct_mach_info::float_format fmt) {
1115      return true;
1116    }
1117
1118#if defined (HAVE_HDF5)
1119    virtual bool
1120      save_hdf5 (hid_t loc_id, const char *name, bool save_as_floats) {
1121      return true;
1122    }
1123
1124    virtual bool
1125      load_hdf5 (hid_t loc_id, const char *name, bool have_h5giterate_bug) {
1126      return true;
1127    }
1128#endif
1129
1130  private:
1131    DECLARE_OCTAVE_ALLOCATOR;
1132    DECLARE_OV_TYPEID_FUNCTIONS_AND_DATA;
1133  };
1134  DEFINE_OCTAVE_ALLOCATOR(octave_swig_packed);
1135  DEFINE_OV_TYPEID_FUNCTIONS_AND_DATA(octave_swig_packed, "swig_packed", "swig_packed");
1136
1137  static octave_value_list octave_set_immutable(const octave_value_list &args, int nargout) {
1138    error("attempt to set immutable member variable");
1139    return octave_value_list();
1140  }
1141
1142  struct octave_value_ref {
1143    const octave_value_list &ovl;
1144    int j;
1145
1146    octave_value_ref(const octave_value_list &_ovl, int _j)
1147      :ovl(_ovl), j(_j) { }
1148
1149    operator  octave_value() const {
1150      return ovl(j);
1151    }
1152
1153    octave_value operator*() const {
1154      return ovl(j);
1155    }
1156  };
1157
1158  octave_value_list swig_subclass(const octave_value_list &args, int nargout) {
1159    octave_swig_type *top = new octave_swig_type;
1160    for (int j = 0; j < args.length(); ++j) {
1161      if (args(j).type_id() == octave_swig_ref::static_type_id()) {
1162	octave_swig_ref *osr = static_cast < octave_swig_ref *>(args(j).internal_rep());
1163	octave_swig_type *ost = osr->get_ptr();
1164	if (!ost->is_owned()) {
1165	  error("cannot subclass object not constructed on octave side");
1166	  return octave_value_list();
1167	}
1168	top->merge(*ost);
1169      } else if (args(j).is_function_handle()) {
1170	top->assign(args(j).fcn_handle_value()->fcn_name(), args(j));
1171      } else if (args(j).is_string()) {
1172	if (j + 1 >= args.length()) {
1173	  error("member assignments must be of string,value form");
1174	  return octave_value_list();
1175	}
1176	top->assign(args(j).string_value(), args(j + 1));
1177	++j;
1178      } else {
1179	error("invalid arguments to subclass");
1180	return octave_value_list();
1181      }
1182    }
1183    return octave_value(Swig::swig_value_ref(top));
1184  }
1185
1186  octave_value_list swig_type(const octave_value_list &args, int nargout) {
1187    if (args.length() != 1) {
1188      error("swig_typeinfo must be called with only a single object");
1189      return octave_value_list();
1190    }
1191    octave_swig_type *ost = Swig::swig_value_deref(args(0));
1192    if (!ost) {
1193      error("object is not a swig_ref");
1194      return octave_value_list();
1195    }
1196    return octave_value(ost->swig_type_name());
1197  }
1198
1199  octave_value_list swig_typequery(const octave_value_list &args, int nargout) {
1200    if (args.length() != 1 || !args(0).is_string()) {
1201      error("swig_typeinfo must be called with single string argument");
1202      return octave_value_list();
1203    }
1204    swig_module_info *module = SWIG_GetModule(0);
1205    swig_type_info *type = SWIG_TypeQueryModule(module, module, args(0).string_value().c_str());
1206    if (!type)
1207      return octave_value("<unknown>");
1208    return octave_value(type->name);
1209  }
1210
1211  octave_value_list swig_this(const octave_value_list &args, int nargout) {
1212    if (args.length() != 1) {
1213      error("swig_typeinfo must be called with only a single object");
1214      return octave_value_list();
1215    }
1216    if (args(0).is_matrix_type() && args(0).rows() == 0 && args(0).columns() == 0)
1217      return octave_value(octave_uint64(0));
1218    octave_swig_type *ost = Swig::swig_value_deref(args(0));
1219    if (!ost) {
1220      error("object is not a swig_ref");
1221      return octave_value_list();
1222    }
1223    return octave_value(octave_uint64((unsigned long long) ost->swig_this()));
1224  }
1225
1226#define SWIG_DIRECTORS
1227
1228namespace Swig {
1229  class Director {
1230    octave_swig_type *self;
1231    bool swig_disowned;
1232
1233    Director(const Director &x);
1234    Director &operator=(const Director &rhs);
1235  public:
1236
1237    Director(void *vptr):self(0), swig_disowned(false) {
1238      set_rtdir(vptr, this);
1239    }
1240
1241    ~Director() {
1242      swig_director_destroyed(self, this);
1243      if (swig_disowned)
1244	self->decref();
1245    }
1246
1247    void swig_set_self(octave_swig_type *new_self) {
1248      assert(!swig_disowned);
1249      self = new_self;
1250    }
1251
1252    octave_swig_type *swig_get_self() const {
1253      return self;
1254    }
1255
1256    void swig_disown() {
1257      if (swig_disowned)
1258	return;
1259      swig_disowned = true;
1260      self->incref();
1261    }
1262  };
1263
1264  struct DirectorTypeMismatchException {
1265    static void raise(const char *msg) {
1266      // ... todo
1267      throw(DirectorTypeMismatchException());
1268    }
1269
1270    static void raise(const octave_value &ov, const char *msg) {
1271      // ... todo
1272      raise(msg);
1273    }
1274  };
1275  struct DirectorPureVirtualException {
1276    static void raise(const char *msg) {
1277      // ... todo
1278      throw(DirectorPureVirtualException());
1279    }
1280
1281    static void raise(const octave_value &ov, const char *msg) {
1282      // ... todo
1283      raise(msg);
1284    }
1285  };
1286
1287}
1288
1289  SWIGRUNTIME void swig_acquire_ownership(void *vptr) {
1290    //  assert(0);
1291    // ... todo
1292  }
1293
1294  SWIGRUNTIME void swig_acquire_ownership_array(void *vptr) {
1295    //  assert(0);
1296    // ... todo
1297  }
1298
1299  SWIGRUNTIME void swig_acquire_ownership_obj(void *vptr, int own) {
1300    //  assert(0);
1301    // ... todo
1302  }
1303
1304  namespace Swig {
1305    SWIGRUNTIME void swig_director_destroyed(octave_swig_type *self, Director *d) {
1306      self->director_destroyed(d);
1307    }
1308
1309    SWIGRUNTIME void swig_director_set_self(Director *d, octave_swig_type *self) {
1310      d->swig_set_self(self);
1311    }
1312
1313    SWIGRUNTIME octave_base_value *swig_value_ref(octave_swig_type *ost) {
1314      return new octave_swig_ref(ost);
1315    }
1316
1317    SWIGRUNTIME octave_swig_type *swig_value_deref(octave_value ov) {
1318      if (ov.is_cell() && ov.rows() == 1 && ov.columns() == 1)
1319	ov = ov.cell_value()(0);
1320      return swig_value_deref(*ov.internal_rep());
1321    }
1322
1323    SWIGRUNTIME octave_swig_type *swig_value_deref(const octave_base_value &ov) {
1324      if (ov.type_id() != octave_swig_ref::static_type_id())
1325	return 0;
1326      const octave_swig_ref *osr = static_cast < const octave_swig_ref *>(&ov);
1327      return osr->get_ptr();
1328    }
1329
1330  }
1331
1332#define swig_unary_op(name) \
1333SWIGRUNTIME octave_value swig_unary_op_##name(const octave_base_value &x) { \
1334  return octave_swig_type::dispatch_unary_op(x,#name); \
1335}
1336#define swig_binary_op(name) \
1337SWIGRUNTIME octave_value swig_binary_op_##name(const octave_base_value&lhs,const octave_base_value &rhs) { \
1338  return octave_swig_type::dispatch_binary_op(lhs,rhs,#name); \
1339}
1340#define swigreg_unary_op(name) \
1341if (!octave_value_typeinfo::lookup_unary_op(octave_value::op_##name,tid)) \
1342octave_value_typeinfo::register_unary_op(octave_value::op_##name,tid,swig_unary_op_##name);
1343#define swigreg_binary_op(name) \
1344if (!octave_value_typeinfo::lookup_binary_op(octave_value::op_##name,tid1,tid2)) \
1345octave_value_typeinfo::register_binary_op(octave_value::op_##name,tid1,tid2,swig_binary_op_##name);
1346
1347  swig_unary_op(not);
1348  swig_unary_op(uplus);
1349  swig_unary_op(uminus);
1350  swig_unary_op(transpose);
1351  swig_unary_op(hermitian);
1352  swig_unary_op(incr);
1353  swig_unary_op(decr);
1354
1355  swig_binary_op(add);
1356  swig_binary_op(sub);
1357  swig_binary_op(mul);
1358  swig_binary_op(div);
1359  swig_binary_op(pow);
1360  swig_binary_op(ldiv);
1361  swig_binary_op(lshift);
1362  swig_binary_op(rshift);
1363  swig_binary_op(lt);
1364  swig_binary_op(le);
1365  swig_binary_op(eq);
1366  swig_binary_op(ge);
1367  swig_binary_op(gt);
1368  swig_binary_op(ne);
1369  swig_binary_op(el_mul);
1370  swig_binary_op(el_div);
1371  swig_binary_op(el_pow);
1372  swig_binary_op(el_ldiv);
1373  swig_binary_op(el_and);
1374  swig_binary_op(el_or);
1375
1376  SWIGRUNTIME void SWIG_InstallUnaryOps(int tid) {
1377    swigreg_unary_op(not);
1378    swigreg_unary_op(uplus);
1379    swigreg_unary_op(uminus);
1380    swigreg_unary_op(transpose);
1381    swigreg_unary_op(hermitian);
1382    swigreg_unary_op(incr);
1383    swigreg_unary_op(decr);
1384  }
1385  SWIGRUNTIME void SWIG_InstallBinaryOps(int tid1, int tid2) {
1386    swigreg_binary_op(add);
1387    swigreg_binary_op(sub);
1388    swigreg_binary_op(mul);
1389    swigreg_binary_op(div);
1390    swigreg_binary_op(pow);
1391    swigreg_binary_op(ldiv);
1392    swigreg_binary_op(lshift);
1393    swigreg_binary_op(rshift);
1394    swigreg_binary_op(lt);
1395    swigreg_binary_op(le);
1396    swigreg_binary_op(eq);
1397    swigreg_binary_op(ge);
1398    swigreg_binary_op(gt);
1399    swigreg_binary_op(ne);
1400    swigreg_binary_op(el_mul);
1401    swigreg_binary_op(el_div);
1402    swigreg_binary_op(el_pow);
1403    swigreg_binary_op(el_ldiv);
1404    swigreg_binary_op(el_and);
1405    swigreg_binary_op(el_or);
1406  }
1407  SWIGRUNTIME void SWIG_InstallOps(int tid) {
1408    // here we assume that tid are conseq integers increasing from zero, and 
1409    // that our tid is the last one. might be better to have explicit string 
1410    // list of types we should bind to, and use lookup_type to resolve their tid.
1411
1412    SWIG_InstallUnaryOps(tid);
1413    SWIG_InstallBinaryOps(tid, tid);
1414    for (int j = 0; j < tid; ++j) {
1415      SWIG_InstallBinaryOps(j, tid);
1416      SWIG_InstallBinaryOps(tid, j);
1417    }
1418  }
1419
1420SWIGRUNTIME octave_value SWIG_Octave_NewPointerObj(void *ptr, swig_type_info *type, int flags) {
1421  int own = (flags &SWIG_POINTER_OWN) ? SWIG_POINTER_OWN : 0;
1422
1423  Swig::Director *d = Swig::get_rtdir(ptr);
1424  if (d && d->swig_get_self())
1425    return d->swig_get_self()->as_value();
1426  return Swig::swig_value_ref(new octave_swig_type(ptr, type, own));
1427}
1428
1429SWIGRUNTIME int SWIG_Octave_ConvertPtrAndOwn(octave_value ov, void **ptr, swig_type_info *type, int flags, int *own) {
1430  if (ov.is_cell() && ov.rows() == 1 && ov.columns() == 1)
1431    ov = ov.cell_value()(0);
1432  if (!ov.is_defined() ||
1433      (ov.is_matrix_type() && ov.rows() == 0 && ov.columns() == 0) ) {
1434    if (ptr)
1435      *ptr = 0;
1436    return SWIG_OK;
1437  }
1438  if (ov.type_id() != octave_swig_ref::static_type_id())
1439    return SWIG_ERROR;
1440  octave_swig_ref *osr = static_cast < octave_swig_ref *>(ov.internal_rep());
1441  octave_swig_type *ost = osr->get_ptr();
1442  void *vptr = ost->cast(type, own, flags);
1443  if (!vptr)
1444    return SWIG_ERROR;
1445  if (ptr)
1446    *ptr = vptr;
1447  return SWIG_OK;
1448}
1449
1450SWIGRUNTIME octave_value SWIG_Octave_NewPackedObj(void *ptr, size_t sz, swig_type_info *type) {
1451  return new octave_swig_packed(type, (char *) ptr, sz);
1452}
1453
1454SWIGRUNTIME int SWIG_Octave_ConvertPacked(const octave_value &ov, void *ptr, size_t sz, swig_type_info *type) {
1455  if (!ov.is_defined())
1456    return SWIG_ERROR;
1457  if (ov.type_id() != octave_swig_packed::static_type_id())
1458    return SWIG_ERROR;
1459  octave_swig_packed *ost = static_cast < octave_swig_packed *>(ov.internal_rep());
1460  return ost->copy(type, (char *) ptr, sz) ? SWIG_OK : SWIG_ERROR;
1461}
1462
1463void SWIG_Octave_SetConstant(octave_swig_type *module_ns, const std::string &name, const octave_value &ov) {
1464  module_ns->assign(name, ov);
1465}
1466
1467SWIGRUNTIME swig_module_info *SWIG_Octave_GetModule(void *clientdata) {
1468  octave_value ov = get_global_value("__SWIG_MODULE__" SWIG_TYPE_TABLE_NAME SWIG_RUNTIME_VERSION, true);
1469  if (!ov.is_defined() ||
1470      ov.type_id() != octave_swig_packed::static_type_id())
1471    return 0;
1472  const octave_swig_packed* osp = 
1473    static_cast < const octave_swig_packed *> (ov.internal_rep());
1474  swig_module_info *pointer = 0;
1475  osp->copy(0, &pointer, sizeof(swig_module_info *));
1476  return pointer;
1477}
1478
1479SWIGRUNTIME void SWIG_Octave_SetModule(void *clientdata, swig_module_info *pointer) {
1480  octave_value ov = new octave_swig_packed(0, &pointer, sizeof(swig_module_info *));
1481  const char *module_var = "__SWIG_MODULE__" SWIG_TYPE_TABLE_NAME SWIG_RUNTIME_VERSION;
1482#if OCTAVE_API_VERSION_NUMBER<37
1483  link_to_global_variable(curr_sym_tab->lookup(module_var, true));
1484#else
1485  symbol_table::varref(module_var);
1486  symbol_table::mark_global(module_var);
1487#endif
1488  set_global_value(module_var, ov);
1489}