c++ - Cythonic way to wrap boost::geometry::Point accessors -
what correct cythonic way wrap following member functions of boost::geometry::point
? code snippet comes here.
/// @brief coordinate /// @tparam k coordinate /// @return coordinate template <std::size_t k> inline coordinatetype const& get() const { #if defined(boost_geometry_enable_access_debugging) boost_geometry_assert(m_created == 1); boost_geometry_assert(m_values_initialized[k] == 1); #endif boost_static_assert(k < dimensioncount); return m_values[k]; } /// @brief set coordinate /// @tparam k coordinate set /// @param value value set template <std::size_t k> inline void set(coordinatetype const& value) { #if defined(boost_geometry_enable_access_debugging) boost_geometry_assert(m_created == 1); m_values_initialized[k] = 1; #endif boost_static_assert(k < dimensioncount); m_values[k] = value; }
i first attempted using:
cdef extern "s57/data/geometries.h" namespace "bg::model": cdef cppclass _geo2 "bg::model::point<double, 2, bg::cs::spherical_equatorial<bg::degree>>": _geo2() _geo2( const _geo2& other ) const double get[size_t]() except + void set[size_t](double) except +
but don't know go since this:
property x: def __set__(self, double value): deref(self._p).set[0](value)
gives me failure:
error compiling cython file: ------------------------------------------------------------ ... property x: def __set__(self, double value): deref(self._p).set[0](value) ^ ------------------------------------------------------------ c:\xxxx\x.pyx:24:31: not parsable type
my current working solution has been create helper functions like:
double get_geo2_x( geo2& pnt ); double get_geo2_y( geo2& pnt ); void set_geo2_x( geo2& pnt, double value ); void set_geo2_y( geo2& pnt, double value );
does have in mind more elegant solution?
you're running problems cython's handling of non-type template parameters. can manually specify function names using strings, inserted directly generated c code (see http://docs.cython.org/src/userguide/external_c_code.html#resolving-naming-conflicts-c-name-specifications)
as simple example
// example.hpp #include <iostream> class c { template <int k> void set(double value) { std::cout << k << ": " << value << std::endl; }
and cython code
cdef extern "example.hpp": cdef cppclass c: void set0 "set<0>"(double) except + void set1 "set<1>"(double) except + def do_set(): # simple illustrative example cdef c c c.set0(1.0) c.set1(1.5) }
whenever cython sees set0
called on c
substitutes set<0>
, calling template function directly. can use properties, trying do.
this isn't better creating helper functions, might little easier.
Comments
Post a Comment