2 // Use the following macro with modern STL implementations
4 //#define SWIG_STD_MODERN_STL
6 // Use this to deactive the previous definition, when using gcc-2.95
7 // or similar old compilers.
9 //#define SWIG_STD_NOMODERN_STL
11 // Here, we identify compilers we now have problems with STL.
14 # if __GNUC__ == 2 && __GNUC_MINOR <= 96
15 # define SWIG_STD_NOMODERN_STL
21 // Common code for supporting the STD C++ namespace
29 %fragment("Traits","header")
35 struct pointer_category { };
36 struct value_category { };
39 General traits that provides type_name and type_info
41 template <class Type> struct traits { };
44 inline const char* type_name() {
45 return traits<Type>::type_name();
50 static swig_type_info *type_query(std::string name) {
52 return SWIG_TypeQuery(name.c_str());
54 static swig_type_info *type_info() {
55 static swig_type_info *info = type_query(type_name<Type>());
61 inline swig_type_info *type_info() {
62 return traits_info<Type>::type_info();
66 Partial specialization for pointers
68 template <class Type> struct traits <Type *> {
69 typedef pointer_category category;
70 static std::string make_ptr_name(const char* name) {
71 std::string ptrname = name;
75 static const char* type_name() {
76 static std::string name = make_ptr_name(swig::type_name<Type>());
82 template <class Type, class Category = typename traits<Type>::category >
83 struct traits_check { };
86 Traits that provides the from method for an unknown type
88 template <int flags, class Type> struct traits_from_ptr {
89 static SWIG_Object from SWIG_FROM_DECL_ARGS(Type *val) {
90 return SWIG_NewPointerObj(val, type_info<Type>(), flags);
94 template <class Type> struct traits_from {
95 static SWIG_Object from SWIG_FROM_DECL_ARGS(const Type& val) {
96 return traits_from_ptr<SWIG_POINTER_OWN, Type>::from(new Type(val));
100 template <class Type> struct traits_from<Type *> {
101 static SWIG_Object from SWIG_FROM_DECL_ARGS(Type* val) {
102 return traits_from_ptr<0, Type>::from(val);
106 template <class Type>
107 inline SWIG_Object from SWIG_FROM_DECL_ARGS(const Type& val) {
108 return traits_from<Type>::from(val);
112 Traits that provides the asptr/asval method for an unknown type
114 template <class Type>
115 struct traits_asptr {
116 static int asptr SWIG_AS_DECL_ARGS (SWIG_Object obj, Type **val) {
118 int res = SWIG_ConvertPtr(obj, %as_voidptrptr(&p), type_info<Type>(), 0);
119 if (SWIG_IsOK(res) && val) *val = p;
124 template <class Type>
125 inline int asptr SWIG_AS_DECL_ARGS(SWIG_Object obj, Type **vptr) {
126 return traits_asptr<Type>::asptr SWIG_AS_CALL_ARGS(obj, vptr);
129 template <class Type>
130 struct traits_asval {
131 static int asval SWIG_AS_DECL_ARGS(SWIG_Object obj, Type *val) {
134 int res = traits_asptr<Type>::asptr SWIG_AS_CALL_ARGS(obj, &p);
135 if (SWIG_IsOK(res) && p) {
137 if (SWIG_IsNewObj(res)) {
139 res = SWIG_DelNewMask(res);
144 return traits_asptr<Type>::asptr SWIG_AS_CALL_ARGS(obj, (Type **)(0));
149 template <class Type>
150 inline int asval SWIG_AS_DECL_ARGS (SWIG_Object obj, Type *val) {
151 return traits_asval<Type>::asval SWIG_AS_CALL_ARGS(obj, val);
155 Traits that provides the check method for an unknown type
157 #define SWIG_CHECK_DECL_ARGS(obj) SWIG_AS_DECL_ARGS(obj, void * = 0)
158 #define SWIG_CHECK_CALL_ARGS(obj) SWIG_AS_CALL_ARGS(obj, 0)
160 template <class Type>
161 struct traits_checkval {
162 static int check SWIG_CHECK_DECL_ARGS(SWIG_Object obj) {
164 int res = asval SWIG_AS_CALL_ARGS(obj, (Type *)(0));
165 return SWIG_CheckState(res);
172 template <class Type>
173 struct traits_checkptr {
174 static int check SWIG_CHECK_DECL_ARGS(SWIG_Object obj) {
176 int res = asptr SWIG_AS_CALL_ARGS(obj, (Type **)(0));
177 return SWIG_CheckState(res);
184 template <class Type>
185 struct traits_check<Type, value_category> : traits_checkval<Type> {
188 template <class Type>
189 struct traits_check<Type, pointer_category> : traits_checkptr<Type> {
192 template <class Type>
193 inline int check SWIG_CHECK_DECL_ARGS(SWIG_Object obj) {
194 return traits_check<Type>::check SWIG_CHECK_CALL_ARGS(obj);
201 Generate the traits for an unknown SWIGTYPE
204 %define %traits_swigtype(Type...)
205 %fragment(SWIG_Traits_frag(Type),"header",fragment="Traits") {
207 template <> struct traits<Type > {
208 typedef pointer_category category;
209 static const char* type_name() { return #Type; }
217 Generate the traits for a 'value' type, such as 'double',
218 for which the SWIG_AsVal and SWIG_From methods are already defined.
221 %define %traits_value(Type...)
222 %fragment(SWIG_Traits_frag(Type),"header",
223 fragment=SWIG_AsVal_frag(Type),
224 fragment=SWIG_From_frag(Type),
227 template <> struct traits<Type > {
228 typedef value_category category;
229 static const char* type_name() { return #Type; }
232 template <> struct traits_asval<Type > {
233 typedef Type value_type;
234 static int asval SWIG_AS_DECL_ARGS (SWIG_Object obj, value_type *val) {
235 return SWIG_AsVal(Type)(obj, val);
239 template <> struct traits_from<Type > {
240 typedef Type value_type;
241 static SWIG_Object from SWIG_FROM_DECL_ARGS (const value_type& val) {
242 return SWIG_From(Type)(val);
250 Generate the traits for a 'pointer' type, such as 'std::string',
251 for which the SWIG_AsPtr and SWIG_From methods are already defined.
254 %define %traits_pointer(Type...)
255 %fragment(SWIG_Traits_frag(Type),"header",
256 fragment=SWIG_AsVal_frag(Type),
257 fragment=SWIG_From_frag(Type),
260 template <> struct traits<Type > {
261 typedef pointer_category category;
262 static const char* type_name() { return #Type; }
265 template <> struct traits_asptr<Type > {
266 typedef Type value_type;
267 static int asptr SWIG_AS_DECL_ARGS (SWIG_Object obj, value_type **val) {
268 return SWIG_AsPtr(Type)(obj, val);
272 template <> struct traits_from<Type > {
273 typedef Type value_type;
274 static SWIG_Object from SWIG_FROM_DECL_ARGS (const value_type& val) {
275 return SWIG_From(Type)(val);
283 Generate the typemaps for a class that has 'value' traits
286 %define %typemap_traits_value(Code,Type...)
287 %typemaps_asvalfrom(%arg(Code),
290 %arg(SWIG_Traits_frag(Type)),
291 %arg(SWIG_Traits_frag(Type)),
296 Generate the typemaps for a class that has 'pointer' traits
299 %define %typemap_traits_pointer(Code,Type...)
300 %typemaps_asptrfrom(%arg(Code),
303 %arg(SWIG_Traits_frag(Type)),
304 %arg(SWIG_Traits_frag(Type)),