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

« back to all changes in this revision

Viewing changes to Lib/python/director_h.swg

  • Committer: Bazaar Package Importer
  • Author(s): Adam Conrad
  • Date: 2005-12-05 01:16:04 UTC
  • mfrom: (1.2.2 upstream)
  • Revision ID: james.westby@ubuntu.com-20051205011604-ygx904it6413k3go
Tags: 1.3.27-1ubuntu1
Resynchronise with Debian again, for the new subversion packages.

Show diffs side-by-side

added added

removed removed

Lines of Context:
12
12
#ifdef __cplusplus
13
13
 
14
14
#include <string>
15
 
 
16
 
extern "C" {
17
 
  struct swig_type_info;
18
 
}
19
 
 
 
15
#include <iostream>
 
16
#include <exception>
 
17
 
 
18
 
 
19
/*
 
20
  Use -DSWIG_DIRECTOR_NOUEH if you prefer to avoid the use of the
 
21
  Undefined Exception Handler provided by swift
 
22
*/
 
23
#ifndef SWIG_DIRECTOR_NOUEH
 
24
#ifndef SWIG_DIRECTOR_UEH
 
25
#define SWIG_DIRECTOR_UEH
 
26
#endif
 
27
#endif
 
28
 
 
29
 
 
30
/*
 
31
  Use -DSWIG_DIRECTOR_STATIC if you prefer to avoid the use of the
 
32
  'Swig' namespace. This could be usefull for multi-modules projects.
 
33
*/
20
34
#ifdef SWIG_DIRECTOR_STATIC
21
35
/* Force anonymous (static) namespace */
22
36
#define Swig
23
37
#endif
24
38
 
 
39
 
 
40
/*
 
41
  Use -DSWIG_DIRECTOR_NORTTI if you prefer to avoid the use of the
 
42
  native C++ RTTI and dynamic_cast<>. But be aware that directors
 
43
  could stop working when using this option.
 
44
*/
 
45
#ifdef SWIG_DIRECTOR_NORTTI
 
46
/* 
 
47
   When we don't use the native C++ RTTI, we implement a minimal one
 
48
   only for Directors.
 
49
*/
 
50
# ifndef SWIG_DIRECTOR_RTDIR
 
51
# define SWIG_DIRECTOR_RTDIR
 
52
#include <map>
25
53
namespace Swig {
 
54
  class Director;
 
55
  SWIGINTERN std::map<void*,Director*>& get_rtdir_map() {
 
56
    static std::map<void*,Director*> rtdir_map;
 
57
    return rtdir_map;
 
58
  }
 
59
 
 
60
  SWIGINTERNINLINE void set_rtdir(void *vptr, Director *rtdir) {
 
61
    get_rtdir_map()[vptr] = rtdir;
 
62
  }
 
63
 
 
64
  SWIGINTERNINLINE Director *get_rtdir(void *vptr) {
 
65
    std::map<void*,Director*>::const_iterator pos = get_rtdir_map().find(vptr);
 
66
    Director *rtdir = (pos != get_rtdir_map().end()) ? pos->second : 0;
 
67
    return rtdir;
 
68
  }
 
69
}
 
70
# endif /* SWIG_DIRECTOR_RTDIR */
 
71
 
 
72
# define SWIG_DIRECTOR_CAST(Arg) Swig::get_rtdir(static_cast<void*>(Arg))
 
73
# define SWIG_DIRECTOR_RGTR(Arg1, Arg2) Swig::set_rtdir(static_cast<void*>(Arg1), Arg2)
 
74
 
 
75
#else
 
76
 
 
77
# define SWIG_DIRECTOR_CAST(Arg) dynamic_cast<Swig::Director*>(Arg)
 
78
# define SWIG_DIRECTOR_RGTR(Arg1, Arg2)
 
79
 
 
80
#endif /* SWIG_DIRECTOR_NORTTI */
 
81
 
 
82
extern "C" {
 
83
  struct swig_type_info;
 
84
}
 
85
 
 
86
namespace Swig {  
 
87
 
26
88
  /* base class for director exceptions */
27
89
  class DirectorException {
28
 
