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


gtsam
Author(s):
autogenerated on Sun Dec 22 2024 04:14:23