Common.h 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. #ifndef ANKI_SCRIPT_COMMON_H
  2. #define ANKI_SCRIPT_COMMON_H
  3. /// @file
  4. /// This file is included by all the *.bpi.cpp files
  5. #include <boost/python.hpp>
  6. #include <boost/python/suite/indexing/vector_indexing_suite.hpp>
  7. namespace anki
  8. {}
  9. using namespace boost;
  10. using namespace boost::python;
  11. using namespace anki;
  12. /// Wrap a class
  13. #define ANKI_WRAP(x) \
  14. void boostPythonWrap##x()
  15. /// Wrap a singleton class
  16. #define ANKI_WRAP_SINGLETON(x) \
  17. WRAP(x) { \
  18. class_<x, noncopyable>(#x, no_init) \
  19. .def("get", & x ::get, \
  20. return_value_policy<reference_existing_object>()) \
  21. .staticmethod("get") \
  22. ; \
  23. }
  24. #define ANKI_WRAP_CONTAINER(x) \
  25. class_<x >(#x) \
  26. .def(vector_indexing_suite<x >()) \
  27. ;
  28. #define ANKI_CALL_WRAP(x) extern void boostPythonWrap##x(); boostPythonWrap##x()
  29. //==============================================================================
  30. // Property for simple types =
  31. //==============================================================================
  32. template<typename ClassType, typename RetType,
  33. const RetType& (ClassType::* accessor)() const>
  34. RetType getterSv(const ClassType* t)
  35. {
  36. return (t->*accessor)();
  37. }
  38. template<typename ClassType, typename InType,
  39. void (ClassType::* accessor)(const InType&)>
  40. void setterSv(ClassType* t, InType in)
  41. {
  42. (t->*accessor)(in);
  43. }
  44. /// Boost python property for simple types (int, float etc) that cannot be
  45. /// wrapped by boost::python correctly
  46. #define BP_PROPERTY_BASIC_TYPE(Type__, Class__, var__, getter__, setter__) \
  47. .add_property(#var__, &getterSv<Class__, Type__, &Class__::getter__>, \
  48. &setterSv<Class__, Type__, &Class__::setter__>)
  49. #endif