opm-common
KeywordLocation.hpp
1 /*
2  Copyright 2015 Statoil ASA.
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 KEYWORD_LOCATION_HPP
21 #define KEYWORD_LOCATION_HPP
22 
23 #include <string>
24 
25 namespace Opm {
26 
28 public:
29  /*
30  Observe that many error messages whcih should print out the name of the
31  problem keyword along with the location {} placeholders can be used. The
32  convention is:
33 
34  {keyword} -> keyword
35  {file} -> filename
36  {line} -> lineno
37 
38  This convention must be adhered to at the call site *creating the output
39  string*.
40  */
41 
42  std::string keyword;
43  std::string filename = "<memory string>";
44  std::size_t lineno = 0;
45  static constexpr std::size_t LINENO_BINARY = 99999999;
46 
47  KeywordLocation() = default;
48  KeywordLocation(std::string kw, std::string fname, std::size_t lno) :
49  keyword(std::move(kw)),
50  filename(std::move(fname)),
51  lineno(lno)
52  {}
53 
54  bool is_binary() const { return lineno == LINENO_BINARY; }
55  std::string format(const std::string& msg_fmt) const;
56 
57  static KeywordLocation serializationTestObject()
58  {
59  KeywordLocation result;
60  result.keyword = "KW";
61  result.filename = "test";
62  result.lineno = 1;
63 
64  return result;
65  }
66 
67  bool operator==(const KeywordLocation& data) const {
68  return keyword == data.keyword &&
69  filename == data.filename &&
70  lineno == data.lineno;
71  }
72 
73  template<class Serializer>
74  void serializeOp(Serializer& serializer)
75  {
76  serializer(keyword);
77  serializer(filename);
78  serializer(lineno);
79  }
80 };
81 
82 }
83 
84 #endif
Definition: KeywordLocation.hpp:27
This class implements a small container which holds the transmissibility mulitpliers for all the face...
Definition: Exceptions.hpp:30
Class for (de-)serializing.
Definition: Serializer.hpp:94