swig/Examples/test-suite/li_boost_array.i
William S Fulton 93eb7eae0b 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.
2015-11-27 19:30:22 +00:00

77 lines
1.8 KiB
OpenEdge ABL

%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