Reputation: 8090
I have two versions of operator<<
in separate namespaces that have the same signature. Since swig
squashes them into a single name-space they conflict with one another, preventing me from running the interface.
I do not need to use the stream-insertion operator from the scripting language (Python), is there a way to suppress these.
The %ignore
directive doesn't seem to help.
A minimal test setup
Header File
//file:test.h
#include <iostream>
#include <boost/numeric/ublas/vector.hpp>
namespace probabilities{
typedef boost::numeric::ublas::vector< double > UnivariateTable;
inline
std::ostream& operator<<( std::ostream& ostr, const UnivariateTable& table){
ostr<<"I am a table";
return ostr;
}
}
namespace positions{
typedef boost::numeric::ublas::vector< double > PositionVector;
inline
std::ostream& operator<<(std::ostream& ostr, const PositionVector& vect){
ostr<<"I am a vector";
return ostr;
}
}
Swig interface file
//file:test.i
%module test
%{
#include "test.h"
%}
%ignore operator<<;
%include "test.h"
Result
[dmcnamara]$ swig -c++ -python -I/opt/vista_deps/include -I/opt/vista/include test.i
test.h:26: Error: '__lshift__' is multiply defined in the generated target language module in scope .
test.h:15: Error: Previous declaration of '__lshift__'
Upvotes: 1
Views: 1235
Reputation: 5201
You can also use the preprocessing tools :
//file:test.h
#include <iostream>
#include <boost/numeric/ublas/vector.hpp>
namespace probabilities{
typedef boost::numeric::ublas::vector< double > UnivariateTable;
#ifndef SWIG
inline
std::ostream& operator<<( std::ostream& ostr, const UnivariateTable& table){
ostr<<"I am a table";
return ostr;
}
#endif
}
namespace positions{
typedef boost::numeric::ublas::vector< double > PositionVector;
#ifndef SWIG
inline
std::ostream& operator<<(std::ostream& ostr, const PositionVector& vect){
ostr<<"I am a vector";
return ostr;
}
#endif
}
Upvotes: 1
Reputation: 8090
In the process of writing the question, I realized the answer:
you need to specify the namespaces for the %ignore
directives:
%ignore positions::operator<<
%ignore probabilities::operator<<
Upvotes: 3