Loading...
Searching...
No Matches
SBCContainerFor.hpp File Reference

Macros

#define SB_FOR(VARIABLE, CONTAINER)
 A macro to easily write for loops involving containers.
 

Macro Definition Documentation

◆ SB_FOR

#define SB_FOR (   VARIABLE,
  CONTAINER 
)

This macro makes it possible to easily write for loops involving containers that have iterators (i.e. an inner iterator). For SAMSON indexers, lists and vectors, the first argument of the macro is a variable with the same type as the one used as a template parameter:

SBIndexer<SBAtom*> atomIndexer;
SB_FOR(SBAtom* atom, atomIndexer) atom->setSelectionFlag(true);
SBList<SBAtom*> atomList;
SB_FOR(SBAtom* atom, atomList) atom->setSelectionFlag(true);
SBVector<SBAtom*> atomVector;
SB_FOR(SBAtom* atom, atomVector) atom->setSelectionFlag(true);
#define SB_FOR(VARIABLE, CONTAINER)
A macro to easily write for loops involving containers.
Definition: SBCContainerFor.hpp:83
This class describes an atom in a structural model.
Definition: SBMStructuralModelNodeAtom.hpp:34

For buffers, the first argument is a variable with unsigned int type, since a buffer iterator iterates over the indices of the elements that have changed since the last update:

SBBuffer<SBPosition3> positionBuffer;
SB_FOR(unsigned int changedElement, positionBuffer) // ...

For hash maps, the first argument of the SB_FOR macro is a variable of type "hash map entry" (SBHashMapEntry). Unfortunately, a limitation of the SB_FOR macro makes it impossible to use a comma in the declaration of the variable, so that the declaration has to be made outside the SB_FOR macro, or, alternatively, the auto keyword can be used:

SBHashMap<SBAtom*, unsigned int> atomMap;
SBHashMapEntry<SBAtom*, unsigned int> entry;
SB_FOR(entry, atomMap) std::cout << entry.getKey() << std::endl;

The SB_FOR macro may also be used for pointer indexers and pointer lists:

SBPointerIndexer<SBAtom> atomIndexer;
SB_FOR(SBAtom* atom, atomIndexer) atom->setSelectionFlag(true);
SBPointerList<SBAtom> atomList;
SB_FOR(SBAtom* atom, atomList) atom->setSelectionFlag(true);

Note that, even though the declaration of a SBPointerIndexer involves SBAtom and not SBAtom*, dereferencing an iterator of SBPointerIndexer<SBAtom> returns a SBAtom*, which is why the syntax of the SB_FOR command involves a SBAtom*.

Finally, the SB_FOR macro also works with STL containers:

std::vector<SBAtom*> atomVector;
SB_FOR(SBAtom* atom, atomVector) atom->setSelectionFlag(true);