~benjamik/dolfin/mesh-resolution

« back to all changes in this revision

Viewing changes to dolfin/swig/typemaps/std_pair.i

  • Committer: Johan Hake
  • Date: 2013-03-12 10:27:27 UTC
  • mfrom: (7505.1.3 vtk_out)
  • Revision ID: hake.dev@gmail.com-20130312102727-fulj3yev85070oo2
Merge work Python wrappers to timed VTK:
  Johan Hake 2013-03-12 Add Python wrappers to timed VTK output and added "unit tests" for all combinations

Show diffs side-by-side

added added

removed removed

Lines of Context:
17
17
// along with DOLFIN. If not, see <http://www.gnu.org/licenses/>.
18
18
//
19
19
// First added:  2011-01-25
20
 
// Last changed: 2013-03-08
 
20
// Last changed: 2013-03-12
21
21
 
22
22
//-----------------------------------------------------------------------------
23
23
// User macro for defining in typmaps for std::pair of a pointer to some
28
28
//-----------------------------------------------------------------------------
29
29
// Make SWIG aware of the shared_ptr version of TYPE
30
30
//-----------------------------------------------------------------------------
31
 
%types(SWIG_SHARED_PTR_QNAMESPACE::shared_ptr<TYPE>*);
32
 
 
33
 
//-----------------------------------------------------------------------------
34
 
// Run the macros for the combination of const and no const of
35
 
// {const} std::vector<{const} dolfin::TYPE *>
36
 
//-----------------------------------------------------------------------------
37
 
//IN_TYPEMAP_STD_VECTOR_OF_POINTERS(TYPE,,)
 
31
%types(SWIG_SHARED_PTR_QNAMESPACE::shared_ptr<TYPE >*);
 
32
//
 
33
////-----------------------------------------------------------------------------
 
34
//// Run the macros for the combination of const and no const of
 
35
//// {const} std::vector<{const} dolfin::TYPE *>
 
36
////-----------------------------------------------------------------------------
 
37
////IN_TYPEMAP_STD_VECTOR_OF_POINTERS(TYPE,,)
38
38
IN_TYPEMAP_STD_PAIR_OF_POINTER_AND_DOUBLE(TYPE,const,)
39
39
IN_TYPEMAP_STD_PAIR_OF_POINTER_AND_DOUBLE(TYPE,,const)
40
40
IN_TYPEMAP_STD_PAIR_OF_POINTER_AND_DOUBLE(TYPE,const,const)
53
53
//-----------------------------------------------------------------------------
54
54
%typecheck(SWIG_TYPECHECK_POINTER) CONST_PAIR std::pair<CONST dolfin::TYPE *, double>
55
55
{
56
 
  $1 = PyTuple_Check($input) ? 1 : 0;
 
56
 
 
57
  // TYPECHEK IN_TYPEMAP_STD_PAIR_OF_POINTER_AND_DOUBLE(TYPE, CONST, CONST_PAIR)
 
58
  $1 = 0;
 
59
  if (PyTuple_Check($input) && PyTuple_Size($input) == 2)
 
60
  {
 
61
    void* itemp = 0;
 
62
    PyObject* py_first  = PyTuple_GetItem($input, 0);
 
63
    int res = SWIG_ConvertPtr(py_first, &itemp, $descriptor(dolfin::TYPE *), 0);
 
64
    if (!SWIG_IsOK(res))
 
65
    {
 
66
      // If failed with normal pointer conversion then
 
67
      // try with shared_ptr conversion
 
68
      int newmem = 0;
 
69
      res = SWIG_ConvertPtrAndOwn(py_first, &itemp, $descriptor(SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< dolfin::TYPE > *), 0, &newmem);
 
70
      if (SWIG_IsOK(res))
 
71
      {
 
72
        $1 = 1;
 
73
        if (newmem & SWIG_CAST_NEW_MEMORY)
 
74
        {
 
75
          delete reinterpret_cast< SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< dolfin::TYPE > * >(itemp);
 
76
        }
 
77
      }
 
78
    }
 
79
    else
 
80
    {
 
81
      $1 = 1;
 
82
    }
 
83
  }
57
84
}
58
85
 
59
86
//-----------------------------------------------------------------------------
60
87
// The typemap
61
88
//-----------------------------------------------------------------------------
62
 
%typemap(in) CONST_PAIR std::pair<CONST dolfin::TYPE*, double> (std::pair<CONST dolfin::TYPE*, double> tmp_pair, SWIG_SHARED_PTR_QNAMESPACE::shared_ptr<dolfin::TYPE> tempshared, dolfin::TYPE * arg)
 
89
%typemap(in) CONST_PAIR std::pair<CONST dolfin::TYPE*, double> (std::pair<CONST dolfin::TYPE*, double> tmp_pair, SWIG_SHARED_PTR_QNAMESPACE::shared_ptr<dolfin::TYPE > tempshared, dolfin::TYPE * arg)
63
90
{
 
91
  // TYPEMAP IN_TYPEMAP_STD_PAIR_OF_POINTER_AND_DOUBLE(TYPE, CONST, CONST_PAIR)
64
92
  int res = 0;
65
93
  void* itemp = 0;
66
94
  int newmem = 0;
94
122
      // If we need to release memory
95
123
      if (newmem & SWIG_CAST_NEW_MEMORY)
96
124
      {
97
 
        tempshared = *reinterpret_cast< SWIG_SHARED_PTR_QNAMESPACE::shared_ptr<dolfin::TYPE> * >(itemp);
 
125
        tempshared = *reinterpret_cast< SWIG_SHARED_PTR_QNAMESPACE::shared_ptr<dolfin::TYPE > * >(itemp);
98
126
        delete reinterpret_cast< SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< dolfin::TYPE > * >(itemp);
99
127
        arg = const_cast< dolfin::TYPE * >(tempshared.get());
100
128
      }
119
147
// Run the different macros and instantiate the typemaps
120
148
//-----------------------------------------------------------------------------
121
149
IN_TYPEMAPS_STD_PAIR_OF_POINTER_AND_DOUBLE(Function)
122
 
IN_TYPEMAPS_STD_PAIR_OF_POINTER_AND_DOUBLE(MeshFunction)
123
 
IN_TYPEMAPS_STD_PAIR_OF_POINTER_AND_DOUBLE(MeshFunctionInt)
124
 
IN_TYPEMAPS_STD_PAIR_OF_POINTER_AND_DOUBLE(MeshFunctionSizet)
125
 
IN_TYPEMAPS_STD_PAIR_OF_POINTER_AND_DOUBLE(MeshFunctionDouble)
126
 
IN_TYPEMAPS_STD_PAIR_OF_POINTER_AND_DOUBLE(MeshFunctionBool)
 
150
IN_TYPEMAPS_STD_PAIR_OF_POINTER_AND_DOUBLE(Mesh)
 
151
IN_TYPEMAPS_STD_PAIR_OF_POINTER_AND_DOUBLE(MeshFunction<int>)
 
152
IN_TYPEMAPS_STD_PAIR_OF_POINTER_AND_DOUBLE(MeshFunction<std::size_t> )
 
153
IN_TYPEMAPS_STD_PAIR_OF_POINTER_AND_DOUBLE(MeshFunction<double> )
 
154
IN_TYPEMAPS_STD_PAIR_OF_POINTER_AND_DOUBLE(MeshFunction<bool>)
127
155
 
128
156
//-----------------------------------------------------------------------------
129
157
// In typemap for std::pair<TYPE,TYPE>