opm-common
RawConsts.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 RAWCONSTS_HPP
21 #define RAWCONSTS_HPP
22 
23 #include <string>
24 
25 namespace Opm {
26 
28  namespace RawConsts {
29  const char slash = '/';
30  const char quote = '\'';
31  const std::string include = "INCLUDE";
32  const std::string end = "END";
33  const std::string endinclude = "ENDINC";
34  const std::string paths = "PATHS";
35  const std::string pyinput = "PYINPUT";
36  const unsigned int maxKeywordLength = 8;
37 
38  /* The lookup uses some bit-tricks to achieve branchless lookup in the
39  * table. It has a robustness weakness because all input characters
40  * that are non-ascii will be interpreted only by their 7 smallest
41  * bits. However:
42  * * only ascii input is supported, so a non-ascii input deck
43  * is fundamentally broken
44  * * the underlying storage is still char which when signed is
45  * +-127
46  * * it's reasonable to assume non-ascii input only shows up in
47  * comments, which most of the time will be skipped when
48  * looking for separators
49  */
50 
51  constexpr bool sep_table[ 128 ] = {
52  0, 1, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 0, 0,
53  0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
54  1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0,
55  0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
56  0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
57  0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
58  0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
59  0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
60  };
61 
62  struct is_separator {
63  /*
64  * ch is SOH (ASCII 1), space, comma, \r, \n, \t, \v or \f => true
65  * else false
66  */
67  constexpr bool operator()( int ch ) const {
68  return sep_table[ ch & 0x7f ];
69  }
70  };
71 
72  constexpr bool q_table[ 128 ] = {
73  0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
74  0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
75  0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0,
76  0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
77  0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
78  0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
79  0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
80  0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
81  };
82 
83  struct is_quote {
84  /*
85  * ch is ' or " => true
86  * else false
87  */
88  constexpr bool operator()( int ch ) const {
89  return q_table[ ch & 0x7f ];
90  }
91  };
92  }
93 }
94 
95 
96 #endif /* RAWCONSTS_HPP */
Definition: RawConsts.hpp:83
This class implements a small container which holds the transmissibility mulitpliers for all the face...
Definition: Exceptions.hpp:30
Definition: RawConsts.hpp:62