ReFRACtor
swig_to_python.h
Go to the documentation of this file.
1 #ifndef SWIG_TO_PYTHON_H
2 #define SWIG_TO_PYTHON_H
4 
5 // Define this to get diagnostic messages printed out
6 //#define SWIG_TYPE_MAPPER_DIAGNOSTIC
7 namespace FullPhysics {
8 //-----------------------------------------------------------------------
10 //-----------------------------------------------------------------------
11 
12 template<typename T> inline PyObject*
14 {
15 
16 //-----------------------------------------------------------------------
17 // If pointer is Null, return None.
18 //-----------------------------------------------------------------------
19 
20  if(!V)
21  return Py_None;
22 
23 //-----------------------------------------------------------------------
24 // If underlying object is a python object wrapped in a
25 // Swig::Director, return the underlying python object
26 //-----------------------------------------------------------------------
27 
28  Swig::Director* d = dynamic_cast<Swig::Director*>(V.get());
29  if(d) {
30 #ifdef SWIG_TYPE_MAPPER_DIAGNOSTIC
31  std::cerr << "Return underlying python object\n";
32 #endif
33  return d->swig_get_self();
34  }
35 
36 //-----------------------------------------------------------------------
37 // See if underlying type is registered in swig_type_map. If so, return the
38 // underlying type
39 //-----------------------------------------------------------------------
40 
41  T& t(*V.get());
42  type_index tid(typeid(t));
43 #ifdef SWIG_TYPE_MAPPER_DIAGNOSTIC
44  std::cerr << tid.name() << "\n";
45 #endif
46  if(swig_type_map.count(tid) != 0) {
47 #ifdef SWIG_TYPE_MAPPER_DIAGNOSTIC
48  std::cerr << "Trying to_python for " << tid.name() << "\n";
49 #endif
50  return swig_type_map[tid]->to_python(V);
51  }
52 
53 //-----------------------------------------------------------------------
54 // Otherwise, fall back to returning the type T.
55 //-----------------------------------------------------------------------
56 
57 #ifdef SWIG_TYPE_MAPPER_DIAGNOSTIC
58  std::cerr << "Returning most general type\n";
59 #endif
60  return swig_type_map[typeid(T)]->to_python(V);
61 }
62 
63 inline PyObject*
65 {
66 //-----------------------------------------------------------------------
67 // If pointer is Null, return None.
68 //-----------------------------------------------------------------------
69 
70  if(!V)
71  return Py_None;
72 
73 //-----------------------------------------------------------------------
74 // If underlying object is a python object wrapped in a
75 // Swig::Director, return the underlying python object
76 //-----------------------------------------------------------------------
77 
78  Swig::Director* d = dynamic_cast<Swig::Director*>(V.get());
79  if(d) {
80 #ifdef SWIG_TYPE_MAPPER_DIAGNOSTIC
81  std::cerr << "Return underlying python object\n";
82 #endif
83  return d->swig_get_self();
84  }
85 
86 //-----------------------------------------------------------------------
87 // See if underlying type is registered in swig_type_map. If so, return the
88 // underlying type
89 //-----------------------------------------------------------------------
90 
91  GenericObject& t(*V.get());
92  type_index tid(typeid(t));
93 #ifdef SWIG_TYPE_MAPPER_DIAGNOSTIC
94  std::cerr << tid.name() << "\n";
95 #endif
96  if(swig_type_map.count(tid) != 0) {
97 #ifdef SWIG_TYPE_MAPPER_DIAGNOSTIC
98  std::cerr << "Trying to_python for " << tid.name() << "\n";
99 #endif
100  return swig_type_map[tid]->to_python(V);
101  }
102 
103 //-----------------------------------------------------------------------
104 // Otherwise, return Py_None
105 //-----------------------------------------------------------------------
106 
107 #ifdef SWIG_TYPE_MAPPER_DIAGNOSTIC
108  std::cerr << "Returning None\n";
109 #endif
110  return Py_None;
111 }
112 
113 template<typename T> inline PyObject*
115 { return swig_to_python(*V); }
116 }
117 #endif
PyObject * swig_to_python_or_none(const boost::shared_ptr< GenericObject > &V)
PyObject * swig_to_python(const boost::shared_ptr< T > &V)
Function to map from a shared point to a python object.
std::map< type_index, boost::shared_ptr< SwigTypeMapperBase > > swig_type_map
Map to go from type_index to the SwigTypeMapperBase object associated with it.
Contains classes to abstract away details in various Spurr Radiative Transfer software.
Definition: doxygen_python.h:1
For use with SWIG, it is useful to have a base class that everything can be cast to.
This is a wrapper around std::type_info that allows it to be used as an index in a associative contai...
Definition: fp_type_index.h:20

Copyright © 2017, California Institute of Technology.
ALL RIGHTS RESERVED.
U.S. Government Sponsorship acknowledged.
Generated Fri Aug 24 2018 15:44:11