octrun.swg 45 KB

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