multiple_files_wrapper.cpp
Go to the documentation of this file.
1 #include <gtwrap/matlab.h>
2 #include <map>
3 
4 
5 
6 
7 
8 typedef std::set<std::shared_ptr<gtsam::Class1>*> Collector_gtsamClass1;
10 typedef std::set<std::shared_ptr<gtsam::Class2>*> Collector_gtsamClass2;
12 typedef std::set<std::shared_ptr<gtsam::ClassA>*> Collector_gtsamClassA;
14 
15 
17 {
18  mstream mout;
19  std::streambuf *outbuf = std::cout.rdbuf(&mout);
20 
21  bool anyDeleted = false;
22  { for(Collector_gtsamClass1::iterator iter = collector_gtsamClass1.begin();
23  iter != collector_gtsamClass1.end(); ) {
24  delete *iter;
25  collector_gtsamClass1.erase(iter++);
26  anyDeleted = true;
27  } }
28  { for(Collector_gtsamClass2::iterator iter = collector_gtsamClass2.begin();
29  iter != collector_gtsamClass2.end(); ) {
30  delete *iter;
31  collector_gtsamClass2.erase(iter++);
32  anyDeleted = true;
33  } }
34  { for(Collector_gtsamClassA::iterator iter = collector_gtsamClassA.begin();
35  iter != collector_gtsamClassA.end(); ) {
36  delete *iter;
37  collector_gtsamClassA.erase(iter++);
38  anyDeleted = true;
39  } }
40 
41  if(anyDeleted)
42  cout <<
43  "WARNING: Wrap modules with variables in the workspace have been reloaded due to\n"
44  "calling destructors, call 'clear all' again if you plan to now recompile a wrap\n"
45  "module, so that your recompiled module is used instead of the old one." << endl;
46  std::cout.rdbuf(outbuf);
47 }
48 
50  const mxArray *alreadyCreated = mexGetVariablePtr("global", "gtsam_multiple_files_rttiRegistry_created");
51  if(!alreadyCreated) {
52  std::map<std::string, std::string> types;
53 
54 
55 
56  mxArray *registry = mexGetVariable("global", "gtsamwrap_rttiRegistry");
57  if(!registry)
58  registry = mxCreateStructMatrix(1, 1, 0, NULL);
59  typedef std::pair<std::string, std::string> StringPair;
60  for(const StringPair& rtti_matlab: types) {
61  int fieldId = mxAddField(registry, rtti_matlab.first.c_str());
62  if(fieldId < 0) {
63  mexErrMsgTxt("gtsam wrap: Error indexing RTTI types, inheritance will not work correctly");
64  }
65  mxArray *matlabName = mxCreateString(rtti_matlab.second.c_str());
66  mxSetFieldByNumber(registry, 0, fieldId, matlabName);
67  }
68  if(mexPutVariable("global", "gtsamwrap_rttiRegistry", registry) != 0) {
69  mexErrMsgTxt("gtsam wrap: Error indexing RTTI types, inheritance will not work correctly");
70  }
71  mxDestroyArray(registry);
72 
73  mxArray *newAlreadyCreated = mxCreateNumericMatrix(0, 0, mxINT8_CLASS, mxREAL);
74  if(mexPutVariable("global", "gtsam_multiple_files_rttiRegistry_created", newAlreadyCreated) != 0) {
75  mexErrMsgTxt("gtsam wrap: Error indexing RTTI types, inheritance will not work correctly");
76  }
77  mxDestroyArray(newAlreadyCreated);
78  }
79 }
80 
81 void gtsamClass1_collectorInsertAndMakeBase_0(int nargout, mxArray *out[], int nargin, const mxArray *in[])
82 {
83  mexAtExit(&_deleteAllObjects);
84  typedef std::shared_ptr<gtsam::Class1> Shared;
85 
86  Shared *self = *reinterpret_cast<Shared**> (mxGetData(in[0]));
87  collector_gtsamClass1.insert(self);
88 }
89 
90 void gtsamClass1_constructor_1(int nargout, mxArray *out[], int nargin, const mxArray *in[])
91 {
92  mexAtExit(&_deleteAllObjects);
93  typedef std::shared_ptr<gtsam::Class1> Shared;
94 
95  Shared *self = new Shared(new gtsam::Class1());
96  collector_gtsamClass1.insert(self);
97  out[0] = mxCreateNumericMatrix(1, 1, mxUINT32OR64_CLASS, mxREAL);
98  *reinterpret_cast<Shared**> (mxGetData(out[0])) = self;
99 }
100 
101 void gtsamClass1_deconstructor_2(int nargout, mxArray *out[], int nargin, const mxArray *in[])
102 {
103  typedef std::shared_ptr<gtsam::Class1> Shared;
104  checkArguments("delete_gtsamClass1",nargout,nargin,1);
105  Shared *self = *reinterpret_cast<Shared**>(mxGetData(in[0]));
106  Collector_gtsamClass1::iterator item;
107  item = collector_gtsamClass1.find(self);
108  if(item != collector_gtsamClass1.end()) {
109  collector_gtsamClass1.erase(item);
110  }
111  delete self;
112 }
113 
114 void gtsamClass2_collectorInsertAndMakeBase_3(int nargout, mxArray *out[], int nargin, const mxArray *in[])
115 {
116  mexAtExit(&_deleteAllObjects);
117  typedef std::shared_ptr<gtsam::Class2> Shared;
118 
119  Shared *self = *reinterpret_cast<Shared**> (mxGetData(in[0]));
120  collector_gtsamClass2.insert(self);
121 }
122 
123 void gtsamClass2_constructor_4(int nargout, mxArray *out[], int nargin, const mxArray *in[])
124 {
125  mexAtExit(&_deleteAllObjects);
126  typedef std::shared_ptr<gtsam::Class2> Shared;
127 
128  Shared *self = new Shared(new gtsam::Class2());
129  collector_gtsamClass2.insert(self);
130  out[0] = mxCreateNumericMatrix(1, 1, mxUINT32OR64_CLASS, mxREAL);
131  *reinterpret_cast<Shared**> (mxGetData(out[0])) = self;
132 }
133 
134 void gtsamClass2_deconstructor_5(int nargout, mxArray *out[], int nargin, const mxArray *in[])
135 {
136  typedef std::shared_ptr<gtsam::Class2> Shared;
137  checkArguments("delete_gtsamClass2",nargout,nargin,1);
138  Shared *self = *reinterpret_cast<Shared**>(mxGetData(in[0]));
139  Collector_gtsamClass2::iterator item;
140  item = collector_gtsamClass2.find(self);
141  if(item != collector_gtsamClass2.end()) {
142  collector_gtsamClass2.erase(item);
143  }
144  delete self;
145 }
146 
147 void gtsamClassA_collectorInsertAndMakeBase_6(int nargout, mxArray *out[], int nargin, const mxArray *in[])
148 {
149  mexAtExit(&_deleteAllObjects);
150  typedef std::shared_ptr<gtsam::ClassA> Shared;
151 
152  Shared *self = *reinterpret_cast<Shared**> (mxGetData(in[0]));
153  collector_gtsamClassA.insert(self);
154 }
155 
156 void gtsamClassA_constructor_7(int nargout, mxArray *out[], int nargin, const mxArray *in[])
157 {
158  mexAtExit(&_deleteAllObjects);
159  typedef std::shared_ptr<gtsam::ClassA> Shared;
160 
161  Shared *self = new Shared(new gtsam::ClassA());
162  collector_gtsamClassA.insert(self);
163  out[0] = mxCreateNumericMatrix(1, 1, mxUINT32OR64_CLASS, mxREAL);
164  *reinterpret_cast<Shared**> (mxGetData(out[0])) = self;
165 }
166 
167 void gtsamClassA_deconstructor_8(int nargout, mxArray *out[], int nargin, const mxArray *in[])
168 {
169  typedef std::shared_ptr<gtsam::ClassA> Shared;
170  checkArguments("delete_gtsamClassA",nargout,nargin,1);
171  Shared *self = *reinterpret_cast<Shared**>(mxGetData(in[0]));
172  Collector_gtsamClassA::iterator item;
173  item = collector_gtsamClassA.find(self);
174  if(item != collector_gtsamClassA.end()) {
175  collector_gtsamClassA.erase(item);
176  }
177  delete self;
178 }
179 
180 
181 void mexFunction(int nargout, mxArray *out[], int nargin, const mxArray *in[])
182 {
183  mstream mout;
184  std::streambuf *outbuf = std::cout.rdbuf(&mout);
185 
187 
188  int id = unwrap<int>(in[0]);
189 
190  try {
191  switch(id) {
192  case 0:
193  gtsamClass1_collectorInsertAndMakeBase_0(nargout, out, nargin-1, in+1);
194  break;
195  case 1:
196  gtsamClass1_constructor_1(nargout, out, nargin-1, in+1);
197  break;
198  case 2:
199  gtsamClass1_deconstructor_2(nargout, out, nargin-1, in+1);
200  break;
201  case 3:
202  gtsamClass2_collectorInsertAndMakeBase_3(nargout, out, nargin-1, in+1);
203  break;
204  case 4:
205  gtsamClass2_constructor_4(nargout, out, nargin-1, in+1);
206  break;
207  case 5:
208  gtsamClass2_deconstructor_5(nargout, out, nargin-1, in+1);
209  break;
210  case 6:
211  gtsamClassA_collectorInsertAndMakeBase_6(nargout, out, nargin-1, in+1);
212  break;
213  case 7:
214  gtsamClassA_constructor_7(nargout, out, nargin-1, in+1);
215  break;
216  case 8:
217  gtsamClassA_deconstructor_8(nargout, out, nargin-1, in+1);
218  break;
219  }
220  } catch(const std::exception& e) {
221  mexErrMsgTxt(("Exception from gtsam:\n" + std::string(e.what()) + "\n").c_str());
222  }
223 
224  std::cout.rdbuf(outbuf);
225 }
int unwrap< int >(const mxArray *array)
Definition: matlab.h:328
void gtsamClass2_collectorInsertAndMakeBase_3(int nargout, mxArray *out[], int nargin, const mxArray *in[])
std::set< std::shared_ptr< gtsam::Class1 > * > Collector_gtsamClass1
void gtsamClass1_constructor_1(int nargout, mxArray *out[], int nargin, const mxArray *in[])
std::ofstream out("Result.txt")
void checkArguments(const string &name, int nargout, int nargin, int expected)
Definition: matlab.h:113
static Collector_gtsamClassA collector_gtsamClassA
void mexFunction(int nargout, mxArray *out[], int nargin, const mxArray *in[])
iterator iter(handle obj)
Definition: pytypes.h:2273
static Collector_gtsamClass2 collector_gtsamClass2
void gtsamClassA_deconstructor_8(int nargout, mxArray *out[], int nargin, const mxArray *in[])
void gtsamClass2_constructor_4(int nargout, mxArray *out[], int nargin, const mxArray *in[])
std::set< std::shared_ptr< gtsam::Class2 > * > Collector_gtsamClass2
void _multiple_files_RTTIRegister()
void gtsamClass2_deconstructor_5(int nargout, mxArray *out[], int nargin, const mxArray *in[])
void gtsamClassA_constructor_7(int nargout, mxArray *out[], int nargin, const mxArray *in[])
Array< double, 1, 3 > e(1./3., 0.5, 2.)
void gtsamClass1_collectorInsertAndMakeBase_0(int nargout, mxArray *out[], int nargin, const mxArray *in[])
#define NULL
Definition: ccolamd.c:609
void gtsamClassA_collectorInsertAndMakeBase_6(int nargout, mxArray *out[], int nargin, const mxArray *in[])
std::set< std::shared_ptr< gtsam::ClassA > * > Collector_gtsamClassA
#define mxUINT32OR64_CLASS
Definition: matlab.h:58
static Collector_gtsamClass1 collector_gtsamClass1
void gtsamClass1_deconstructor_2(int nargout, mxArray *out[], int nargin, const mxArray *in[])
void _deleteAllObjects()
Definition: matlab.h:95


gtsam
Author(s):
autogenerated on Tue Jul 4 2023 02:34:56