FeResPost Web Site                     FeResPost Online User Manual

VI.0.2.3 Iterators

COM provides a standard interface that allows the writing of iterators on collections of different types. In FeResPost, the iteration is based on the IEnumVARIANT interface. One notes however, that it does not seem possible to implement a class that defines several enumerators. This is why, an additional class corresponding to the iteration has been created in FeResPost: the “Iterator” class.

The “Iterator” class is common to all the iterators of all the FeResPost classes. But an Iterator object behaves differently depending on the class that produces it and/or the method of the class that is used to produce it.

Let us illustrate it by an example... Consider the “each_ply” iterator defined in ClaLam class of FeResPost ruby extension. With the ruby extension, the iteration on the plies of a laminate may be performed as follows:

   ...
   lam.each_ply do |plyDescr|
      ...
   end
   ...

With FeResPost COM component, an Iterator must first be produced before iterating on the elements of the corresponding collection. This can be done as follows:

   ...
   plyIt = lam.iter_ply
   plyIt.each do |plyDescr|
      ...
   end
   ...

This examples illustrates the conventions that have been used when programming the FeResPost COM component to transpose the iterators proposed in the ruby extension:

1.

As in the FeResPost ruby extension, each iterator method name starts with “each_”, correspondingly, the COM component methods returning an Iterator object have a name that starts with “iter_”. The correspondence between ruby extension methods and COM component methods is obvious: “each_ply” becomes “iter_ply”, “each_material” becomes “iter_material”,...

2.

When the COM iteration method has no argument, it is a property “getter” that is used instead of a method. Otherwise, a method with argument is defined.

3.

In ruby using the COM component, the iteration on the Iterator object is done using “each” iteration method.

Note that to the ruby lines given as example above, one prefers the shorter notation:

   ...
   lam.iter_ply.each do |plyDescr|
      ...
   end
   ...

The corresponding code in python may be:

   ...
   for plyDescr in lam.iter_ply:
      ...
   ...

and in VBscript, one shall have:

   ...
   for each plyDescr in lam.iter_ply
      ...
   Next
   ...