File: conditionFileExist.h

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 (80 lines) | stat: -rw-r--r-- 1,810 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
72
73
74
75
76
77
78
79
80
/***********************************************/
/**
* @file conditionFileExist.h
*
* @brief Check for a file or directory existing.
*
* @author Torsten Mayer-Guerr
* @date 2018-08-18
*
*/
/***********************************************/

#ifndef __GROOPS_CONDITIONFILEEXIST__
#define __GROOPS_CONDITIONFILEEXIST__

// Latex documentation
#ifdef DOCSTRING_Condition
static const char *docstringConditionFileExist = R"(
\subsection{FileExist}
Check for a file or directory existing.
Supports wildcards * for any number of characters and ? for exactly one character.
)";
#endif

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

#include "base/import.h"
#include "parallel/parallel.h"
#include "inputOutput/system.h"
#include "classes/condition/condition.h"

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

/** @brief Check for a file or directory existing.
* @ingroup conditionGroup
* @see Condition */
class ConditionFileExist : public Condition
{
  FileName fileName;

public:
  ConditionFileExist(Config &config);

  Bool condition(const VariableList &varList) const;
};

/***********************************************/
/***** Inlines *********************************/
/***********************************************/

inline ConditionFileExist::ConditionFileExist(Config &config)
{
  try
  {
    readConfig(config, "file", fileName, Config::MUSTSET, "", "supports wildcards: * and ?");
    if(isCreateSchema(config)) return;
  }
  catch(std::exception &e)
  {
    GROOPS_RETHROW(e)
  }
}

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

inline Bool ConditionFileExist::condition(const VariableList &varList) const
{
  try
  {
    return System::exists(fileName(varList));
  }
  catch(std::exception &e)
  {
    GROOPS_RETHROW(e)
  }
}

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

#endif