/** * \file internal/swig_helpers.h * \brief Functions for use in swig wrappers * * Copyright 2007-2013 IMP Inventors. All rights reserved. */ #ifndef IMPKERNEL_INTERNAL_SWIG_HELPERS_H #define IMPKERNEL_INTERNAL_SWIG_HELPERS_H // Python.h must be included first #include #include "../Particle.h" #include "../ParticleTuple.h" #include "../Restraint.h" #include "../SingletonScore.h" #include "../macros.h" #include using namespace IMP; #ifndef SWIG template<> struct Convert: public ConvertObjectBase { static const int converter=2; template static Particle* get_cpp_object(PyObject *o, SwigData st, SwigData particle_st, SwigData decorator_st) { void *vp; int res=SWIG_ConvertPtr(o, &vp,particle_st, 0 ); Particle *p=nullptr; if (!SWIG_IsOK(res)) { int res=SWIG_ConvertPtr(o, &vp,decorator_st, 0 ); if (!SWIG_IsOK(res)) { IMP_THROW( "Not all objects in list have correct object type.", ValueException); } else { Decorator* d= reinterpret_cast(vp); if (*d) { p= d->get_particle(); } else { p=nullptr; } } } else { p= reinterpret_cast(vp); } if (p) { IMP_CHECK_OBJECT(static_cast(p)); } return p; } template static bool get_is_cpp_object(PyObject *o, SwigData st, SwigData particle_st, SwigData decorator_st) { try { get_cpp_object(o, st, particle_st, decorator_st); } catch (...) { return 0; } return 1; } }; template struct Convert, not_ > >::type >: public ConvertValueBase { static const int converter=3; template static T get_cpp_object(PyObject *o, SwigData st, SwigData particle_st, SwigData decorator_st) { Particle *p= Convert::get_cpp_object(o, particle_st, particle_st, decorator_st); if (!T::particle_is_instance(p)) { IMP_THROW( "Not all objects in list have correct object type: " << p->get_name(), ValueException); } return T(p); } template static bool get_is_cpp_object(PyObject *o, SwigData st, SwigData particle_st, SwigData decorator_st) { try { get_cpp_object(o, st, particle_st, decorator_st); } catch (...) { return 0; } return 1; } }; template struct Convert::type >: public ConvertValueBase { static const int converter=4; template static T get_cpp_object(PyObject *o, SwigData st, SwigData particle_st, SwigData decorator_st) { try { return ConvertValueBase::get_cpp_object(o, st, particle_st, decorator_st); } catch (ValueException) { Particle *p= Convert::get_cpp_object(o, particle_st, particle_st, decorator_st); if (!T::particle_is_instance(p)) { IMP_THROW( "Not all objects in list have correct object type: " << p->get_name(), ValueException); } return T(p); } } template static bool get_is_cpp_object(PyObject *o, SwigData st, SwigData particle_st, SwigData decorator_st) { try { get_cpp_object(o, st, particle_st, decorator_st); } catch (...) { return 0; } return 1; } }; #endif #endif /* IMPKERNEL_INTERNAL_SWIG_HELPERS_H */