Skip to content

Commit

Permalink
use datatypeinfo
Browse files Browse the repository at this point in the history
  • Loading branch information
fredroy committed Oct 11, 2024
1 parent 39cc454 commit f4b0c68
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions bindings/SofaTypes/src/SofaPython3/SofaTypes/Binding_Vec.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,17 +22,18 @@
#include <functional>
#include <pybind11/operators.h>
#include <sstream>
using sofa::type::Vec;

#define BINDING_VEC_MAKE_NAME(N, T) \
std::string(std::string("Vec") + std::to_string(N) + typeid(T).name())
#include <sofa/defaulttype/typeinfo/TypeInfo_Vec.h>

using sofa::type::Vec;

namespace pyVec {
namespace pyVec
{
template <sofa::Size N, class T> std::string __str__(const Vec<N, T> &v, bool repr)
{
std::stringstream s ;
s.imbue(std::locale("C"));
s << ((repr) ? (BINDING_VEC_MAKE_NAME(N, T) + "(") : ("("));
s << ((repr) ? (sofa::defaulttype::DataTypeInfo< Vec<N, T> >::name() + "(") : ("("));
s << v[0];
for (size_t i = 1; i < v.size(); ++i)
s << ", " << v[i];
Expand Down Expand Up @@ -86,7 +87,7 @@ template <sofa::Size N, class T>
py::class_<Vec<N,T>> addVec(py::module &m)
{
typedef Vec<N, T> VecClass;
py::class_<Vec<N, T>> p(m, BINDING_VEC_MAKE_NAME(N, T).c_str());
py::class_<Vec<N, T>> p(m, sofa::defaulttype::DataTypeInfo< Vec<N, T> >::name().c_str());

p.def(py::init<>()); // empty ctor
p.def(py::init<const VecClass &>()); // copy ctor
Expand Down

0 comments on commit f4b0c68

Please sign in to comment.