-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmaf.i
More file actions
209 lines (157 loc) · 7.03 KB
/
Copy pathmaf.i
File metadata and controls
209 lines (157 loc) · 7.03 KB
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
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
%module(directors="1", docstring="This is the MAF's docstring!") maf
%include "std_string.i"
%include "exception.i"
%include "std_vector.i"
%include "std_shared_ptr.i"
%feature("autodoc", "2");
%{
#include "maf/maf.hpp"
%}
namespace std {
%template(StringVector) vector<string>;
}
%exception {
try {
$action
} catch(std::exception& ex) {
std::ostringstream full_msg;
full_msg << typeid(ex).name() << " in $decl: " << ex.what();
SWIG_exception(SWIG_RuntimeError, full_msg.str().c_str());
} catch(std::string& msg) {
std::string full_msg = "something bad happend in $decl: " + msg;
SWIG_exception(SWIG_RuntimeError, full_msg.c_str());
} catch(...) {
SWIG_exception(SWIG_RuntimeError, "something bad happened in $decl, but I do not know what it was :-(");
}
};
%feature("director") maf::Context;
%shared_ptr(maf::Context);
%feature("director") maf::Action;
%feature("nodirector") maf::Action::start;
%shared_ptr(maf::Action);
%feature("director") maf::AbstractTestAction;
%shared_ptr(maf::AbstractTestAction);
%shared_ptr(maf::MafComm);
%shared_ptr(maf::Exception);
%shared_ptr(maf::EndLoopAction);
%shared_ptr(maf::EmptyAction);
%shared_ptr(maf::SplitMpiAction);
%shared_ptr(maf::RevertSplitAction);
%feature("director") maf::ActionFactory;
%shared_ptr(maf::ActionFactory);
%shared_ptr(maf::Controller);
%shared_ptr(maf::BcastController);
%shared_ptr(maf::ScatterController);
%shared_ptr(maf::TestController);
%feature("director") maf::Controller;
%feature("director") maf::BcastController;
%feature("director") maf::ScatterController;
%feature("director") maf::TestController;
%feature("nodirector") maf::Controller::scatter;
%feature("nodirector") maf::BcastController::scatter;
%feature("nodirector") maf::ScatterController::scatter;
%feature("nodirector") maf::TestController::scatter;
%feature("nodirector") maf::Controller::bcast;
%feature("nodirector") maf::BcastController::bcast;
%feature("nodirector") maf::ScatterController::bcast;
%feature("nodirector") maf::TestController::bcast;
%shared_ptr(maf::Archive);
%shared_ptr(maf::ReadArchive);
%shared_ptr(maf::WriteArchive);
/* vectors */
%template(ActionVector) std::vector<std::shared_ptr<maf::Action>>;
%include "maf/maf.hpp"
%template(log) maf::log<std::string>;
%template(warning) maf::warning<std::string>;
%template(barrier) maf::barrier<std::string>;
%template(bcast) maf::MafComm::bcast<std::string>;
%template(bcast) maf::MafComm::bcast<long long>;
%template(bcast) maf::MafComm::bcast<double>;
%template(bcast) maf::MafComm::bcast<std::vector<long long>>;
%template(bcast) maf::MafComm::bcast<std::vector<double>>;
%template(assert_equal) maf::AbstractTestAction::assert_equal<std::string>;
%template(assert_equal) maf::AbstractTestAction::assert_equal<int>;
%template(assert_equal) maf::AbstractTestAction::assert_equal<long long>;
%template(assert_equal) maf::AbstractTestAction::assert_equal<double>;
%template(assert_equal) maf::AbstractTestAction::assert_equal<float>;
%template(assert_equal) maf::AbstractTestAction::assert_equal<std::vector<std::string>>;
%template(assert_equal) maf::AbstractTestAction::assert_equal<std::vector<int>>;
%template(assert_equal) maf::AbstractTestAction::assert_equal<std::vector<long long>>;
%template(assert_equal) maf::AbstractTestAction::assert_equal<std::vector<double>>;
%template(assert_equal) maf::AbstractTestAction::assert_equal<std::vector<float>>;
%template(assert_not_equal) maf::AbstractTestAction::assert_not_equal<std::string>;
%template(assert_not_equal) maf::AbstractTestAction::assert_not_equal<int>;
%template(assert_not_equal) maf::AbstractTestAction::assert_not_equal<long long>;
%template(assert_not_equal) maf::AbstractTestAction::assert_not_equal<double>;
%template(assert_not_equal) maf::AbstractTestAction::assert_not_equal<float>;
%template(assert_not_equal) maf::AbstractTestAction::assert_not_equal<std::vector<std::string>>;
%template(assert_not_equal) maf::AbstractTestAction::assert_not_equal<std::vector<int>>;
%template(assert_not_equal) maf::AbstractTestAction::assert_not_equal<std::vector<long long>>;
%template(assert_not_equal) maf::AbstractTestAction::assert_not_equal<std::vector<double>>;
%template(assert_not_equal) maf::AbstractTestAction::assert_not_equal<std::vector<float>>;
%template(assert_close) maf::AbstractTestAction::assert_close<int, int>;
%template(assert_close) maf::AbstractTestAction::assert_close<long long, long long>;
%template(assert_close) maf::AbstractTestAction::assert_close<double, double>;
%template(assert_close) maf::AbstractTestAction::assert_close<float, float>;
%template(assert_close) maf::AbstractTestAction::assert_close<std::vector<int>, int>;
%template(assert_close) maf::AbstractTestAction::assert_close<std::vector<long long>, long long>;
%template(assert_close) maf::AbstractTestAction::assert_close<std::vector<double>, double>;
%template(assert_close) maf::AbstractTestAction::assert_close<std::vector<float>, float>;
%template(assert_not_close) maf::AbstractTestAction::assert_not_close<int>;
%template(assert_not_close) maf::AbstractTestAction::assert_not_close<long long>;
%template(assert_not_close) maf::AbstractTestAction::assert_not_close<double>;
%template(assert_not_close) maf::AbstractTestAction::assert_not_close<float>;
%pythoncode %{
_FACTORY_REFRENCES = []
class ActionFactory(_maf.ActionFactory):
def __init__(self, klass, is_test):
_maf.ActionFactory.__init__(self, klass.__name__)
self.klass = klass
_FACTORY_REFRENCES.append(self)
_maf.ActionFactory.Register(self, is_test)
def create_action(self):
return self.klass()
_ACTION_STACK = set()
class _Action(object):
def __init__(self):
_ACTION_STACK.add(self)
def __del__(self):
# when everything is getting cleaned up, it is possible that the _ACTION_STACK is None
if _ACTION_STACK is not None:
_ACTION_STACK.discard(self)
def type_name(self):
return self.__class__.__name__
def serialize(self, archive):
pass
class Action(_Action, _maf.Action):
def __init__(self):
_Action.__init__(self)
_maf.Action.__init__(self)
class TestAction(_Action, _maf.AbstractTestAction):
def __init__(self):
_Action.__init__(self)
_maf.AbstractTestAction.__init__(self)
def action(klass_or_method):
if isinstance(klass_or_method, type):
klass = klass_or_method
else:
def run(self):
klass_or_method()
cls_dict = dict(run=run, __doc__=klass_or_method.__doc__)
klass = type(klass_or_method.__name__, (Action, ), cls_dict)
factory = ActionFactory(klass, False)
return klass
def test(klass_or_method):
if isinstance(klass_or_method, type):
klass = klass_or_method
else:
def run(self):
klass_or_method(self)
cls_dict = dict(run=klass_or_method, __doc__=klass_or_method.__doc__)
klass = type(klass_or_method.__name__, (TestAction, ), cls_dict)
factory = ActionFactory(klass, True)
return klass
import atexit
atexit.register(MafComm.Finalize)
del atexit
%}