PageRenderTime 67ms CodeModel.GetById 29ms RepoModel.GetById 0ms app.codeStats 0ms

/trunk/Lib/octave/octrun.swg

#
Unknown | 1489 lines | 1283 code | 206 blank | 0 comment | 0 complexity | fe5886f2f7bab8dc0869efc16754510e MD5 | raw file
Possible License(s): LGPL-2.1, Cube, GPL-3.0, 0BSD, GPL-2.0
  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. octave_swig_type *nc_this = const_cast < octave_swig_type *>(this);
  354. // Find the __dims__ method of this object
  355. member_value_pair *m = nc_this->find_member("__dims__", false);
  356. if (!m) return dim_vector(1,1);
  357. // Call the __dims__ method of this object
  358. octave_value_list inarg;
  359. inarg.append(nc_this->as_value());
  360. octave_value_list outarg = nc_this->member_invoke(m, inarg, 1);
  361. // __dims__ should return (at least) one output argument
  362. if (outarg.length() < 1) return dim_vector(1,1);
  363. octave_value & out = outarg(0);
  364. // Return value should be cell or matrix of integers
  365. if (out.is_cell()) {
  366. const Cell & c=out.cell_value();
  367. int ndim = c.rows();
  368. if (ndim==1 && c.columns()!=1) ndim = c.columns();
  369. dim_vector d;
  370. d.resize(ndim);
  371. // Fill in dim_vector
  372. for (int k=0;k<ndim;k++) {
  373. const octave_value& obj = c(k);
  374. d.elem(k) = obj.int_value();
  375. // __dims__ should return a cell filled with integers
  376. if (error_state) return dim_vector(1,1);
  377. }
  378. return d;
  379. } else if (out.is_matrix_type() || out.is_real_nd_array() || out.is_numeric_type() ) {
  380. if (out.rows()==1 || out.columns()==1) {
  381. Array<int> a = out.int_vector_value();
  382. if (error_state) return dim_vector(1,1);
  383. dim_vector d;
  384. d.resize(a.numel());
  385. for (int k=0;k<a.numel();k++) {
  386. d.elem(k) = a(k);
  387. }
  388. return d;
  389. } else {
  390. return dim_vector(1,1);
  391. }
  392. } else {
  393. return dim_vector(1,1);
  394. }
  395. }
  396. octave_value as_value() {
  397. ++count;
  398. return Swig::swig_value_ref(this);
  399. }
  400. void incref() {
  401. ++count;
  402. }
  403. void decref() {
  404. if (!--count)
  405. delete this;
  406. }
  407. long swig_this() const {
  408. if (!types.size())
  409. return (long) this;
  410. return (long) types[0].second.ptr;
  411. }
  412. const char* help_text() const {
  413. if (!types.size())
  414. return 0;
  415. if (!types[0].first->clientdata)
  416. return 0;
  417. swig_octave_class *c = (swig_octave_class *) types[0].first->clientdata;
  418. return c->constructor_doc;
  419. }
  420. std::string swig_type_name() const {
  421. // * need some way to manually name subclasses.
  422. // * eg optional first arg to subclass(), or named_subclass()
  423. std::string ret;
  424. for (unsigned int j = 0; j < types.size(); ++j) {
  425. if (j)
  426. ret += "_";
  427. if (types[j].first->clientdata) {
  428. swig_octave_class *c = (swig_octave_class *) types[j].first->clientdata;
  429. ret += c->name;
  430. } else
  431. ret += types[j].first->name;
  432. }
  433. return ret;
  434. }
  435. void merge(octave_swig_type &rhs) {
  436. rhs.own = 0;
  437. for (unsigned int j = 0; j < rhs.types.size(); ++j) {
  438. assert(!rhs.types[j].second.destroyed);
  439. Swig::Director *d = Swig::get_rtdir(rhs.types[j].second.ptr);
  440. if (d)
  441. Swig::swig_director_set_self(d, this);
  442. }
  443. types.insert(types.end(), rhs.types.begin(), rhs.types.end());
  444. members.insert(rhs.members.begin(), rhs.members.end());
  445. rhs.types.clear();
  446. rhs.members.clear();
  447. }
  448. void install_global(bool global_load) {
  449. for (member_map::const_iterator it = members.begin(); it != members.end(); ++it) {
  450. bool is_global_op = (it->first.substr(0, strlen(SWIG_op_prefix)) == SWIG_op_prefix);
  451. bool is_func_defined = (it->second.first && it->second.first->method);
  452. if (is_func_defined && (is_global_op || global_load)) {
  453. install_builtin_function(it->second.first->method, it->first,
  454. it->second.first->doc ? it->second.first->doc : std::string());
  455. }
  456. octave_value global_val = is_global_op ? make_fcn_handle(it->first) : it->second.second;
  457. if (global_val.is_defined() && (is_global_op || global_load)) {
  458. #if OCTAVE_API_VERSION_NUMBER<37
  459. link_to_global_variable(curr_sym_tab->lookup(it->first, true));
  460. #else
  461. symbol_table::varref(it->first);
  462. symbol_table::mark_global(it->first);
  463. #endif
  464. set_global_value(it->first, global_val);
  465. #if OCTAVE_API_VERSION_NUMBER<37
  466. octave_swig_type *ost = Swig::swig_value_deref(global_val);
  467. if (ost) {
  468. const char* h = ost->help_text();
  469. if (h) {
  470. symbol_record *sr = global_sym_tab->lookup (it->first, true);
  471. sr->document(h);
  472. }
  473. }
  474. #endif
  475. }
  476. }
  477. }
  478. void *cast(swig_type_info *type, int *_own, int flags) {
  479. if (_own)
  480. *_own = own;
  481. if (flags &SWIG_POINTER_DISOWN)
  482. own = 0;
  483. if (!type && types.size())
  484. return types[0].second.ptr;
  485. for (unsigned int j = 0; j < types.size(); ++j)
  486. if (type == types[j].first)
  487. return types[j].second.ptr;
  488. for (unsigned int j = 0; j < types.size(); ++j) {
  489. swig_cast_info *tc = SWIG_TypeCheck(types[j].first->name, type);
  490. if (!tc)
  491. continue;
  492. int newmemory = 0;
  493. void *vptr = SWIG_TypeCast(tc, types[j].second.ptr, &newmemory);
  494. assert(!newmemory); // newmemory handling not yet implemented
  495. return vptr;
  496. }
  497. return 0;
  498. }
  499. bool is_owned() const {
  500. return own;
  501. }
  502. void director_destroyed(Swig::Director *d) {
  503. bool found = false;
  504. for (unsigned int j = 0; j < types.size(); ++j) {
  505. Swig::Director *dj = Swig::get_rtdir(types[j].second.ptr);
  506. if (dj == d) {
  507. types[j].second.destroyed = true;
  508. found = true;
  509. }
  510. }
  511. assert(found);
  512. }
  513. void assign(const std::string &name, const octave_value &ov) {
  514. members[name] = std::make_pair((const swig_octave_member *) 0, ov);
  515. }
  516. void assign(const std::string &name, const swig_octave_member *m) {
  517. members[name] = std::make_pair(m, octave_value());
  518. }
  519. octave_base_value *clone() const {
  520. // pass-by-value is probably not desired, and is harder;
  521. // requires calling copy constructors of contained types etc.
  522. assert(0);
  523. *(int *) 0 = 0;
  524. return 0;
  525. }
  526. octave_base_value *empty_clone() const {
  527. return new octave_swig_type();
  528. }
  529. bool is_defined() const {
  530. return true;
  531. }
  532. virtual bool is_map() const {
  533. return true;
  534. }
  535. virtual octave_value subsref(const std::string &ops, const std::list < octave_value_list > &idx) {
  536. octave_value_list ovl = subsref(ops, idx, 1);
  537. return ovl.length()? ovl(0) : octave_value();
  538. }
  539. virtual octave_value_list subsref(const std::string &ops, const std::list < octave_value_list > &idx, int nargout) {
  540. assert(ops.size() > 0);
  541. assert(ops.size() == idx.size());
  542. std::list < octave_value_list >::const_iterator idx_it = idx.begin();
  543. int skip = 0;
  544. octave_value_list sub_ovl;
  545. // constructor invocation
  546. if (ops[skip] == '(' && construct_type) {
  547. assert(construct_type->clientdata);
  548. swig_octave_class *c = (swig_octave_class *) construct_type->clientdata;
  549. if (!c->constructor) {
  550. error("cannot create instance");
  551. return octave_value_list();
  552. }
  553. octave_value_list args;
  554. if (c->director)
  555. args.append(Swig::swig_value_ref(new octave_swig_type(this, 0, 0)));
  556. args.append(*idx_it++);
  557. ++skip;
  558. sub_ovl = c->constructor(args, nargout);
  559. }
  560. // member dereference or invocation
  561. else if (ops[skip] == '.') {
  562. std::string subname;
  563. const swig_type_info *base = 0; // eg, a.base.base_cpp_mem
  564. for (;;) {
  565. octave_value_list subname_ovl(*idx_it++);
  566. ++skip;
  567. assert(subname_ovl.length() == 1 && subname_ovl(0).is_string());
  568. subname = subname_ovl(0).string_value();
  569. const swig_type_info *next_base = find_base(subname, base);
  570. if (!next_base || skip >= (int) ops.size() || ops[skip] != '.')
  571. break;
  572. base = next_base;
  573. }
  574. member_value_pair tmp, *m = &tmp;
  575. if (!base || !(m->first = find_member(base, subname)))
  576. m = find_member(subname, false);
  577. if (!m) {
  578. error("member not found");
  579. return octave_value_list();
  580. }
  581. octave_value_list args;
  582. if (!always_static &&
  583. (!m->first || (!m->first->is_static() && !m->first->is_global())))
  584. args.append(as_value());
  585. if (skip < (int) ops.size() && ops[skip] == '(' &&
  586. ((m->first && m->first->method) || m->second.is_function() ||
  587. m->second.is_function_handle())) {
  588. args.append(*idx_it++);
  589. ++skip;
  590. sub_ovl = member_invoke(m, args, nargout);
  591. } else {
  592. sub_ovl = member_deref(m, args);
  593. }
  594. }
  595. // index operator
  596. else {
  597. if (ops[skip] == '(' || ops[skip] == '{') {
  598. const char *op_name = ops[skip] == '(' ? "__paren__" : "__brace__";
  599. octave_value_list args;
  600. args.append(*idx_it++);
  601. ++skip;
  602. if (!dispatch_index_op(op_name, args, sub_ovl)) {
  603. error("error evaluating index operator");
  604. return octave_value_list();
  605. }
  606. } else {
  607. error("unsupported subsref");
  608. return octave_value_list();
  609. }
  610. }
  611. if (skip >= (int) ops.size())
  612. return sub_ovl;
  613. if (sub_ovl.length() < 1) {
  614. error("bad subs ref");
  615. return octave_value_list();
  616. }
  617. return sub_ovl(0).next_subsref(nargout, ops, idx, skip);
  618. }
  619. octave_value subsasgn(const std::string &ops, const std::list < octave_value_list > &idx, const octave_value &rhs) {
  620. assert(ops.size() > 0);
  621. assert(ops.size() == idx.size());
  622. std::list < octave_value_list >::const_iterator idx_it = idx.begin();
  623. int skip = 0;
  624. if (ops.size() > 1) {
  625. std::list < octave_value_list >::const_iterator last = idx.end();
  626. --last;
  627. std::list < octave_value_list > next_idx(idx.begin(), last);
  628. octave_value next_ov = subsref(ops.substr(0, ops.size() - 1), next_idx);
  629. next_ov.subsasgn(ops.substr(ops.size() - 1), std::list < octave_value_list > (1, *last), rhs);
  630. }
  631. else if (ops[skip] == '(' || ops[skip] == '{') {
  632. const char *op_name = ops[skip] == '(' ? "__paren_asgn__" : "__brace_asgn__";
  633. member_value_pair *m = find_member(op_name, false);
  634. if (m) {
  635. octave_value_list args;
  636. args.append(as_value());
  637. args.append(*idx_it);
  638. args.append(rhs);
  639. member_invoke(m, args, 1);
  640. } else
  641. error("%s member not found", op_name);
  642. }
  643. else if (ops[skip] == '.') {
  644. octave_value_list subname_ovl(*idx_it++);
  645. ++skip;
  646. assert(subname_ovl.length() == 1 &&subname_ovl(0).is_string());
  647. std::string subname = subname_ovl(0).string_value();
  648. member_value_pair *m = find_member(subname, true);
  649. if (!m->first || !m->first->set_method) {
  650. m->first = 0;
  651. m->second = rhs;
  652. } else if (m->first->set_method) {
  653. octave_value_list args;
  654. if (!m->first->is_static() && !m->first->is_global())
  655. args.append(as_value());
  656. args.append(rhs);
  657. m->first->set_method(args, 1);
  658. } else
  659. error("member not assignable");
  660. } else
  661. error("unsupported subsasgn");
  662. return as_value();
  663. }
  664. virtual bool is_object() const {
  665. return true;
  666. }
  667. virtual bool is_string() const {
  668. octave_swig_type *nc_this = const_cast < octave_swig_type *>(this);
  669. return !!nc_this->find_member("__str__", false);
  670. }
  671. virtual std::string string_value(bool force = false) const {
  672. octave_swig_type *nc_this = const_cast < octave_swig_type *>(this);
  673. member_value_pair *m = nc_this->find_member("__str__", false);
  674. if (!m) {
  675. error("__str__ method not defined");
  676. return std::string();
  677. }
  678. octave_value_list outarg = nc_this->member_invoke(m, octave_value_list(nc_this->as_value()), 1);
  679. if (outarg.length() < 1 || !outarg(0).is_string()) {
  680. error("__str__ method did not return a string");
  681. return std::string();
  682. }
  683. return outarg(0).string_value();
  684. }
  685. #if OCTAVE_API_VERSION_NUMBER >= 40
  686. virtual octave_map map_value() const {
  687. return octave_map();
  688. }
  689. #else
  690. virtual Octave_map map_value() const {
  691. return Octave_map();
  692. }
  693. #endif
  694. virtual string_vector map_keys() const {
  695. member_map tmp;
  696. load_members(tmp);
  697. string_vector keys(tmp.size());
  698. int k = 0;
  699. for (member_map::iterator it = tmp.begin(); it != tmp.end(); ++it)
  700. keys(k++) = it->first;
  701. return keys;
  702. }
  703. virtual bool save_ascii (std::ostream& os) {
  704. return true;
  705. }
  706. virtual bool load_ascii (std::istream& is) {
  707. return true;
  708. }
  709. virtual bool save_binary (std::ostream& os, bool& save_as_floats) {
  710. return true;
  711. }
  712. virtual bool load_binary (std::istream& is, bool swap,
  713. oct_mach_info::float_format fmt) {
  714. return true;
  715. }
  716. #if defined (HAVE_HDF5)
  717. virtual bool
  718. save_hdf5 (hid_t loc_id, const char *name, bool save_as_floats) {
  719. return true;
  720. }
  721. virtual bool
  722. load_hdf5 (hid_t loc_id, const char *name, bool have_h5giterate_bug) {
  723. return true;
  724. }
  725. #endif
  726. virtual octave_value convert_to_str(bool pad = false, bool force = false, char type = '"') const {
  727. return string_value();
  728. }
  729. virtual octave_value convert_to_str_internal(bool pad, bool force, char type) const {
  730. return string_value();
  731. }
  732. static bool dispatch_global_op(const std::string &symbol, const octave_value_list &args, octave_value &ret) {
  733. // we assume that SWIG_op_prefix-prefixed functions are installed in global namespace
  734. // (rather than any module namespace).
  735. octave_value fcn = get_global_value(symbol, true);
  736. if (!fcn.is_function() && !fcn.is_function_handle())
  737. return false;
  738. ret = fcn.subsref("(", std::list < octave_value_list > (1, args), 1);
  739. return true;
  740. }
  741. static octave_value dispatch_unary_op(const octave_base_value &x, const char *op_name) {
  742. octave_swig_type *ost = Swig::swig_value_deref(x);
  743. assert(ost);
  744. octave_value ret;
  745. if (ost->dispatch_unary_op(std::string("__") + op_name + std::string("__"), ret))
  746. return ret;
  747. std::string symbol = SWIG_op_prefix + ost->swig_type_name() + "_" + op_name;
  748. octave_value_list args;
  749. args.append(make_value_hack(x));
  750. if (dispatch_global_op(symbol, args, ret))
  751. return ret;
  752. error("could not dispatch unary operator");
  753. return octave_value();
  754. }
  755. static octave_value dispatch_binary_op(const octave_base_value &lhs, const octave_base_value &rhs, const char *op_name) {
  756. octave_swig_type *lhs_ost = Swig::swig_value_deref(lhs);
  757. octave_swig_type *rhs_ost = Swig::swig_value_deref(rhs);
  758. octave_value ret;
  759. if (lhs_ost && lhs_ost->dispatch_binary_op(std::string("__") + op_name + std::string("__"), rhs, ret))
  760. return ret;
  761. if (rhs_ost) {
  762. if (strlen(op_name) == 2 && (op_name[1] == 't' || op_name[1] == 'e')) {
  763. if (op_name[0] == 'l' && rhs_ost->dispatch_binary_op(std::string("__g") + op_name[1] + std::string("__"), lhs, ret))
  764. return ret;
  765. if (op_name[0] == 'g' && rhs_ost->dispatch_binary_op(std::string("__l") + op_name[1] + std::string("__"), lhs, ret))
  766. return ret;
  767. }
  768. if (rhs_ost->dispatch_binary_op(std::string("__r") + op_name + std::string("__"), lhs, ret))
  769. return ret;
  770. }
  771. std::string symbol;
  772. octave_value_list args;
  773. args.append(make_value_hack(lhs));
  774. args.append(make_value_hack(rhs));
  775. symbol = SWIG_op_prefix;
  776. symbol += lhs_ost ? lhs_ost->swig_type_name() : lhs.type_name();
  777. symbol += "_";
  778. symbol += op_name;
  779. symbol += "_";
  780. symbol += rhs_ost ? rhs_ost->swig_type_name() : rhs.type_name();
  781. if (dispatch_global_op(symbol, args, ret))
  782. return ret;
  783. symbol = SWIG_op_prefix;
  784. symbol += lhs_ost ? lhs_ost->swig_type_name() : lhs.type_name();
  785. symbol += "_";
  786. symbol += op_name;
  787. symbol += "_";
  788. symbol += "any";
  789. if (dispatch_global_op(symbol, args, ret))
  790. return ret;
  791. symbol = SWIG_op_prefix;
  792. symbol += "any";
  793. symbol += "_";
  794. symbol += op_name;
  795. symbol += "_";
  796. symbol += rhs_ost ? rhs_ost->swig_type_name() : rhs.type_name();
  797. if (dispatch_global_op(symbol, args, ret))
  798. return ret;
  799. error("could not dispatch binary operator");
  800. return octave_value();
  801. }
  802. void print(std::ostream &os, bool pr_as_read_syntax = false) const {
  803. if (is_string()) {
  804. os << string_value();
  805. return;
  806. }
  807. member_map tmp;
  808. load_members(tmp);
  809. indent(os);
  810. os << "{"; newline(os);
  811. increment_indent_level();
  812. for (unsigned int j = 0; j < types.size(); ++j) {
  813. indent(os);
  814. if (types[j].first->clientdata) {
  815. const swig_octave_class *c = (const swig_octave_class *) types[j].first->clientdata;
  816. os << c->name << ", ptr = " << types[j].second.ptr; newline(os);
  817. } else {
  818. os << types[j].first->name << ", ptr = " << types[j].second.ptr; newline(os);
  819. }
  820. }
  821. for (member_map::const_iterator it = tmp.begin(); it != tmp.end(); ++it) {
  822. indent(os);
  823. if (it->second.first) {
  824. const char *objtype = it->second.first->method ? "method" : "variable";
  825. const char *modifier = (it->second.first->flags &1) ? "static " : (it->second.first->flags &2) ? "global " : "";
  826. os << it->second.first->name << " (" << modifier << objtype << ")"; newline(os);
  827. assert(it->second.first->name == it->first);
  828. } else {
  829. os << it->first; newline(os);
  830. }
  831. }
  832. decrement_indent_level();
  833. indent(os);
  834. os << "}"; newline(os);
  835. }
  836. };
  837. // Octave tries hard to preserve pass-by-value semantics. Eg, assignments
  838. // will call clone() via make_unique() if there is more than one outstanding
  839. // reference to the lhs, and forces the clone's reference count to 1
  840. // (so you can't just increment your own count and return this).
  841. //
  842. // One way to fix this (without modifying Octave) is to add a level of
  843. // indirection such that clone copies ref-counted pointer and we keep
  844. // pass-by-ref semantics (which are more natural/expected for C++ bindings).
  845. //
  846. // Supporting both pass-by-{ref,value} and toggling via %feature/option
  847. // might be nice.
  848. class octave_swig_ref:public octave_base_value {
  849. octave_swig_type *ptr;
  850. public:
  851. octave_swig_ref(octave_swig_type *_ptr = 0)
  852. :ptr(_ptr) { }
  853. ~octave_swig_ref()
  854. { if (ptr) ptr->decref(); }
  855. octave_swig_type *get_ptr() const
  856. { return ptr; }
  857. octave_base_value *clone() const
  858. { if (ptr) ptr->incref(); return new octave_swig_ref(ptr); }
  859. octave_base_value *empty_clone() const
  860. { return new octave_swig_ref(0); }
  861. dim_vector dims(void) const
  862. { return ptr->dims(); }
  863. bool is_defined() const
  864. { return ptr->is_defined(); }
  865. virtual bool is_map() const
  866. { return ptr->is_map(); }
  867. virtual octave_value subsref(const std::string &ops, const std::list < octave_value_list > &idx)
  868. { return ptr->subsref(ops, idx); }
  869. virtual octave_value_list subsref(const std::string &ops, const std::list < octave_value_list > &idx, int nargout)
  870. { return ptr->subsref(ops, idx, nargout); }
  871. octave_value subsasgn(const std::string &ops, const std::list < octave_value_list > &idx, const octave_value &rhs)
  872. { return ptr->subsasgn(ops, idx, rhs); }
  873. virtual bool is_object() const
  874. { return ptr->is_object(); }
  875. virtual bool is_string() const
  876. { return ptr->is_string(); }
  877. virtual std::string string_value(bool force = false) const
  878. { return ptr->string_value(force); }
  879. #if OCTAVE_API_VERSION_NUMBER >= 40
  880. virtual octave_map map_value() const
  881. { return ptr->map_value(); }
  882. #else
  883. virtual Octave_map map_value() const
  884. { return ptr->map_value(); }
  885. #endif
  886. virtual string_vector map_keys() const
  887. { return ptr->map_keys(); }
  888. virtual bool save_ascii (std::ostream& os)
  889. { return ptr->save_ascii(os); }
  890. virtual bool load_ascii (std::istream& is)
  891. { return ptr->load_ascii(is); }
  892. virtual bool save_binary (std::ostream& os, bool& save_as_floats)
  893. { return ptr->save_binary(os, save_as_floats); }
  894. virtual bool load_binary (std::istream& is, bool swap,
  895. oct_mach_info::float_format fmt)
  896. { return ptr->load_binary(is, swap, fmt); }
  897. #if defined (HAVE_HDF5)
  898. virtual bool
  899. save_hdf5 (hid_t loc_id, const char *name, bool save_as_floats)
  900. { return ptr->save_hdf5(loc_id, name, save_as_floats); }
  901. virtual bool
  902. load_hdf5 (hid_t loc_id, const char *name, bool have_h5giterate_bug)
  903. { return ptr->load_hdf5(loc_id, name, have_h5giterate_bug); }
  904. #endif
  905. virtual octave_value convert_to_str(bool pad = false, bool force = false, char type = '"') const
  906. { return ptr->convert_to_str(pad, force, type); }
  907. virtual octave_value convert_to_str_internal(bool pad, bool force, char type) const
  908. { return ptr->convert_to_str_internal(pad, force, type); }
  909. void print(std::ostream &os, bool pr_as_read_syntax = false) const
  910. { return ptr->print(os, pr_as_read_syntax); }
  911. private:
  912. DECLARE_OCTAVE_ALLOCATOR;
  913. DECLARE_OV_TYPEID_FUNCTIONS_AND_DATA;
  914. };
  915. DEFINE_OCTAVE_ALLOCATOR(octave_swig_ref);
  916. DEFINE_OV_TYPEID_FUNCTIONS_AND_DATA(octave_swig_ref, "swig_ref", "swig_ref");
  917. class octave_swig_packed:public octave_base_value {
  918. swig_type_info *type;
  919. std::vector < char > buf;
  920. public:
  921. octave_swig_packed(swig_type_info *_type = 0, const void *_buf = 0, size_t _buf_len = 0)
  922. : type(_type), buf((const char*)_buf, (const char*)_buf + _buf_len) {
  923. }
  924. bool copy(swig_type_info *outtype, void *ptr, size_t sz) const {
  925. if (outtype && outtype != type)
  926. return false;
  927. assert(sz <= buf.size());
  928. std::copy(buf.begin(), buf.begin()+sz, (char*)ptr);
  929. return true;
  930. }
  931. octave_base_value *clone() const {
  932. return new octave_swig_packed(*this);
  933. }
  934. octave_base_value *empty_clone() const {
  935. return new octave_swig_packed();
  936. }
  937. bool is_defined() const {
  938. return true;
  939. }
  940. void print(std::ostream &os, bool pr_as_read_syntax = false) const {
  941. indent(os);
  942. os << "swig packed type: name = " << (type ? type->name : std::string()) << ", len = " << buf.size(); newline(os);
  943. }
  944. virtual bool save_ascii (std::ostream& os) {
  945. return true;
  946. }
  947. virtual bool load_ascii (std::istream& is) {
  948. return true;
  949. }
  950. virtual bool save_binary (std::ostream& os, bool& save_as_floats) {
  951. return true;
  952. }
  953. virtual bool load_binary (std::istream& is, bool swap,
  954. oct_mach_info::float_format fmt) {
  955. return true;
  956. }
  957. #if defined (HAVE_HDF5)
  958. virtual bool
  959. save_hdf5 (hid_t loc_id, const char *name, bool save_as_floats) {
  960. return true;
  961. }
  962. virtual bool
  963. load_hdf5 (hid_t loc_id, const char *name, bool have_h5giterate_bug) {
  964. return true;
  965. }
  966. #endif
  967. private:
  968. DECLARE_OCTAVE_ALLOCATOR;
  969. DECLARE_OV_TYPEID_FUNCTIONS_AND_DATA;
  970. };
  971. DEFINE_OCTAVE_ALLOCATOR(octave_swig_packed);
  972. DEFINE_OV_TYPEID_FUNCTIONS_AND_DATA(octave_swig_packed, "swig_packed", "swig_packed");
  973. static octave_value_list octave_set_immutable(const octave_value_list &args, int nargout) {
  974. error("attempt to set immutable member variable");
  975. return octave_value_list();
  976. }
  977. struct octave_value_ref {
  978. const octave_value_list &ovl;
  979. int j;
  980. octave_value_ref(const octave_value_list &_ovl, int _j)
  981. :ovl(_ovl), j(_j) { }
  982. operator octave_value() const {
  983. return ovl(j);
  984. }
  985. octave_value operator*() const {
  986. return ovl(j);
  987. }
  988. };
  989. octave_value_list swig_subclass(const octave_value_list &args, int nargout) {
  990. octave_swig_type *top = new octave_swig_type;
  991. for (int j = 0; j < args.length(); ++j) {
  992. if (args(j).type_id() == octave_swig_ref::static_type_id()) {
  993. octave_swig_ref *osr = static_cast < octave_swig_ref *>(args(j).internal_rep());
  994. octave_swig_type *ost = osr->get_ptr();
  995. if (!ost->is_owned()) {
  996. error("cannot subclass object not constructed on octave side");
  997. return octave_value_list();
  998. }
  999. top->merge(*ost);
  1000. } else if (args(j).is_function_handle()) {
  1001. top->assign(args(j).fcn_handle_value()->fcn_name(), args(j));
  1002. } else if (args(j).is_string()) {
  1003. if (j + 1 >= args.length()) {
  1004. error("member assignments must be of string,value form");
  1005. return octave_value_list();
  1006. }
  1007. top->assign(args(j).string_value(), args(j + 1));
  1008. ++j;
  1009. } else {
  1010. error("invalid arguments to subclass");
  1011. return octave_value_list();
  1012. }
  1013. }
  1014. return octave_value(Swig::swig_value_ref(top));
  1015. }
  1016. octave_value_list swig_type(const octave_value_list &args, int nargout) {
  1017. if (args.length() != 1) {
  1018. error("swig_typeinfo must be called with only a single object");
  1019. return octave_value_list();
  1020. }
  1021. octave_swig_type *ost = Swig::swig_value_deref(args(0));
  1022. if (!ost) {
  1023. error("object is not a swig_ref");
  1024. return octave_value_list();
  1025. }
  1026. return octave_value(ost->swig_type_name());
  1027. }
  1028. octave_value_list swig_typequery(const octave_value_list &args, int nargout) {
  1029. if (args.length() != 1 || !args(0).is_string()) {
  1030. error("swig_typeinfo must be called with single string argument");
  1031. return octave_value_list();
  1032. }
  1033. swig_module_info *module = SWIG_GetModule(0);
  1034. swig_type_info *type = SWIG_TypeQueryModule(module, module, args(0).string_value().c_str());
  1035. if (!type)
  1036. return octave_value("<unknown>");
  1037. return octave_value(type->name);
  1038. }
  1039. octave_value_list swig_this(const octave_value_list &args, int nargout) {
  1040. if (args.length() != 1) {
  1041. error("swig_typeinfo must be called with only a single object");
  1042. return octave_value_list();
  1043. }
  1044. if (args(0).is_matrix_type() && args(0).rows() == 0 && args(0).columns() == 0)
  1045. return octave_value(octave_uint64(0));
  1046. octave_swig_type *ost = Swig::swig_value_deref(args(0));
  1047. if (!ost) {
  1048. error("object is not a swig_ref");
  1049. return octave_value_list();
  1050. }
  1051. return octave_value(octave_uint64((unsigned long long) ost->swig_this()));
  1052. }
  1053. #define SWIG_DIRECTORS
  1054. namespace Swig {
  1055. class Director {
  1056. octave_swig_type *self;
  1057. bool swig_disowned;
  1058. Director(const Director &x);
  1059. Director &operator=(const Director &rhs);
  1060. public:
  1061. Director(void *vptr):self(0), swig_disowned(false) {
  1062. set_rtdir(vptr, this);
  1063. }
  1064. ~Director() {
  1065. swig_director_destroyed(self, this);
  1066. if (swig_disowned)
  1067. self->decref();
  1068. }
  1069. void swig_set_self(octave_swig_type *new_self) {
  1070. assert(!swig_disowned);
  1071. self = new_self;
  1072. }
  1073. octave_swig_type *swig_get_self() const {
  1074. return self;
  1075. }
  1076. void swig_disown() {
  1077. if (swig_disowned)
  1078. return;
  1079. swig_disowned = true;
  1080. self->incref();
  1081. }
  1082. };
  1083. struct DirectorTypeMismatchException {
  1084. static void raise(const char *msg) {
  1085. // ... todo
  1086. throw(DirectorTypeMismatchException());
  1087. }
  1088. static void raise(const octave_value &ov, const char *msg) {
  1089. // ... todo
  1090. raise(msg);
  1091. }
  1092. };
  1093. struct DirectorPureVirtualException {
  1094. static void raise(const char *msg) {
  1095. // ... todo
  1096. throw(DirectorPureVirtualException());
  1097. }
  1098. static void raise(const octave_value &ov, const char *msg) {
  1099. // ... todo
  1100. raise(msg);
  1101. }
  1102. };
  1103. }
  1104. SWIGRUNTIME void swig_acquire_ownership(void *vptr) {
  1105. // assert(0);
  1106. // ... todo
  1107. }
  1108. SWIGRUNTIME void swig_acquire_ownership_array(void *vptr) {
  1109. // assert(0);
  1110. // ... todo
  1111. }
  1112. SWIGRUNTIME void swig_acquire_ownership_obj(void *vptr, int own) {
  1113. // assert(0);
  1114. // ... todo
  1115. }
  1116. namespace Swig {
  1117. SWIGRUNTIME void swig_director_destroyed(octave_swig_type *self, Director *d) {
  1118. self->director_destroyed(d);
  1119. }
  1120. SWIGRUNTIME void swig_director_set_self(Director *d, octave_swig_type *self) {
  1121. d->swig_set_self(self);
  1122. }
  1123. SWIGRUNTIME octave_base_value *swig_value_ref(octave_swig_type *ost) {
  1124. return new octave_swig_ref(ost);
  1125. }
  1126. SWIGRUNTIME octave_swig_type *swig_value_deref(octave_value ov) {
  1127. if (ov.is_cell() && ov.rows() == 1 && ov.columns() == 1)
  1128. ov = ov.cell_value()(0);
  1129. return swig_value_deref(*ov.internal_rep());
  1130. }
  1131. SWIGRUNTIME octave_swig_type *swig_value_deref(const octave_base_value &ov) {
  1132. if (ov.type_id() != octave_swig_ref::static_type_id())
  1133. return 0;
  1134. const octave_swig_ref *osr = static_cast < const octave_swig_ref *>(&ov);
  1135. return osr->get_ptr();
  1136. }
  1137. }
  1138. #define swig_unary_op(name) \
  1139. SWIGRUNTIME octave_value swig_unary_op_##name(const octave_base_value &x) { \
  1140. return octave_swig_type::dispatch_unary_op(x,#name); \
  1141. }
  1142. #define swig_binary_op(name) \
  1143. SWIGRUNTIME octave_value swig_binary_op_##name(const octave_base_value&lhs,const octave_base_value &rhs) { \
  1144. return octave_swig_type::dispatch_binary_op(lhs,rhs,#name); \
  1145. }
  1146. #define swigreg_unary_op(name) \
  1147. if (!octave_value_typeinfo::lookup_unary_op(octave_value::op_##name,tid)) \
  1148. octave_value_typeinfo::register_unary_op(octave_value::op_##name,tid,swig_unary_op_##name);
  1149. #define swigreg_binary_op(name) \
  1150. if (!octave_value_typeinfo::lookup_binary_op(octave_value::op_##name,tid1,tid2)) \
  1151. octave_value_typeinfo::register_binary_op(octave_value::op_##name,tid1,tid2,swig_binary_op_##name);
  1152. swig_unary_op(not);
  1153. swig_unary_op(uplus);
  1154. swig_unary_op(uminus);
  1155. swig_unary_op(transpose);
  1156. swig_unary_op(hermitian);
  1157. swig_unary_op(incr);
  1158. swig_unary_op(decr);
  1159. swig_binary_op(add);
  1160. swig_binary_op(sub);
  1161. swig_binary_op(mul);
  1162. swig_binary_op(div);
  1163. swig_binary_op(pow);
  1164. swig_binary_op(ldiv);
  1165. swig_binary_op(lshift);
  1166. swig_binary_op(rshift);
  1167. swig_binary_op(lt);
  1168. swig_binary_op(le);
  1169. swig_binary_op(eq);
  1170. swig_binary_op(ge);
  1171. swig_binary_op(gt);
  1172. swig_binary_op(ne);
  1173. swig_binary_op(el_mul);
  1174. swig_binary_op(el_div);
  1175. swig_binary_op(el_pow);
  1176. swig_binary_op(el_ldiv);
  1177. swig_binary_op(el_and);
  1178. swig_binary_op(el_or);
  1179. SWIGRUNTIME void SWIG_InstallUnaryOps(int tid) {
  1180. swigreg_unary_op(not);
  1181. swigreg_unary_op(uplus);
  1182. swigreg_unary_op(uminus);
  1183. swigreg_unary_op(transpose);
  1184. swigreg_unary_op(hermitian);
  1185. swigreg_unary_op(incr);
  1186. swigreg_unary_op(decr);
  1187. }
  1188. SWIGRUNTIME void SWIG_InstallBinaryOps(int tid1, int tid2) {
  1189. swigreg_binary_op(add);
  1190. swigreg_binary_op(sub);
  1191. swigreg_binary_op(mul);
  1192. swigreg_binary_op(div);
  1193. swigreg_binary_op(pow);
  1194. swigreg_binary_op(ldiv);
  1195. swigreg_binary_op(lshift);
  1196. swigreg_binary_op(rshift);
  1197. swigreg_binary_op(lt);
  1198. swigreg_binary_op(le);
  1199. swigreg_binary_op(eq);
  1200. swigreg_binary_op(ge);
  1201. swigreg_binary_op(gt);
  1202. swigreg_binary_op(ne);
  1203. swigreg_binary_op(el_mul);
  1204. swigreg_binary_op(el_div);
  1205. swigreg_binary_op(el_pow);
  1206. swigreg_binary_op(el_ldiv);
  1207. swigreg_binary_op(el_and);
  1208. swigreg_binary_op(el_or);
  1209. }
  1210. SWIGRUNTIME void SWIG_InstallOps(int tid) {
  1211. // here we assume that tid are conseq integers increasing from zero, and
  1212. // that our tid is the last one. might be better to have explicit string
  1213. // list of types we should bind to, and use lookup_type to resolve their tid.
  1214. SWIG_InstallUnaryOps(tid);
  1215. SWIG_InstallBinaryOps(tid, tid);
  1216. for (int j = 0; j < tid; ++j) {
  1217. SWIG_InstallBinaryOps(j, tid);
  1218. SWIG_InstallBinaryOps(tid, j);
  1219. }
  1220. }
  1221. SWIGRUNTIME octave_value SWIG_Octave_NewPointerObj(void *ptr, swig_type_info *type, int flags) {
  1222. int own = (flags &SWIG_POINTER_OWN) ? SWIG_POINTER_OWN : 0;
  1223. Swig::Director *d = Swig::get_rtdir(ptr);
  1224. if (d && d->swig_get_self())
  1225. return d->swig_get_self()->as_value();
  1226. return Swig::swig_value_ref(new octave_swig_type(ptr, type, own));
  1227. }
  1228. SWIGRUNTIME int SWIG_Octave_ConvertPtrAndOwn(octave_value ov, void **ptr, swig_type_info *type, int flags, int *own) {
  1229. if (ov.is_cell() && ov.rows() == 1 && ov.columns() == 1)
  1230. ov = ov.cell_value()(0);
  1231. if (!ov.is_defined() ||
  1232. (ov.is_matrix_type() && ov.rows() == 0 && ov.columns() == 0) ) {
  1233. if (ptr)
  1234. *ptr = 0;
  1235. return SWIG_OK;
  1236. }
  1237. if (ov.type_id() != octave_swig_ref::static_type_id())
  1238. return SWIG_ERROR;
  1239. octave_swig_ref *osr = static_cast < octave_swig_ref *>(ov.internal_rep());
  1240. octave_swig_type *ost = osr->get_ptr();
  1241. void *vptr = ost->cast(type, own, flags);
  1242. if (!vptr)
  1243. return SWIG_ERROR;
  1244. if (ptr)
  1245. *ptr = vptr;
  1246. return SWIG_OK;
  1247. }
  1248. SWIGRUNTIME octave_value SWIG_Octave_NewPackedObj(void *ptr, size_t sz, swig_type_info *type) {
  1249. return new octave_swig_packed(type, (char *) ptr, sz);
  1250. }
  1251. SWIGRUNTIME int SWIG_Octave_ConvertPacked(const octave_value &ov, void *ptr, size_t sz, swig_type_info *type) {
  1252. if (!ov.is_defined())
  1253. return SWIG_ERROR;
  1254. if (ov.type_id() != octave_swig_packed::static_type_id())
  1255. return SWIG_ERROR;
  1256. octave_swig_packed *ost = static_cast < octave_swig_packed *>(ov.internal_rep());
  1257. return ost->copy(type, (char *) ptr, sz) ? SWIG_OK : SWIG_ERROR;
  1258. }
  1259. void SWIG_Octave_SetConstant(octave_swig_type *module_ns, const std::string &name, const octave_value &ov) {
  1260. module_ns->assign(name, ov);
  1261. }
  1262. SWIGRUNTIME swig_module_info *SWIG_Octave_GetModule(void *clientdata) {
  1263. octave_value ov = get_global_value("__SWIG_MODULE__" SWIG_TYPE_TABLE_NAME SWIG_RUNTIME_VERSION, true);
  1264. if (!ov.is_defined() ||
  1265. ov.type_id() != octave_swig_packed::static_type_id())
  1266. return 0;
  1267. const octave_swig_packed* osp =
  1268. static_cast < const octave_swig_packed *> (ov.internal_rep());
  1269. swig_module_info *pointer = 0;
  1270. osp->copy(0, &pointer, sizeof(swig_module_info *));
  1271. return pointer;
  1272. }
  1273. SWIGRUNTIME void SWIG_Octave_SetModule(void *clientdata, swig_module_info *pointer) {
  1274. octave_value ov = new octave_swig_packed(0, &pointer, sizeof(swig_module_info *));
  1275. const char *module_var = "__SWIG_MODULE__" SWIG_TYPE_TABLE_NAME SWIG_RUNTIME_VERSION;
  1276. #if OCTAVE_API_VERSION_NUMBER<37
  1277. link_to_global_variable(curr_sym_tab->lookup(module_var, true));
  1278. #else
  1279. symbol_table::varref(module_var);
  1280. symbol_table::mark_global(module_var);
  1281. #endif
  1282. set_global_value(module_var, ov);
  1283. }