Vegastrike 0.5.1 rc1  1.0
Original sources for Vegastrike Evolved
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
init.h
Go to the documentation of this file.
1 //#define HAVE_PYTHON
2 #include "config.h"
3 
4 #ifdef HAVE_PYTHON
5 #ifndef PY_INIT_H_
6 #define PY_INIT_H_
7 #include "gfx/vec.h"
8 #include <boost/version.hpp>
9 #if BOOST_VERSION != 102800
10 #if defined (_MSC_VER) && _MSC_VER <= 1200
11 #define Vector Vactor
12 #endif
13 #include "cs_boostpython.h"
14 #if defined (_MSC_VER) && _MSC_VER <= 1200
15 #undef Vector
16 #endif
17 #else
18 #include <boost/python/detail/extension_class.hpp>
19 #endif
20 class Python
21 {
22 public:
23  static void init();
24  static void initpaths();
25  static void test();
26  static void reseterrors();
27 };
28 
29 BOOST_PYTHON_BEGIN_CONVERSION_NAMESPACE
30 #if BOOST_VERSION != 102800
31 /*
32  * typedef boost::tuples::tuple<double,double,double> python_wector;
33  * struct to_python <Vector> {
34  * inline PyObject *operator () (const Vector &vec) const{
35  * boost::python::to_python<boost::python::tuple> a();
36  * return a.convert(boost::python::make_tuple((double)vec.i,(double)vec.j,(double)vec.k));
37  * }
38  * };
39  */
40 struct my_builtin_to_python
41 {
42  BOOST_STATIC_CONSTANT( bool, uses_registry = false );
43 };
44 
45 #ifndef BOOST_PYTHON_TO_PYTHON_BY_VALUE
46 # define BOOST_PYTHON_RETURN_TO_PYTHON_BY_VALUE( T, expr ) \
47  template < class MYTYPE > \
48  struct to_python_value; \
49  template < > \
50  struct to_python_value< T& >: \
51  my_builtin_to_python \
52  { \
53  inline PyObject* operator()( T const &x ) const \
54  { \
55  return expr; \
56  } \
57  }; \
58  template < > \
59  struct to_python_value< T const& >: \
60  my_builtin_to_python \
61  { \
62  inline PyObject* operator()( T const &x ) const \
63  { \
64  return expr; \
65  } \
66  };
67 
68 # define BOOST_PYTHON_ARG_TO_PYTHON_BY_VALUE( T, expr ) \
69  namespace converter \
70  { \
71  template < class MYTYPE > \
72  struct arg_to_python; \
73  template < > \
74  struct arg_to_python< T >: \
75  ::boost::python::handle< > \
76  { \
77  arg_to_python( T const&x ) : \
78  ::boost::python::handle< > ( expr ) {} \
79  }; \
80  }
81 
82 //Specialize argument and return value converters for T using expr
83 # define BOOST_PYTHON_TO_PYTHON_BY_VALUE( T, expr ) \
84  BOOST_PYTHON_RETURN_TO_PYTHON_BY_VALUE( T, expr ) \
85  BOOST_PYTHON_ARG_TO_PYTHON_BY_VALUE( T, expr )
86 #endif
88  boost::python::to_python_value< boost::python::tuple > () ( boost::python::make_tuple( (double)
89  x.i,
90  (double)
91  x.j,
92  (double)
93  x.k ) ) );
95  boost::python::to_python_value< boost::python::tuple > () ( boost::python::make_tuple( (double)
96  x.i,
97  (double)
98  x.j,
99  (double)
100  x.k ) ) );
101 #else
102 inline PyObject * to_python( Vector vec )
103 {
104  return to_python( boost::python::tuple( (double) vec.i, (double) vec.j, (double) vec.k ) );
105 }
106 inline PyObject * to_python( QVector vec )
107 {
108  return to_python( boost::python::tuple( (double) vec.i, (double) vec.j, (double) vec.k ) );
109 }
110 
111 inline Vector from_python( PyObject *p, boost::python::type< Vector >)
112 {
113  Vector vec( 0, 0, 0 );
114  PyArg_ParseTuple( p, "fff", &vec.i, &vec.j, &vec.k );
115  return vec;
116 }
117 inline QVector from_python( PyObject *p, boost::python::type< QVector >)
118 {
119  QVector vec( 0, 0, 0 );
120  PyArg_ParseTuple( p, "ddd", &vec.i, &vec.j, &vec.k );
121  return vec;
122 }
123 #endif
124 BOOST_PYTHON_END_CONVERSION_NAMESPACE
125 
126 void InitBriefing();
127 void InitDirector();
128 void InitVS();
129 void InitBase();
130 
131 #endif
132 
133 #endif
134