Skip to content
Snippets Groups Projects

Version 1.2

Merged Adrien Crovato requested to merge adri into master
3 files
+ 36
9
Compare changes
  • Side-by-side
  • Inline
Files
3
+ 32
7
@@ -91,6 +91,9 @@ threads="1"
// SDPM typemaps
%include "sdpm_def.h" // needed to access USE_CODI in SWIG interface
#ifndef USE_CODI
typedef double sdpmDouble; // needed so that SWIG does not convert sdpmDouble to double
#endif
%typemap(out) sdpmDouble {
#ifndef USE_CODI
$result = PyFloat_FromDouble($1);
@@ -107,6 +110,14 @@ threads="1"
%template(std_vector_Elementp) std::vector<sdpm::Element *>;
%template(std_vector_Tagp) std::vector<sdpm::Tag *>;
%template(std_map_string_Tagp) std::map<std::string, sdpm::Tag *>;
%template(std_vector_vector3d) std::vector<sdpmVector3d>;
#ifndef USE_CODI
%rename(std_vector_double) std::vector<sdpmDouble>;
%rename(std_vector_vector_double) std::vector<std::vector<sdpmDouble>>;
#else
%template(std_vector_sdpmdouble) std::vector<sdpmDouble>;
%template(std_vector_vector_sdpmdouble) std::vector<std::vector<sdpmDouble>>;
#endif
// SDPM
%include "sdpm.h"
@@ -136,26 +147,40 @@ threads="1"
// Interface to SDPM types
class sdpmVector3d {};
%extend sdpmVector3d {
double getitem(int i)
double __getitem__(int i)
{
if (i > 2)
throw std::runtime_error("sdpmVector3d: index out of range (size 3)!\n");
#ifndef USE_CODI
return (*self)(i);
#else
return (*self)(i).getValue();
#endif
}
std::string __str__()
// use repr instead of str so that iterables also print nicely
std::string __repr__()
{
std::ostringstream out; out << *self; return out.str();
std::ostringstream out; out << *self;
return out.str();
}
}
%pythoncode {
def __getitem__(self, idx):
return self.getitem(idx)
#ifdef USE_CODI
class sdpmDouble {};
%extend sdpmDouble {
double __float__()
{
return (*self).getValue();
}
// use repr instead of str so that iterables also print nicely
std::string __repr__()
{
std::ostringstream out; out << *self;
return out.str();
}
}
#endif
// Interface to SDPM classes
namespace sdpm {
Loading