1 %module octave_dim 2 3 %include "std_vector.i" 4 5 namespace std { 6 %template(IntVector) vector<int>; 7 } 8 9 10 %typemap(out) Matrix { 11 $result = $1; 12 } 13 14 // Code below will not work. Kept for future reference. 15 // Reason: there is no octave_value(Array<octave_idx_type>) constructor 16 //%typemap(out) Array<octave_idx_type> { 17 // $result = octave_value($1,true); 18 //} 19 20 21 %inline %{ 22 23 class Foo45a { 24 public: __dims__()25 std::vector<int> __dims__() const { 26 std::vector<int> ret(2); 27 ret[0] = 4; 28 ret[1] = 5; 29 return ret; 30 } 31 }; 32 33 // doubles are not converted to ints. 34 class Bar1 { 35 public: __dims__()36 std::vector<double> __dims__() const { 37 std::vector<double> ret(2); 38 ret[0] = 4; 39 ret[1] = 5; 40 return ret; 41 } 42 }; 43 44 class Bar2 { 45 public: __dims__()46 std::string __dims__() const { 47 return "foo"; 48 } 49 }; 50 51 52 class Foo4a { 53 public: __dims__()54 std::vector<int> __dims__() const { 55 std::vector<int> ret(1); 56 ret[0] = 4; 57 return ret; 58 } 59 }; 60 61 class Foo4b { 62 public: __dims__()63 int __dims__() const { 64 return 4; 65 } 66 }; 67 68 class Foo456a { 69 public: __dims__()70 std::vector<int> __dims__() const { 71 std::vector<int> ret(3); 72 ret[0] = 4; 73 ret[1] = 5; 74 ret[2] = 6; 75 return ret; 76 } 77 }; 78 79 80 81 82 class Foo { 83 84 }; 85 86 87 class Baz1 { 88 public: __dims__()89 Cell __dims__() const { 90 Cell c(1,2); 91 c(0) = 3; 92 c(1) = 4; 93 return c; 94 } 95 }; 96 97 class Baz2 { 98 public: __dims__()99 Cell __dims__() const { 100 Cell c(2,1); 101 c(0) = 3; 102 c(1) = 4; 103 return c; 104 } 105 }; 106 107 class Baz3 { 108 public: __dims__()109 Matrix __dims__() const { 110 Matrix c(2,1); 111 c(0) = 3; 112 c(1) = 4; 113 return c; 114 } 115 }; 116 117 class Baz4 { 118 public: __dims__()119 Matrix __dims__() const { 120 Matrix c(1,2); 121 c(0) = 3; 122 c(1) = 4; 123 return c; 124 } 125 }; 126 127 class Baz5 { 128 public: __dims__()129 Array<octave_idx_type> __dims__() const { 130 Array<octave_idx_type> c(dim_vector(2,1)); 131 c(0) = 3; 132 c(1) = 4; 133 return c; 134 } 135 }; 136 137 class Baz6 { 138 public: __dims__()139 Array<octave_idx_type> __dims__() const { 140 Array<octave_idx_type> c(dim_vector(1,2)); 141 c(0) = 3; 142 c(1) = 4; 143 return c; 144 } 145 }; 146 147 // Code below will not work. Kept for future reference. 148 // Reason: there is no octave_value(dim_vector) constructor 149 // class Baz7 { 150 //public: 151 // dim_vector __dims__() const { 152 // octave_value v = dim_vector(3,4); 153 // Array<int> a = v.int_vector_value(); 154 // if (error_state) return dim_vector(1,1); 155 // int mysize = a.numel(); 156 // return dim_vector(3,4); 157 // } 158 //}; 159 160 %} 161