opm-common
Toggle main menu visibility
Loading...
Searching...
No Matches
MessageFormatter.hpp
1
/*
2
Copyright 2016 SINTEF ICT, Applied Mathematics.
3
4
This file is part of the Open Porous Media project (OPM).
5
6
OPM is free software: you can redistribute it and/or modify
7
it under the terms of the GNU General Public License as published by
8
the Free Software Foundation, either version 3 of the License, or
9
(at your option) any later version.
10
11
OPM is distributed in the hope that it will be useful,
12
but WITHOUT ANY WARRANTY; without even the implied warranty of
13
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
GNU General Public License for more details.
15
16
You should have received a copy of the GNU General Public License
17
along with OPM. If not, see <http://www.gnu.org/licenses/>.
18
*/
19
20
#ifndef OPM_MESSAGEFORMATTER_HEADER_INCLUDED
21
#define OPM_MESSAGEFORMATTER_HEADER_INCLUDED
22
23
#include <opm/common/OpmLog/LogUtil.hpp>
24
#include <string>
25
26
namespace
Opm
27
{
28
29
31
class
MessageFormatterInterface
32
{
33
public
:
35
virtual
~MessageFormatterInterface
() =
default
;
39
virtual
std::string
format
(
const
int64_t message_flag,
const
std::string& message) = 0;
40
};
41
42
43
44
45
47
class
SimpleMessageFormatter
:
public
MessageFormatterInterface
48
{
49
public
:
51
SimpleMessageFormatter
(
const
bool
use_prefix,
const
bool
use_color_coding)
52
: use_color_coding_(use_color_coding)
53
{
54
if
(use_prefix) {
55
prefix_flag_ = Log::DefaultMessageTypes;
56
}
57
}
58
59
60
SimpleMessageFormatter
(
const
int64_t prefix_flag,
const
bool
use_color_coding)
61
: use_color_coding_(use_color_coding),
62
prefix_flag_(prefix_flag)
63
{
64
}
65
66
67
explicit
SimpleMessageFormatter
(
const
bool
use_color_coding)
68
: use_color_coding_(use_color_coding)
69
{
70
prefix_flag_ = Log::MessageType::Warning + Log::MessageType::Error
71
+ Log::MessageType::Problem + Log::MessageType::Bug;
72
}
76
virtual
std::string
format
(
const
int64_t message_flag,
const
std::string& message)
override
77
{
78
std::string msg = message;
79
if
(message_flag & prefix_flag_) {
80
msg = Log::prefixMessage(message_flag, msg);
81
}
82
if
(use_color_coding_) {
83
msg = Log::colorCodeMessage(message_flag, msg);
84
}
85
return
msg;
86
}
87
private
:
88
bool
use_color_coding_ =
false
;
89
int64_t prefix_flag_ = 0;
90
};
91
92
93
}
// namespace Opm
94
95
#endif
// OPM_MESSAGEFORMATTER_HEADER_INCLUDED
Opm::MessageFormatterInterface
Abstract interface for message formatting classes.
Definition
MessageFormatter.hpp:32
Opm::MessageFormatterInterface::~MessageFormatterInterface
virtual ~MessageFormatterInterface()=default
Virtual destructor to enable inheritance.
Opm::MessageFormatterInterface::format
virtual std::string format(const int64_t message_flag, const std::string &message)=0
Should return a possibly modified/decorated version of the input string, the formatting applied depen...
Opm::SimpleMessageFormatter::format
virtual std::string format(const int64_t message_flag, const std::string &message) override
Returns a copy of the input string with a flag-dependant prefix (if use_prefix) and the entire messag...
Definition
MessageFormatter.hpp:76
Opm::SimpleMessageFormatter::SimpleMessageFormatter
SimpleMessageFormatter(const bool use_prefix, const bool use_color_coding)
Constructor controlling formatting to be applied.
Definition
MessageFormatter.hpp:51
Opm
This class implements a small container which holds the transmissibility mulitpliers for all the face...
Definition
Exceptions.hpp:30
opm
common
OpmLog
MessageFormatter.hpp
Generated by
1.17.0