Hello list,
What is the preferred (or best) way to get access to the underlying
C Datatypes of the octave integer Arrays?
I am using an int32NDArray and would like to retrieve a pointer to
int32_t which is the internal datatype. The member functions data() and
fortran_vec() return pointers to the octave_int32 type, which does not
behave like a C integer (which is in my case necessary).
One solution that (at least syntactically) works is to use
reinterpret_cast<>, but it there a more elegant solution?
Imagine C++ Code like:
#include <octave/oct.h>
#include <octave/oct-intytpes.h>
template <class T> int foo( const T* pIN, size_t len_in, T* pOUT ) {
// do something in here...
// T must be a built-in C integer type
}
DEFUN_DLD( foo, args, , "out=foo(in)" ) {
int32NDArray sigin( args(0).array_value() );
unsigned int len_sigin = args(0).length();
int32NDArray sigout( dim_vector(len_sigin, 1), 0 );
// IS THIS THE PREFERRED WAY ??
const int32_t* pIN = reinterpret_cast<const int32_t*>( sigin.data() );
int32_t* pOUT = reinterpret_cast<int32_t*>( sigout.fortran_vec() );
// call template
unsigned int t = foo( pIN, len_sigin, pOUT );
...
}
thanks for hints
benjamin