On 17 May 2010 15:53, Tim Vandermeersch <tim.vandermeer...@gmail.com> wrote: > On Mon, May 17, 2010 at 12:50 PM, Noel O'Boyle <baoille...@gmail.com> wrote: >> On 17 May 2010 11:19, Tim Vandermeersch <tim.vandermeer...@gmail.com> wrote: >>> On Mon, May 17, 2010 at 11:22 AM, Noel O'Boyle <baoille...@gmail.com> wrote: >>>> Hi all, >>>> >>>> I would like to be able to const iterate over the atoms of a mol with, >>>> for example, FOR_CONST_ATOMS_OF_MOL or so. I am instead reduced to >>>> using "for (i=1; i<=mol.NumAtoms(); ++i)" which is very sad. >>>> >>>> I'm not quite sure how to add this to OBMolAtomIter, so I'd appreciate >>>> if someone else could do this or steer me in the right direction. >>> >>> The easiest way to do this would be to add a OBConstMolAtomIter I >>> think. A new (const) version for OBMol::BeginAtom/NextAtom is also >>> needed. Shouldn't be alot of work though. Do you want me to add this? >> >> That's fine. You've given me the starting point. I'll see if anyone >> else comments and if not, I'll give it a go later today or tomorrow. >> >>> Note: Ideally, const OBMol objects would be used more. However there >>> are methods which prevent this (e.g. GetSSSR, ...) > > http://pastebin.com/xtrf2kVc > > Here is a patch for an OBMolAtomIter2 class. The class works for both > const and non-const OBMol objects depending on the template parameter. > While we still have to keep the old class for backwards compatibility, > having one class for both const/non-const should be easier to > maintain. Similar classes could be added for bond/residue iteration. > > The class requires boost::mpl (template metaprogramming library) to > select the correct data types. We could embed the boost::mpl::if_c > code in OB if you agree this is a good solution.
Thanks for this Tim. Looks like a tidy solution. I'll leave it to the others to comment on whether it can be integrated directly into OB 2.3. > Tim > >>>> - Noel >>>> >>>> ------------------------------------------------------------------------------ >>>> >>>> _______________________________________________ >>>> OpenBabel-Devel mailing list >>>> OpenBabel-Devel@lists.sourceforge.net >>>> https://lists.sourceforge.net/lists/listinfo/openbabel-devel >>>> >>> >> > > ------------------------------------------------------------------------------ > > _______________________________________________ > OpenBabel-Devel mailing list > OpenBabel-Devel@lists.sourceforge.net > https://lists.sourceforge.net/lists/listinfo/openbabel-devel > ------------------------------------------------------------------------------ _______________________________________________ OpenBabel-Devel mailing list OpenBabel-Devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/openbabel-devel