Limited Python/Ruby support for boost::array
Hack to use the std::array support for boost::array. Is limited as it currently exposes some 'using' bugs in SWIG. For example, the type system fails to see that pointers to std::array and pointers to boost::array are the same. This approach saves having to maintain separate boost::array support. The 'using' bug ought to be fixed, otherwise separate boost_array.i files could be easily made from the std_array.i files.
This commit is contained in:
parent
b69719eb5b
commit
93eb7eae0b
10 changed files with 220 additions and 7 deletions
77
Examples/test-suite/li_boost_array.i
Normal file
77
Examples/test-suite/li_boost_array.i
Normal file
|
|
@ -0,0 +1,77 @@
|
|||
%module li_boost_array
|
||||
|
||||
#if defined(SWIGPYTHON) || defined(SWIGRUBY)
|
||||
|
||||
// Hack to use the std::array support for boost::array.
|
||||
// Is limited as it currently exposes some 'using' bugs in SWIG though.
|
||||
// For example, the type system fails to see that pointers to std::array
|
||||
// and pointers to boost::array are the same.
|
||||
|
||||
%{
|
||||
#include <boost/array.hpp>
|
||||
namespace std {
|
||||
using boost::array;
|
||||
}
|
||||
%}
|
||||
namespace boost {
|
||||
using std::array;
|
||||
}
|
||||
|
||||
%include <std_array.i>
|
||||
|
||||
%template(ArrayInt6) std::array<int, 6>;
|
||||
|
||||
%inline %{
|
||||
boost::array<int, 6> arrayOutVal() {
|
||||
const char carray[] = { -2, -1, 0, 0, 1, 2 };
|
||||
boost::array<int, 6> myarray;
|
||||
for (size_t i=0; i<6; ++i) {
|
||||
myarray[i] = carray[i];
|
||||
}
|
||||
return myarray;
|
||||
}
|
||||
|
||||
boost::array<int, 6> & arrayOutRef() {
|
||||
static boost::array<int, 6> a = { -2, -1, 0, 0, 1, 2 };
|
||||
return a;
|
||||
}
|
||||
|
||||
const boost::array<int, 6> & arrayOutConstRef() {
|
||||
static boost::array<int, 6> a = { -2, -1, 0, 0, 1, 2 };
|
||||
return a;
|
||||
}
|
||||
|
||||
boost::array<int, 6> * arrayOutPtr() {
|
||||
static boost::array<int, 6> a = { -2, -1, 0, 0, 1, 2 };
|
||||
return &a;
|
||||
}
|
||||
|
||||
boost::array<int, 6> arrayInVal(boost::array<int, 6> myarray) {
|
||||
for (boost::array<int, 6>::iterator it = myarray.begin(); it!=myarray.end(); ++it) {
|
||||
*it *= 10;
|
||||
}
|
||||
return myarray;
|
||||
}
|
||||
|
||||
const boost::array<int, 6> & arrayInConstRef(const boost::array<int, 6> & myarray) {
|
||||
static boost::array<int, 6> a = myarray;
|
||||
for (boost::array<int, 6>::iterator it = a.begin(); it!=a.end(); ++it) {
|
||||
*it *= 10;
|
||||
}
|
||||
return a;
|
||||
}
|
||||
|
||||
void arrayInRef(boost::array<int, 6> & myarray) {
|
||||
for (boost::array<int, 6>::iterator it = myarray.begin(); it!=myarray.end(); ++it) {
|
||||
*it *= 10;
|
||||
}
|
||||
}
|
||||
|
||||
void arrayInPtr(boost::array<int, 6> * myarray) {
|
||||
for (boost::array<int, 6>::iterator it = myarray->begin(); it!=myarray->end(); ++it) {
|
||||
*it *= 10;
|
||||
}
|
||||
}
|
||||
%}
|
||||
|
||||
#endif
|
||||
Loading…
Add table
Add a link
Reference in a new issue