// needed to work around bug in SWIG -- can't completely override module from command-line %module "Chemistry::OpenBabel" %{ // used to set import/export for Cygwin DLLs #ifdef WIN32 #define USING_OBDLL #endif #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include %} %include "std_list.i" %include "std_map.i" %include "std_vector.i" %include "std_string.i" namespace std { %template (vectorInt) vector; %template (vectorUnsignedInt) vector; %template (vvInt) vector< vector >; %template (vectorDouble) vector; %template (vectorString) vector; %template (vVector3) vector; %template (vectorMol) vector; %template (vectorBond) vector; %template (vectorResidue) vector; %template (vectorRing) vector; %template (vectorpRing) vector; %template (vectorData) vector; } %inline %{ OpenBabel::OBPairData *toPairData(OpenBabel::OBGenericData *data) { return (OpenBabel::OBPairData *) data; } OpenBabel::OBUnitCell *toUnitCell(OpenBabel::OBGenericData *data) { return (OpenBabel::OBUnitCell *) data; } %} %rename(inc) *::operator++; %rename(good) *::operator bool; %rename(deref) *::operator->; %import %include %include %include %include %import %import %include %include %include %import %import %import %import %include %include %include %include %include %include %include %include %include %include %include %include %include %include %include %include # The following %ignores avoid warning messages due to shadowed classes. # This does not imply a loss of functionality as (in this case) # the shadowed class is identical (from the point of view of SWIG) to # the shadowing class. # This is because C++ references (&) are transformed by SWIG back into # pointers, so that OBAtomIter(OBMol &) would be treated the same as # OBAtomIter(OBMol *). %ignore OBAtomAtomIter(OBAtom &); %ignore OBAtomBondIter(OBAtom &); %ignore OBMolAngleIter(OBMol &); %ignore OBMolAtomIter(OBMol &); %ignore OBMolAtomBFSIter(OBMol &); %ignore OBMolAtomBFSIter(OBMol &, int); %ignore OBMolAtomDFSIter(OBMol &); %ignore OBMolAtomDFSIter(OBMol &, int); %ignore OBMolBondIter(OBMol &); %ignore OBMolPairIter(OBMol &); %ignore OBMolRingIter(OBMol &); %ignore OBMolTorsionIter(OBMol &); %ignore OBResidueIter(OBMol &); %ignore OBResidueAtomIter(OBResidue &); %ignore *::operator=; %perlcode %{ # http://www.perl.com/pub/a/2005/06/16/iterators.html sub gen_iterator { my $iterator_function = shift; return sub { my $iter = new $iterator_function(shift); my ($current_state, $done); return sub { # code to calculate $next_state or $done; return undef if $done; my $next_state = $iter->deref(); $iter->inc(); if (!$iter->good()) {$done = 1;}; return $current_state = $next_state; }; }; } %} %define MAKE_ITER_CLASS(itername, renamediter) %rename itername renamediter; %perlcode %{ package Chemistry::OpenBabel::itername; sub new { my $pkg = shift; my $self = Chemistry::OpenBabel::gen_iterator(Chemistry::OpenBabel::renamediter)->(shift); bless($self, $pkg); } %} %enddef MAKE_ITER_CLASS(OBAtomAtomIter, _OBAtomAtomIter) MAKE_ITER_CLASS(OBAtomBondIter, _OBAtomBondIter) MAKE_ITER_CLASS(OBMolAngleIter, _OBMolAngleIter) MAKE_ITER_CLASS(OBMolAtomIter, _OBMolAtomIter) MAKE_ITER_CLASS(OBMolAtomBFSIter, _OBMolAtomBFSIter) MAKE_ITER_CLASS(OBMolAtomDFSIter, _OBMolAtomDFSIter) MAKE_ITER_CLASS(OBMolBondIter, _OBMolBondIter) MAKE_ITER_CLASS(OBMolPairIter, _OBMolPairIter) MAKE_ITER_CLASS(OBMolRingIter, _OBMolRingIter) MAKE_ITER_CLASS(OBMolTorsionIter, _OBMolTorsionIter) MAKE_ITER_CLASS(OBResidueAtomIter, _OBResidueAtomIter) MAKE_ITER_CLASS(OBFingerprintIter, _OBFingerprintIter) %include