My Project
Loading...
Searching...
No Matches
StarToken.hpp
1/*
2 Copyright 2013 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 STAR_TOKEN_HPP
21#define STAR_TOKEN_HPP
22
23#include <cctype>
24#include <string>
25
26#include <opm/input/eclipse/Utility/Typetools.hpp>
27
28namespace Opm {
29 bool isStarToken(const std::string_view& token,
30 std::string& countString,
31 std::string& valueString);
32
33 template <class T>
34 T readValueToken( std::string_view );
35
36class StarToken {
37public:
38 StarToken(const std::string_view& token)
39 {
40 if (!isStarToken(token, m_countString, m_valueString))
41 throw std::invalid_argument("Token \""+ std::string(token) +"\" is not a repetition specifier");
42 init_(token);
43 }
44
45 StarToken(const std::string_view& token, const std::string& countStr, const std::string& valueStr)
46 : m_countString(countStr)
47 , m_valueString(valueStr)
48 {
49 init_(token);
50 }
51
52 std::size_t count() const {
53 return m_count;
54 }
55
56 bool hasValue() const {
57 return !m_valueString.empty();
58 }
59
60 // returns the coubt as rendered in the deck. note that this might be different
61 // than just converting the return value of count() to a string because an empty
62 // count is interpreted as 1...
63 const std::string& countString() const {
64 return m_countString;
65 }
66
67 // returns the value as rendered in the deck. note that this might be different
68 // than just converting the return value of value() to a string because values
69 // might have different representations in the deck (e.g. strings can be
70 // specified with and without quotes and but spaces are only allowed using the
71 // first representation.)
72 const std::string& valueString() const {
73 return m_valueString;
74 }
75
76private:
77 // internal initialization method. the m_countString and m_valueString attributes
78 // must be set before calling this method.
79 void init_(const std::string_view& token);
80
81 std::size_t m_count;
82 std::string m_countString;
83 std::string m_valueString;
84};
85}
86
87
88#endif
Definition StarToken.hpp:36
This class implements a small container which holds the transmissibility mulitpliers for all the face...
Definition Exceptions.hpp:30