    protected:
29
 
      std::string swig_msg;
30
 
    public:
31
 
      DirectorException(const char* msg="") {
32
 
      }
33
 
      const char *getMessage() const { 
34
 
        return swig_msg.c_str(); 
35
 
      }
36
 
    virtual ~DirectorException();
37
 
    
 
90
  protected:
 
91
    std::string swig_msg;
 
92
  public:
 
93
    DirectorException(const char* hdr ="", const char* msg ="") 
 
94
    : swig_msg(hdr) {
 
95
      swig_msg += msg;
 
96
      if (!PyErr_Occurred()) {
 
97
        PyErr_SetString(PyExc_TypeError, getMessage());
 
98
      } else {
 
99
        SWIG_Python_AddErrMesg(getMessage(), 1);
 
100
      }
 
101
    }
 
102
 
 
103
    const char *getMessage() const { 
 
104
      return swig_msg.c_str(); 
 
105
    }
 
106
 
 
107
    static void raise(const char* msg = "") 
 
108
    {
 
109
      throw DirectorException(msg);
 
110
    }
 
111
  };
 
112
 
 
113
  class UnknownExceptionHandler 
 
114
  {
 
115
    static void handler();
 
116
    
 
117
  public:
 
118
    
 
119
#ifdef SWIG_DIRECTOR_UEH
 
120
    std::unexpected_handler old;
 
121
    UnknownExceptionHandler(std::unexpected_handler nh = handler)
 
122
    {
 
123
      old = std::set_unexpected(nh);
 
124
    }
 
125
 
 
126
    ~UnknownExceptionHandler()
 
127
    {
 
128
      std::set_unexpected(old);
 
129
    }
 
130
#endif
38
131
  };
39
132
 
40
133
  /* type mismatch in the return value from a python method call */
41
134
  class DirectorTypeMismatchException : public Swig::DirectorException {
42
 
    public:
43
 
      DirectorTypeMismatchException(const char* msg="") {
44
 
        swig_msg = "Swig director type mismatch: ";
45
 
        swig_msg += msg;
46
 
        PyErr_SetString(PyExc_TypeError, getMessage());
47
 
      }
 
135
  public:
 
136
    DirectorTypeMismatchException(const char* msg="") 
 
137
      : Swig::DirectorException("Swig director type mismatch: ", msg) {
 
138
    }
 
139
 
 
140
    static void raise(const char* msg = "") 
 
141
    {
 
142
      throw DirectorTypeMismatchException(msg);
 
143
    }
48
144
  };
49
145
 
50
146
  /* any python exception that occurs during a director method call */
51
 
  class DirectorMethodException : public Swig::DirectorException {};
 
147
  class DirectorMethodException : public Swig::DirectorException {
 
148
  public:
 
149
    DirectorMethodException(const char* msg = "") 
 
150
      : DirectorException("Swig director python method error: ", msg)
 
151
    {
 
152
    }    
 
153
 
 
154
    static void raise(const char* msg = "") 
 
155
    {
 
156
      throw DirectorMethodException(msg);
 
157
    }
 
158
  };
52
159
 
53
160
  /* attempt to call a pure virtual method via a director method */
54
 
  class DirectorPureVirtualException : public Swig::DirectorException {};
 
161
  class DirectorPureVirtualException : public Swig::DirectorException
 
162
  {
 
163
  public:
 
164
    DirectorPureVirtualException(const char* msg = "") 
 
165
      : DirectorException("Swig director pure virtal method called: ", msg)
 
166
    { 
 
167
    }
 
168
 
 
169
    static void raise(const char* msg = "") 
 
170
    {
 
171
      throw DirectorPureVirtualException(msg);
 
172
    }
 
173
  };
55
174
 
56
175
 
57
176
  /* simple thread abstraction for pthreads on win32 */
71
190
 
72
191
  /* director base class */
73
192
  class Director {
74
 
    private:
75
 
      /* pointer to the wrapped python object */
76
 
      PyObject* swig_self;
77
 
      /* flag indicating whether the object is owned by python or c++ */
78
 
