1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99
|
/***********************************************/
/**
* @file loop.h
*
* @brief Loop.
*
* @author Torsten Mayer-Guerr
* @author Sebastian Strasser
* @date 2017-01-27
*
*/
/***********************************************/
#ifndef __GROOPS_LOOP__
#define __GROOPS_LOOP__
// Latex documentation
#ifdef DOCSTRING_Loop
static const char *docstringLoop = R"(
\section{Loop}\label{loopType}
Generates a sequence with variables to loop over.
The variable names can be set with \config{variableLoop...} and
the current values are assigned to the variables for each loop step.
With \configClass{condition}{conditionType} only a subset of loop steps are performed.
The \config{variableLoopIndex} and \config{variableLoopCount} are not affected by the condition.
The result would therefore be the same as using \program{LoopPrograms} with a nested \program{IfPrograms}.
See \reference{Loop and conditions}{general.loopsAndConditions} for usage.
)";
#endif
/***********************************************/
#include "base/import.h"
#include "config/config.h"
#include "classes/condition/condition.h"
/**
* @defgroup loopGroup Loop
* @brief Loop config elements of programs.
* @ingroup classesGroup
* The interface is given by @ref Loop. */
/// @{
/***** TYPES ***********************************/
class Loop;
typedef std::shared_ptr<Loop> LoopPtr;
/***** CLASS ***********************************/
/** @brief Loop.
* An instance of this class can be created with @ref readConfig. */
class Loop
{
UInt index_;
Bool isCondition;
Config conditionConfig;
protected:
void readConfigCondition(Config &config);
Bool checkCondition(VariableList &varList);
public:
/// Destructor.
virtual ~Loop() {}
/** @brief Returns the approximate total number of iterations. */
virtual UInt count() const = 0;
/** @brief Returns the number of already performed iteration steps. */
UInt index() const {return index_;}
/** @brief Sets values of loop variables in @p varList for current iteration.
* @return valid iteration step? */
virtual Bool iteration(VariableList &varList) = 0;
/** @brief creates an derived instance of this class. */
static LoopPtr create(Config &config, const std::string &name);
};
/***** FUNCTIONS *******************************/
/** @brief Creates an instance of the class Loop.
* Search for a node with @a name in the Config node.
* if @a name is not found the function returns FALSE and @a loop is untouched.
* @param config The config node which includes the node with the options for this class
* @param name Tag name in the config.
* @param[out] loop Created class.
* @param mustSet If is MUSTSET and @a name is not found, this function throws an exception instead of returning with FALSE.
* @param defaultValue Ignored at the moment.
* @param annotation Description of the function of this class.
* @relates Loop */
template<> Bool readConfig(Config &config, const std::string &name, LoopPtr &loop, Config::Appearance mustSet, const std::string &defaultValue, const std::string &annotation);
/// @}
#endif /* __GROOPS_DERIVATION__ */
|