File: ifPrograms.cpp

package info (click to toggle)
groops 0%2Bgit20250907%2Bds-1
  • links: PTS, VCS
  • area: non-free
  • in suites: forky, sid
  • size: 11,140 kB
  • sloc: cpp: 135,607; fortran: 1,603; makefile: 20
file content (71 lines) | stat: -rw-r--r-- 1,983 bytes parent folder | download | duplicates (2)
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
/***********************************************/
/**
* @file ifPrograms.cpp
*
* @brief Runs programs if condition is met.
*
* @author Andreas Kvas
* @date 2017-01-04
*/
/***********************************************/

// Latex documentation
#define DOCSTRING docstring
static const char *docstring = R"(
Runs a list of \config{program}s if a \configClass{condition}{conditionType} is met.
Otherwise \config{elseProgram}s are executed.
)";

/***********************************************/

#include "programs/program.h"
#include "classes/condition/condition.h"

/***** CLASS ***********************************/

/** @brief  Runs programs if condition is met.
* @ingroup programsGroup */
class IfPrograms
{
public:
  void run(Config &config, Parallel::CommunicatorPtr comm);
};

GROOPS_REGISTER_PROGRAM(IfPrograms, PARALLEL, "Runs programs if condition is met.", System)
GROOPS_RENAMED_PROGRAM(IfProgramme, IfPrograms, date2time(2020, 6, 3))

/***********************************************/

void IfPrograms::run(Config &config, Parallel::CommunicatorPtr comm)
{
  try
  {
    ConditionPtr  conditionPtr;
    ProgramConfig programs, elsePrograms;

    renameDeprecatedConfig(config, "programme", "program", date2time(2020, 6, 3));

    readConfig(config, "condition",   conditionPtr, Config::MUSTSET,  "", "");
    readConfig(config, "program",     programs,     Config::OPTIONAL, "", "executed if condition evaluates to true");
    readConfig(config, "elseProgram", elsePrograms, Config::OPTIONAL, "", "executed if condition evaluates to false");
    if(isCreateSchema(config)) return;

    VariableList varList;
    if(conditionPtr->condition(varList))
    {
      logInfo<<"  condition is true."<<Log::endl;
      programs.run(varList, comm);
    }
    else
    {
      logInfo<<"  condition is false."<<Log::endl;
      elsePrograms.run(varList, comm);
    }
  }
  catch(std::exception &e)
  {
    GROOPS_RETHROW(e)
  }
}

/***********************************************/