-
-
Notifications
You must be signed in to change notification settings - Fork 108
Expand file tree
/
Copy pathUtilities.C
More file actions
74 lines (70 loc) · 2.02 KB
/
Utilities.C
File metadata and controls
74 lines (70 loc) · 2.02 KB
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
#include "Utilities.H"
#include <cctype>
using namespace Foam;
void adapterInfo(const std::string message, const std::string level)
{
if (level.compare("info") == 0)
{
// Prepend the message with a string
Info << INFO_STR_ADAPTER
<< message.c_str()
<< nl;
}
else if (level.compare("warning") == 0)
{
// Produce a warning message with cyan header
WarningInFunction
<< "\033[36m" // cyan color
<< "Warning in the preCICE adapter: "
<< "\033[0m" // restore color
<< nl
<< message.c_str()
<< nl
<< nl;
}
else if (level.compare("error") == 0)
{
// Produce an error message with red header
// and exit the functionObject.
// It will also exit the simulation, unless it
// is called inside the functionObject's read().
FatalError
<< "\033[31m" // red color
<< "Error in the preCICE adapter: "
<< "\033[0m" // restore color
<< nl
<< message.c_str()
<< nl
<< exit(FatalError);
}
else if (level.compare("debug") == 0)
{
Pout << INFO_STR_ADAPTER
<< "[DEBUG] "
<< message.c_str()
<< nl;
}
else if (level.compare("dev") == 0)
{
Info << "\033[35m" // cyan color
<< INFO_STR_ADAPTER
<< "[under development] "
<< "\033[0m " // restore color
<< message.c_str()
<< nl;
}
else
{
Info << INFO_STR_ADAPTER
<< "[unknown info level] "
<< message.c_str()
<< nl;
}
return;
}
bool matchingStrings(std::string s, std::string match)
{
std::transform(s.begin(), s.end(), s.begin(), [](unsigned char c) { return std::tolower(c); });
std::transform(match.begin(), match.end(), match.begin(), [](unsigned char c) { return std::tolower(c); });
return s.find(match) == 0;
}