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