OOF2: The Manual

Name

ComponentIteratorP — Wrapper for ComponentIterator pointers

Synopses

C++ Synopsis

#include "engine/fieldindex.h"
class ComponentIteratorP {
  ComponentIteratorP(ComponentIterator* iterator);
  ComponentIteratorP(ComponentIteratorP&& other);
  bool operator!=(const ComponentIteratorP& other) const;
  ComponentIteratorP& operator++();
  IndexP operator*() const;
  FieldIndex* current() const;
}

Python Synopsis

from ooflib.SWIG.engine.fieldindex import ComponentIteratorP
class ComponentIteratorP:
  def __ne__(self, other)
  def increment(self)
  def current(self)

Source Files

  • SRC/engine/fieldindex.h: C++ header
  • SRC/engine/fieldindex.C: C++ source code
  • SRC/engine/fieldindex.swg: SWIG source code

Description

ComponentIteratorP is a wrapper for ComponentIterator pointers, just as IndexP is a wrapper for FieldIndex pointers. The class provides access to the ComponentIterator virtual functions, and deletes the pointer when it is destroyed.

In C++, the begin() and end() methods of the various Components subclasses return ComponentIteratorPs that wrap the appropriate iterator for the Components subclass. This allows code like this:

for(ComponentIteratorP cp=field.components().begin(); cp!=field.components.end(); cp++)  {
   IndexP idx = *cp;
   ...
} 

where the allocated ComponentIterator (inside cp) and FieldIndex (inside idx) are deallocated when the loop finishes.

Unlike IndexP, ComponentIteratorP is exported to Python, but it is rarely necessary to access it there. It is used within the generator function that is returned by Field::components() and the equivalent methods in Flux and other classes.

Methods

Most of the ComponentIteratorP methods simply the similarly named method in the wrapped ComponentIterator object and return the result.

ComponentIteratorP(ComponentIterator* iterator)

The constructor argument is a pointer to a newly allocated ComponentIterator. The ComponentIterator will be deleted by the ComponentIteratorP destructor.

ComponentIteratorP(ComponentIteratorP&& other)

The move constructor creates a new ComponentIteratorP that takes ownership of the old ComponentIteratorP's ComponentIterator pointer. The ComponentIterator will be deleted when the new ComponentIteratorP is destroyed. The old ComponentIteratorP is invalidated.

bool operator!=(const ComponentIteratorP& other) const and __ne__(self, other)

The inequality operator indicates whether the wrapped ComponentIterators point to the same FieldIndex. It is assumed that they are iterating over the same type of Components.

ComponentIteratorP& operator++() and increment()

operator++() (C++) and increment() (Python) advance the ComponentIterator to the next component.

IndexP operator*() const

Dereferencing the ComponentIteratorP in C++ returns an IndexP for the current component.

FieldIndex* current() const

current() returns a newly allocated FieldIndex pointing to the current component.