GemaCoreLib
The GeMA Core library
Classes | Macros
gmCellMesh.h File Reference

Declaration of the GmCellMesh interface class. More...

#include "gmMesh.h"
#include "gmCell.h"
#include <assert.h>
#include <float.h>
Include dependency graph for gmCellMesh.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

class  GmCellMesh
 Base interface class for CellMesh type plugins. More...
 
struct  GmCellMesh::GmCellEdgeStatistics
 
struct  GmCellMesh::GmCellBboxStatistics
 
class  GmForeachCellHelperClass< T >
 Helper class for the GmForeachActiveXxxx() family of macros. More...
 

Macros

#define GmForeachCellHelper(variable, container, contType, cellType, activeOnly)
 Helper macro used to traverse all the (active) cells in a generic container. Should NOT be used in user code. More...
 
#define GmForeachActiveCell(variable, mesh)   GmForeachCellHelper(variable, mesh, GmCellMesh, GmCell, true)
 Macro used to traverse all the active cells in a mesh. More...
 
#define GmForeachCell(variable, mesh, activeOnly)   GmForeachCellHelper(variable, mesh, GmCellMesh, GmCell, activeOnly)
 Similar to GmForeachActiveCell but with a flag (activeOnly) controlling if all cells will be traversed or only the active ones.
 

Detailed Description

Declaration of the GmCellMesh interface class.

Author
Carlos Augusto Teixeira Mendes
Date
may, 2015

Macro Definition Documentation

◆ GmForeachActiveCell

#define GmForeachActiveCell (   variable,
  mesh 
)    GmForeachCellHelper(variable, mesh, GmCellMesh, GmCell, true)

Macro used to traverse all the active cells in a mesh.

Can be used as:

GmForeachActiveCell(const GmCell* c, _mesh)
{
printf("%d\n", c->id());
}
{
printf("%d\n", c->id());
}

◆ GmForeachCellHelper

#define GmForeachCellHelper (   variable,
  container,
  contType,
  cellType,
  activeOnly 
)
Value:
for(GmForeachCellHelperClass<contType> it(container, activeOnly); it._control && it._index<it._n; it.inc(container, activeOnly), it._control ^= 1) \
for(variable = (cellType*)container->cell(it._index); it._control; it._control = 0)
Helper class for the GmForeachActiveXxxx() family of macros.
Definition: gmCellMesh.h:422
int _control
The controls flag used to allow breaking inside the inner loop.
Definition: gmCellMesh.h:438

Helper macro used to traverse all the (active) cells in a generic container. Should NOT be used in user code.

The implementation is largelly inspired by the implementation of the Qt foreach macro, so it can include break. The container parameter should be a pointer.

From the documentation of the Q_FOREACH macro:

Explanation of the control word:

  • it's initialized to 1
  • that means both the inner and outer loops start
  • if there were no breaks, at the end of the inner loop, it's set to 0, which causes it to exit (the inner loop is run exactly once)
  • at the end of the outer loop, it's inverted, so it becomes 1 again, allowing the outer loop to continue executing
  • if there was a break inside the inner loop, it will exit with control still set to 1; in that case, the outer loop will invert it to 0 and will exit too