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