      mutable bool swig_disown_flag;
79
 
      /* shared flag for breaking recursive director calls */
80
 
      static bool swig_up;
 
193
  private:
 
194
    /* pointer to the wrapped python object */
 
195
    PyObject* swig_self;
 
196
    /* flag indicating whether the object is owned by python or c++ */
 
197
    mutable bool swig_disown_flag;
 
198
    /* shared flag for breaking recursive director calls */
 
199
    static bool swig_up;
81
200
 
82
201
#ifdef __PTHREAD__
83
 
      /* locks for sharing the swig_up flag in a threaded environment */
84
 
      static pthread_mutex_t swig_mutex_up;
85
 
      static bool swig_mutex_active;
86
 
      static pthread_t swig_mutex_thread;
 
202
    /* locks for sharing the swig_up flag in a threaded environment */
 
203
    static pthread_mutex_t swig_mutex_up;
 
204
    static bool swig_mutex_active;
 
205
    static pthread_t swig_mutex_thread;
87
206
#endif
88
207
 
89
 
      /* decrement the reference count of the wrapped python object */
90
 
      void swig_decref() const { 
91
 
        if (swig_disown_flag) {
92
 
          Py_DECREF(swig_self); 
93
 
        }
 
208
    /* decrement the reference count of the wrapped python object */
 
209
    void swig_decref() const { 
 
210
      if (swig_disown_flag) {
 
211
        Py_DECREF(swig_self); 
94
212
      }
 
213
    }
95
214
 
96
 
      /* reset the swig_up flag once the routing direction has been determined */
 
215
    /* reset the swig_up flag once the routing direction has been determined */
97
216
#ifdef __PTHREAD__
98
 
      void swig_clear_up() const { 
99
 
        Swig::Director::swig_up = false; 
100
 
        Swig::Director::swig_mutex_active = false;
101
 
        pthread_mutex_unlock(&swig_mutex_up);
102
 
      }
 
217
    void swig_clear_up() const { 
 
218
      Swig::Director::swig_up = false; 
 
219
      Swig::Director::swig_mutex_active = false;
 
220
      pthread_mutex_unlock(&swig_mutex_up);
 
221
    }
103
222
#else
104
 
      void swig_clear_up() const { 
105
 
        Swig::Director::swig_up = false; 
106
 
      }
107
 
#endif
108
 
 
109
 
    public:
110
 
      /* wrap a python object, optionally taking ownership */
111
 
      Director(PyObject* self) : swig_self(self), swig_disown_flag(false) {
112
 
        swig_incref();
113
 
      }
114
 
 
115
 
      /* discard our reference at destruction */
116
 
      virtual ~Director();
117
 
 
118
 
      /* return a pointer to the wrapped python object */
119
 
      PyObject *swig_get_self() const { 
120
 
        return swig_self; 
121
 
      }
122
 
 
123
 
      /* get the swig_up flag to determine if the method call should be routed
124
 
       * to the c++ base class or through the wrapped python object
125
 
       */
126
 
#ifdef __PTHREAD__
127
 
      bool swig_get_up() const { 
128
 
        if (Swig::Director::swig_mutex_active) {
129
 
          if (pthread_equal(Swig::Director::swig_mutex_thread, pthread_self())) {
130
 
            bool up = swig_up;
131
 
            swig_clear_up();
132
 
            return up;
133
 
          }
134
 
        }
135
 
        return 0;
136
 
      }
137
 
#else 
138
 
      bool swig_get_up() const { 
139
 
        bool up = swig_up;
140
 
        swig_up = false;
141
 
        return up;
142
 
      }
143
 
#endif
144
 
 
145
 
      /* set the swig_up flag if the next method call should be directed to
146
 
       * the c++ base class rather than the wrapped python object
147
 
       */
148
 
#ifdef __PTHREAD__
149
 
      void swig_set_up() const { 
150
 
        pthread_mutex_lock(&Swig::Director::swig_mutex_up);
151
 
        Swig::Director::swig_mutex_thread = pthread_self();
152
 
        Swig::Director::swig_mutex_active = true;
153
 
        Swig::Director::swig_up = true; 
154
 
      }
155
 
#else 
156
 
      void swig_set_up() const { 
157
 
        Swig::Director::swig_up = true; 
158
 
      }
159
 
#endif
160
 
 
161
 
      /* acquire ownership of the wrapped python object (the sense of "disown"
162
 
       * is from python) */
163
 
      void swig_disown() const { 
164
 
        if (!swig_disown_flag) { 
165
 
          swig_disown_flag=true;
166
 
          swig_incref(); 
167
 
        } 
168
 
      }
169
 
 
170
 
      /* increase the reference count of the wrapped python object */
171
 
      void swig_incref() const { 
172
 
        if (swig_disown_flag) {
173
 
          Py_INCREF(swig_self); 
174
 
        }
175
 
      }
176
 
 
177
 
      /* methods to implement pseudo protected director members */
178
 
      virtual bool swig_get_inner(const char* name) const {
179
 
        return true;
180
 
      }
181
 
 
182
 
      virtual void swig_set_inner(const char* name, bool val) const {
183
 
      }
 
223
    void swig_clear_up() const { 
 
224
      Swig::Director::swig_up = false; 
 
225
    }
 
226
#endif
 
227
 
 
228
  public:
 
229
    /* wrap a python object, optionally taking ownership */
 
230
    Director(PyObject* self) : swig_self(self), swig_disown_flag(false) {
 
231
      swig_incref();
 
232
    }
 
233
 
 
234
    /* discard our reference at destruction */
 
235
    virtual ~Director();
 
236
 
 
237
    /* return a pointer to the wrapped python object */
 
238
    PyObject *swig_get_self() const { 
 
239
      return swig_self; 
 
240
    }
 
241
 
 
242
    /* get the swig_up flag to determine if the method call should be routed
 
243
     * to the c++ base class or through the wrapped python object
 
244
     */
 
245
#ifdef __PTHREAD__
 
246
    bool swig_get_up() const { 
 
247
      if (Swig::Director::swig_mutex_active) {
 
248
        if (pthread_equal(Swig::Director::swig_mutex_thread, pthread_self())) {
 
249
          bool up = swig_up;
 
250
          swig_clear_up();
 
251
          return up;
 
252
        }
 
253
      }
 
254
      return 0;
 
255
    }
 
256
#else 
 
257
    bool swig_get_up() const { 
 
258
      bool up = swig_up;
 
259
      swig_up = false;
 
260
      return up;
 
261
    }
 
262
#endif
 
263
 
 
264
    /* set the swig_up flag if the next method call should be directed to
 
265
     * the c++ base class rather than the wrapped python object
 
266
     */
 
267
#ifdef __PTHREAD__
 
268
    void swig_set_up() const { 
 
269
      pthread_mutex_lock(&Swig::Director::swig_mutex_up);
 
270
      Swig::Director::swig_mutex_thread = pthread_self();
 
271
      Swig::Director::swig_mutex_active = true;
 
272
      Swig::Director::swig_up = true; 
 
273
    }
 
274
#else 
 
275
    void swig_set_up() const { 
 
276
      Swig::Director::swig_up = true; 
 
277
    }
 
278
#endif
 
279
 
 
280
    /* acquire ownership of the wrapped python object (the sense of "disown"
 
281
     * is from python) */
 
282
    void swig_disown() const { 
 
283
      if (!swig_disown_flag) { 
 
284
        swig_disown_flag=true;
 
285
        swig_incref(); 
 
286
      } 
 
287
    }
 
288
 
 
289
    /* increase the reference count of the wrapped python object */
 
290
    void swig_incref() const { 
 
291
      if (swig_disown_flag) {
 
292
        Py_INCREF(swig_self); 
 
293
      }
 
294
    }
 
295
 
 
296
    /* methods to implement pseudo protected director members */
 
297
    virtual bool swig_get_inner(const char* /* name */) const {
 
298
      return true;
 
299
    }
 
300
    
 
301
    virtual void swig_set_inner(const char* /* name */, bool /* val */) const {
 
302
    }
184
303
  };
185
304
 
186
305
}