1%include <std/std_except.i>
2
3//
4// Use the following macro with modern STL implementations
5//
6//#define SWIG_STD_MODERN_STL
7//
8// Use this to deactive the previous definition, when using gcc-2.95
9// or similar old compilers.
10//
11//#define SWIG_STD_NOMODERN_STL
12
13// Here, we identify compilers we know have problems with STL.
14%{
15#if defined(__GNUC__)
16#  if __GNUC__ == 2 && __GNUC_MINOR <= 96
17#     define SWIG_STD_NOMODERN_STL
18#  endif
19#endif
20%}
21
22//
23// Common code for supporting the STD C++ namespace
24//
25
26%{
27#include <string>
28#include <stdexcept>
29%}
30
31
32%fragment("StdIteratorTraits","header") %{
33#if defined(__SUNPRO_CC) && defined(_RWSTD_VER)
34#  if !defined(SWIG_NO_STD_NOITERATOR_TRAITS_STL)
35#    define SWIG_STD_NOITERATOR_TRAITS_STL
36#  endif
37#endif
38
39#if !defined(SWIG_STD_NOITERATOR_TRAITS_STL)
40#include <iterator>
41#else
42namespace std {
43  template <class Iterator>
44  struct iterator_traits {
45    typedef ptrdiff_t difference_type;
46    typedef typename Iterator::value_type value_type;
47  };
48
49  template <class Iterator, class Category,class T, class Reference, class Pointer, class Distance>
50  struct iterator_traits<__reverse_bi_iterator<Iterator,Category,T,Reference,Pointer,Distance> > {
51    typedef Distance difference_type;
52    typedef T value_type;
53  };
54
55  template <class T>
56  struct iterator_traits<T*> {
57    typedef T value_type;
58    typedef ptrdiff_t difference_type;
59  };
60
61  template<typename _InputIterator>
62  inline typename iterator_traits<_InputIterator>::difference_type
63  distance(_InputIterator __first, _InputIterator __last)
64  {
65    typename iterator_traits<_InputIterator>::difference_type __n = 0;
66    while (__first != __last) {
67      ++__first; ++__n;
68    }
69    return __n;
70  }
71}
72#endif
73%}
74
75%fragment("StdTraitsCommon","header") %{
76namespace swig {
77  template <class Type>
78  struct noconst_traits {
79    typedef Type noconst_type;
80  };
81
82  template <class Type>
83  struct noconst_traits<const Type> {
84    typedef Type noconst_type;
85  };
86
87  /*
88    type categories
89  */
90  struct pointer_category { };
91  struct value_category { };
92
93  /*
94    General traits that provides type_name and type_info
95  */
96  template <class Type> struct traits { };
97
98  template <class Type>
99  inline const char* type_name() {
100    return traits<typename noconst_traits<Type >::noconst_type >::type_name();
101  }
102
103  template <class Type>
104  struct traits_info {
105    static swig_type_info *type_query(std::string name) {
106      name += " *";
107      return SWIG_TypeQuery(name.c_str());
108    }
109    static swig_type_info *type_info() {
110      static swig_type_info *info = type_query(type_name<Type>());
111      return info;
112    }
113  };
114
115  template <class Type>
116  inline swig_type_info *type_info() {
117    return traits_info<Type>::type_info();
118  }
119
120  /*
121    Partial specialization for pointers
122  */
123  template <class Type> struct traits <Type *> {
124    typedef pointer_category category;
125    static std::string make_ptr_name(const char* name) {
126      std::string ptrname = name;
127      ptrname += " *";
128      return ptrname;
129    }
130    static const char* type_name() {
131      static std::string name = make_ptr_name(swig::type_name<Type>());
132      return name.c_str();
133    }
134  };
135
136  template <class Type, class Category>
137  struct traits_as { };
138
139  template <class Type, class Category>
140  struct traits_check { };
141
142}
143%}
144
145/*
146  Generate the traits for a swigtype
147*/
148
149%define %traits_swigtype(Type...)
150%fragment(SWIG_Traits_frag(Type),"header",fragment="StdTraits") {
151  namespace swig {
152    template <>  struct traits<Type > {
153      typedef pointer_category category;
154      static const char* type_name() { return  #Type; }
155    };
156  }
157}
158%enddef
159
160
161
162/*
163  Generate the typemaps for a class that has 'value' traits
164*/
165
166%define %typemap_traits(Code,Type...)
167  %typemaps_asvalfrom(%arg(Code),
168		     %arg(swig::asval<Type >),
169		     %arg(swig::from),
170		     %arg(SWIG_Traits_frag(Type)),
171		     %arg(SWIG_Traits_frag(Type)),
172		     Type);
173%enddef
174
175/*
176  Generate the typemaps for a class that behaves more like a 'pointer' or
177  plain wrapped Swigtype.
178*/
179
180%define %typemap_traits_ptr(Code,Type...)
181  %typemaps_asptrfrom(%arg(Code),
182		     %arg(swig::asptr),
183		     %arg(swig::from),
184		     %arg(SWIG_Traits_frag(Type)),
185		     %arg(SWIG_Traits_frag(Type)),
186		     Type);
187%enddef
188
189
190/*
191  Equality methods
192*/
193%define %std_equal_methods(Type...)
194%extend Type {
195  bool operator == (const Type& v) {
196    return *self == v;
197  }
198
199  bool operator != (const Type& v) {
200    return *self != v;
201  }
202}
203
204%enddef
205
206/*
207  Order methods
208*/
209
210%define %std_order_methods(Type...)
211%extend Type {
212  bool operator > (const Type& v) {
213    return *self > v;
214  }
215
216  bool operator < (const Type& v) {
217    return *self < v;
218  }
219
220  bool operator >= (const Type& v) {
221    return *self >= v;
222  }
223
224  bool operator <= (const Type& v) {
225    return *self <= v;
226  }
227}
228%enddef
229
230/*
231  Comparison methods
232*/
233
234%define %std_comp_methods(Type...)
235%std_equal_methods(Type )
236%std_order_methods(Type )
237%enddef
238
239