Ignore:
Timestamp:
Oct 5, 2009, 8:51:24 PM (16 years ago)
Author:
Frederik Heber <heber@…>
Children:
d40b96
Parents:
424d1ce
Message:

Member functions of Vector class may be called while going over an iteration of a list containing Vectors, thanks to member function pointers.

  • Unit test ActOnAllTest is the basic class for showing, how we can use any member function of Vector:: and make it act globally over a list of vectors.
  • this is incorporated into the definition of class molecule for the vectors contained in the atoms chained list.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • molecuilder/src/molecules.hpp

    r424d1ce r4bc937  
    132132  bool IsEnd();
    133133
     134  // templates for allowing global manipulation of all vectors
     135  template <typename res, typename T> void ActOnAllVectors( res (Vector::*f)(T), T t );
     136  template <typename res, typename T, typename U> void ActOnAllVectors( res (Vector::*f)(T, U), T t, U u );
     137  template <typename res, typename T, typename U, typename V> void ActOnAllVectors( res (Vector::*f)(T, U, V), T t, U u, V v);
     138
    134139  /// remove atoms from molecule.
    135140  bool AddAtom(atom *pointer);
     
    249254};
    250255
     256
     257template <typename res, typename T> void molecule::ActOnAllVectors( res (Vector::*f)(T), T t )
     258{
     259  atom *Walker = start;
     260  while (Walker->next != end) {
     261    Walker = Walker->next;
     262    ((*Walker->node)->*f)(t);
     263  }
     264};
     265
     266template <typename res, typename T, typename U> void molecule::ActOnAllVectors( res (Vector::*f)(T, U), T t, U u )
     267{
     268  atom *Walker = start;
     269  while (Walker->next != end) {
     270    Walker = Walker->next;
     271    ((*Walker->node)->*f)(t, u);
     272  }
     273};
     274
     275template <typename res, typename T, typename U, typename V> void molecule::ActOnAllVectors( res (Vector::*f)(T, U, V), T t, U u, V v)
     276{
     277  atom *Walker = start;
     278  while (Walker->next != end) {
     279    Walker = Walker->next;
     280    ((*Walker->node)->*f)(t, u, v);
     281  }
     282};
     283
    251284/** A list of \a molecule classes.
    252285 */
Note: See TracChangeset for help on using the changeset viewer.