~ubuntu-branches/ubuntu/maverick/swig1.3/maverick

« back to all changes in this revision

Viewing changes to Lib/std/std_common.i

  • Committer: Bazaar Package Importer
  • Author(s): Adam Conrad
  • Date: 2005-09-01 18:35:55 UTC
  • mfrom: (2.1.1 sarge)
  • Revision ID: james.westby@ubuntu.com-20050901183555-eq59uwhq8b62e44c
Tags: 1.3.24-1ubuntu4
* Use php5-dev instead of php4-dev, to kick php4 out of main.
* Drop support for generation of pike bindings, as nothing uses it,
  and swig is the only thing keeping pike7.6 in main (Ubuntu #13796)

Show diffs side-by-side

added added

removed removed

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