/branches/talby-perl5-improvements/Lib/octave/octrun.swg

# · Unknown · 1432 lines · 1237 code · 195 blank · 0 comment · 0 complexity · cded8b1e1521124836d792713cce6df5 MD5 · raw file

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