Deck.hpp
Go to the documentation of this file.
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 DECK_HPP
21#define DECK_HPP
22
23#include <map>
24#include <memory>
25#include <ostream>
26#include <vector>
27#include <string>
28
31
32#ifdef OPM_PARSER_DECK_API_WARNING
33#ifndef OPM_PARSER_DECK_API
34#pragma message "\n\n" \
35" ----------------------------------------------------------------------------------\n" \
36" The current compilation unit includes the header Deck.hpp. Outside of opm-parser \n" \
37" you are encouraged to use the EclipseState API instead of the low level Deck API. \n" \
38" If use of the Deck API is absolutely necessary you can silence this warning with \n" \
39" #define OPM_PARSER_DECK_API before including the Deck.hpp header. \n" \
40" ----------------------------------------------------------------------------------\n" \
41""
42#endif
43#endif
44
45
47namespace Opm {
48
49 /*
50 * The Deck (container) class owns all memory given to it via .addX(), as
51 * do all inner objects. This means that the Deck object itself must stay
52 * alive as long as DeckItem (and friends) are needed, to avoid
53 * use-after-free.
54 */
55 class DeckOutput;
56
57 class DeckView {
58 public:
59 typedef std::vector< DeckKeyword >::const_iterator const_iterator;
60
61 bool hasKeyword( const DeckKeyword& keyword ) const;
62 bool hasKeyword( const std::string& keyword ) const;
63 template< class Keyword >
64 bool hasKeyword() const {
65 return hasKeyword( Keyword::keywordName );
66 }
67
68 const DeckKeyword& getKeyword( const std::string& keyword, size_t index ) const;
69 const DeckKeyword& getKeyword( const std::string& keyword ) const;
70 const DeckKeyword& getKeyword( size_t index ) const;
72 template< class Keyword >
73 const DeckKeyword& getKeyword() const {
74 return getKeyword( Keyword::keywordName );
75 }
76 template< class Keyword >
77 const DeckKeyword& getKeyword( size_t index ) const {
78 return getKeyword( Keyword::keywordName, index );
79 }
80 template< class Keyword >
81 std::size_t count() const {
82 return count( Keyword::keywordName );
83 }
84
85 const std::vector< const DeckKeyword* > getKeywordList( const std::string& keyword ) const;
86 template< class Keyword >
87 const std::vector< const DeckKeyword* > getKeywordList() const {
88 return getKeywordList( Keyword::keywordName );
89 }
90
91 size_t count(const std::string& keyword) const;
92 size_t size() const;
93
96
97
98 protected:
100
101 const std::vector< size_t >& offsets( const std::string& ) const;
102
104 explicit DeckView( std::pair< const_iterator, const_iterator > );
105 DeckView() = default;
107
108 private:
109 const_iterator first;
110 const_iterator last;
111 std::map< std::string, std::vector< size_t > > keywordMap;
112
113 };
114
115 class Deck : private DeckView {
116 public:
121 using DeckView::count;
122 using DeckView::size;
123 using DeckView::begin;
124 using DeckView::end;
125
126 using iterator = std::vector< DeckKeyword >::iterator;
127
129 Deck( const Deck& );
130
132
133 Deck& operator=(const Deck& rhs);
134 bool operator==(const Deck& data) const;
135
138
140
146
147 const std::string& getInputPath() const;
148 const std::string& getDataFile() const;
149 void setDataFile(const std::string& dataFile);
151
154 void write( DeckOutput& output ) const ;
155 friend std::ostream& operator<<(std::ostream& os, const Deck& deck);
156
157 template<class Serializer>
158 void serializeOp(Serializer& serializer)
159 {
160 serializer.vector(keywordList);
161 defaultUnits.serializeOp(serializer);
162 serializer(activeUnits);
163 serializer(m_dataFile);
164 serializer(input_path);
165 serializer(unit_system_access_count);
166 if (!serializer.isSerializing())
167 this->init(this->keywordList.begin(), this->keywordList.end());
168 }
169
170 private:
171 Deck(std::vector<DeckKeyword>&& keywordList);
172
173 std::vector< DeckKeyword > keywordList;
174 UnitSystem defaultUnits;
175 std::unique_ptr<UnitSystem> activeUnits;
176
177 std::string m_dataFile;
178 std::string input_path;
179 mutable std::size_t unit_system_access_count = 0;
180 };
181}
182#endif /* DECK_HPP */
int index
Definition: cJSON.h:168
const char *const string
Definition: cJSON.h:170
Definition: DeckKeyword.hpp:38
Definition: DeckOutput.hpp:29
Definition: Deck.hpp:115
iterator end()
friend std::ostream & operator<<(std::ostream &os, const Deck &deck)
const UnitSystem & getDefaultUnitSystem() const
void setDataFile(const std::string &dataFile)
std::vector< DeckKeyword >::iterator iterator
Definition: Deck.hpp:126
void addKeyword(const DeckKeyword &keyword)
UnitSystem & getDefaultUnitSystem()
void addKeyword(DeckKeyword &&keyword)
const std::string & getInputPath() const
const UnitSystem & getActiveUnitSystem() const
void serializeOp(Serializer &serializer)
Definition: Deck.hpp:158
const std::string & getDataFile() const
iterator begin()
UnitSystem & getActiveUnitSystem()
Deck & operator=(const Deck &rhs)
Deck(const Deck &)
bool operator==(const Deck &data) const
void selectActiveUnitSystem(UnitSystem::UnitType unit_type)
static Deck serializeObject()
void write(DeckOutput &output) const
std::string makeDeckPath(const std::string &path) const
DeckKeyword & getKeyword(size_t)
Definition: Deck.hpp:57
void add(const DeckKeyword *, const_iterator, const_iterator)
bool hasKeyword(const std::string &keyword) const
const DeckKeyword & getKeyword(size_t index) const
bool hasKeyword(const DeckKeyword &keyword) const
DeckView()=default
size_t size() const
const std::vector< const DeckKeyword * > getKeywordList() const
Definition: Deck.hpp:87
const_iterator end() const
DeckView(const_iterator first, const_iterator last)
const DeckKeyword & getKeyword() const
Definition: Deck.hpp:73
const std::vector< size_t > & offsets(const std::string &) const
const_iterator begin() const
void init(const_iterator, const_iterator)
bool hasKeyword() const
Definition: Deck.hpp:64
std::vector< DeckKeyword >::const_iterator const_iterator
Definition: Deck.hpp:59
const DeckKeyword & getKeyword(size_t index) const
Definition: Deck.hpp:77
const std::vector< const DeckKeyword * > getKeywordList(const std::string &keyword) const
size_t count(const std::string &keyword) const
std::size_t count() const
Definition: Deck.hpp:81
DeckView(std::pair< const_iterator, const_iterator >)
const DeckKeyword & getKeyword(const std::string &keyword, size_t index) const
const DeckKeyword & getKeyword(const std::string &keyword) const
DeckKeyword & getKeyword(size_t index)
Definition: Serializer.hpp:38
Definition: UnitSystem.hpp:32
void serializeOp(Serializer &serializer)
Definition: UnitSystem.hpp:121
UnitType
Definition: UnitSystem.hpp:34
UDAKeyword keyword(UDAControl control)
Definition: A.hpp:4
static std::string data()
Definition: exprtk.hpp:40022