Skip to content

Commit 6f16853

Browse files
authored
Merge pull request #17 from peastman/cast
Added a method for casting Force to ExampleForce
2 parents 5c24825 + a1c1601 commit 6f16853

File tree

2 files changed

+26
-1
lines changed

2 files changed

+26
-1
lines changed

python/exampleplugin.i

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,18 @@ import simtk.unit as unit
3838
val[3] = unit.Quantity(val[3], unit.kilojoule_per_mole/unit.nanometer**4)
3939
%}
4040

41+
/*
42+
* Convert C++ exceptions to Python exceptions.
43+
*/
44+
%exception {
45+
try {
46+
$action
47+
} catch (std::exception &e) {
48+
PyErr_SetString(PyExc_Exception, const_cast<char*>(e.what()));
49+
return NULL;
50+
}
51+
}
52+
4153

4254
namespace ExamplePlugin {
4355

@@ -66,6 +78,19 @@ public:
6678
%clear int& particle2;
6779
%clear double& length;
6880
%clear double& k;
81+
82+
/*
83+
* Add methods for casting a Force to an ExampleForce.
84+
*/
85+
%extend {
86+
static ExamplePlugin::ExampleForce& cast(OpenMM::Force& force) {
87+
return dynamic_cast<ExamplePlugin::ExampleForce&>(force);
88+
}
89+
90+
static bool isinstance(OpenMM::Force& force) {
91+
return (dynamic_cast<ExamplePlugin::ExampleForce*>(&force) != NULL);
92+
}
93+
}
6994
};
7095

7196
}

python/setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
exampleplugin_library_dir = '@EXAMPLEPLUGIN_LIBRARY_DIR@'
1010

1111
# setup extra compile and link arguments on Mac
12-
extra_compile_args = []
12+
extra_compile_args = ['-std=c++11']
1313
extra_link_args = []
1414

1515
if platform.system() == 'Darwin':

0 commit comments

Comments
 (0)