aboutsummaryrefslogtreecommitdiff
path: root/Lib/octave/director.swg
blob: bf71d18e848efc24e8d8a8f8d77d1130e5caaca6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
/* -----------------------------------------------------------------------------
 * director.swg
 *
 * This file contains support for director classes so that Octave proxy
 * methods can be called from C++.
 * ----------------------------------------------------------------------------- */

# define SWIG_DIRECTOR_CAST(ARG) dynamic_cast<Swig::Director *>(ARG)

#include <exception>

namespace Swig {

  class Director {
    octave_swig_type *self;
    bool swig_disowned;

    Director(const Director &x);
    Director &operator=(const Director &rhs);
  public:

    Director(void *vptr):self(0), swig_disowned(false) {
      set_rtdir(vptr, this);
    }

    ~Director() {
      swig_director_destroyed(self, this);
      if (swig_disowned)
	self->decref();
    }

    void swig_set_self(octave_swig_type *new_self) {
      assert(!swig_disowned);
      self = new_self;
    }

    octave_swig_type *swig_get_self() const {
      return self;
    }

    void swig_disown() {
      if (swig_disowned)
	return;
      swig_disowned = true;
      self->incref();
    }
  };

  // Base class for director exceptions.
  class DirectorException : public std::exception {
  public:
    static void raise(const char *msg) {
      // ... todo
      throw DirectorException();
    }

    static void raise(const octave_value &ov, const char *msg) {
      // ... todo
      raise(msg);
    }
  };

  class DirectorTypeMismatchException : public DirectorException {
  public:
    static void raise(const char *msg) {
      // ... todo
      throw DirectorTypeMismatchException();
    }

    static void raise(const octave_value &ov, const char *msg) {
      // ... todo
      raise(msg);
    }
  };

  class DirectorPureVirtualException : public DirectorException {
  public:
    static void raise(const char *msg) {
      // ... todo
      throw DirectorPureVirtualException();
    }

    static void raise(const octave_value &ov, const char *msg) {
      // ... todo
      raise(msg);
    }
  };

  SWIGINTERN rtdir_map *get_rtdir_map() {
    static swig_module_info *module = 0;
    if (!module)
      module = SWIG_GetModule(0);
    if (!module)
      return 0;
    if (!module->clientdata)
      module->clientdata = new rtdir_map;
    return (rtdir_map *) module->clientdata;
  }

  SWIGINTERNINLINE void set_rtdir(void *vptr, Director *d) {
    rtdir_map *rm = get_rtdir_map();
    if (rm)
      (*rm)[vptr] = d;
  }

  SWIGINTERNINLINE void erase_rtdir(void *vptr) {
    rtdir_map *rm = get_rtdir_map();
    if (rm)
      (*rm).erase(vptr);
  }

  SWIGINTERNINLINE Director *get_rtdir(void *vptr) {
    rtdir_map *rm = get_rtdir_map();
    if (!rm)
      return 0;
    rtdir_map::const_iterator pos = rm->find(vptr);
    Director *rtdir = (pos != rm->end())? pos->second : 0;
    return rtdir;
  }

  SWIGRUNTIME void swig_director_destroyed(octave_swig_type *self, Director *d) {
    self->director_destroyed(d);
  }

  SWIGRUNTIME octave_swig_type *swig_director_get_self(Director *d) {
    return d->swig_get_self();
  }

  SWIGRUNTIME void swig_director_set_self(Director *d, octave_swig_type *self) {
    d->swig_set_self(self);
  }

}

SWIGRUNTIME void swig_acquire_ownership(void *vptr) {
  //  assert(0);
  // ... todo
}

SWIGRUNTIME void swig_acquire_ownership_array(void *vptr) {
  //  assert(0);
  // ... todo
}

SWIGRUNTIME void swig_acquire_ownership_obj(void *vptr, int own) {
  //  assert(0);
  // ... todo
}