DeckItem.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 DECKITEM_HPP
21 #define DECKITEM_HPP
22 
24 
25 #include <stdexcept>
26 #include <string>
27 #include <vector>
28 #include <memory>
29 
30 namespace Opm {
31  class DeckItem {
32  public:
33  DeckItem(const std::string& name , bool m_scalar = true);
34  const std::string& name() const;
35 
36  // return true if the default value was used for a given data point
37  bool defaultApplied(size_t index) const;
38 
39  // Return true if the item has a value for the current index;
40  // does not differentiate between default values from the
41  // config and values which have been set in the deck.
42  bool hasValue(size_t index) const;
43 
44  // if the number returned by this method is less than what is semantically
45  // expected (e.g. size() is less than the number of cells in the grid for
46  // keywords like e.g. SGL), then the remaining values are defaulted. The deck
47  // creates the defaulted items if all their sizes are fully specified by the
48  // keyword, though...
49  virtual size_t size() const = 0;
50 
51  virtual int getInt(size_t /* index */) const {
52  throw std::logic_error("This implementation of DeckItem does not support int");
53  }
54 
55  virtual float getSIFloat(size_t /* index */) const {
56  throw std::logic_error("This implementation of DeckItem does not support float");
57  }
58 
59  virtual float getRawFloat(size_t /* index */) const {
60  throw std::logic_error("This implementation of DeckItem does not support float");
61  }
62 
63  virtual double getSIDouble(size_t /* index */) const {
64  throw std::logic_error("This implementation of DeckItem does not support double");
65  }
66 
67  virtual double getRawDouble(size_t /* index */) const {
68  throw std::logic_error("This implementation of DeckItem does not support double");
69  }
70 
71  virtual bool getBool(size_t /* index */) const {
72  throw std::logic_error("This implementation of DeckItem does not support bool");
73  }
74 
75  virtual const std::string& getString(size_t /* index */) const {
76  throw std::logic_error("This implementation of DeckItem does not support string");
77  }
78 
79  virtual std::string getTrimmedString(size_t /* index */) const {
80  throw std::logic_error("This implementation of DeckItem does not support trimmed strings");
81  }
82 
83  virtual const std::vector<int>& getIntData( ) const {
84  throw std::logic_error("This implementation of DeckItem does not support int");
85  }
86 
87  virtual const std::vector<double>& getSIDoubleData() const {
88  throw std::logic_error("This implementation of DeckItem does not support double");
89  }
90 
91  virtual const std::vector<double>& getRawDoubleData() const {
92  throw std::logic_error("This implementation of DeckItem does not support double");
93  }
94 
95  virtual const std::vector<float>& getSIFloatData() const {
96  throw std::logic_error("This implementation of DeckItem does not support float");
97  }
98 
99  virtual const std::vector<float>& getRawFloatData() const {
100  throw std::logic_error("This implementation of DeckItem does not support float");
101  }
102 
103 
104  virtual const std::vector<std::string>& getStringData() const {
105  throw std::logic_error("This implementation of DeckItem does not support string");
106  }
107 
108  virtual void push_backDimension(std::shared_ptr<const Dimension> /* activeDimension */,
109  std::shared_ptr<const Dimension> /* defaultDimension */) {
110  throw std::invalid_argument("Should not be here - internal error ...");
111  }
112 
113  virtual ~DeckItem() {
114  }
115 
116  protected:
117  void assertSize(size_t index) const;
118 
119  std::vector<bool> m_dataPointDefaulted;
120 
121  private:
122  std::string m_name;
123  bool m_scalar;
124  };
125 
126  typedef std::shared_ptr<DeckItem> DeckItemPtr;
127  typedef std::shared_ptr<const DeckItem> DeckItemConstPtr;
128 }
129 #endif /* DECKITEM_HPP */
130 
virtual const std::string & getString(size_t) const
Definition: DeckItem.hpp:75
virtual std::string getTrimmedString(size_t) const
Definition: DeckItem.hpp:79
virtual const std::vector< double > & getRawDoubleData() const
Definition: DeckItem.hpp:91
std::shared_ptr< DeckItem > DeckItemPtr
Definition: DeckItem.hpp:126
Definition: Deck.hpp:29
bool defaultApplied(size_t index) const
void assertSize(size_t index) const
virtual const std::vector< float > & getRawFloatData() const
Definition: DeckItem.hpp:99
virtual double getSIDouble(size_t) const
Definition: DeckItem.hpp:63
std::shared_ptr< const DeckItem > DeckItemConstPtr
Definition: DeckItem.hpp:127
virtual bool getBool(size_t) const
Definition: DeckItem.hpp:71
const std::string & name() const
virtual const std::vector< int > & getIntData() const
Definition: DeckItem.hpp:83
bool hasValue(size_t index) const
virtual size_t size() const =0
virtual double getRawDouble(size_t) const
Definition: DeckItem.hpp:67
virtual void push_backDimension(std::shared_ptr< const Dimension >, std::shared_ptr< const Dimension >)
Definition: DeckItem.hpp:108
virtual const std::vector< std::string > & getStringData() const
Definition: DeckItem.hpp:104
Definition: DeckItem.hpp:31
virtual const std::vector< double > & getSIDoubleData() const
Definition: DeckItem.hpp:87
virtual int getInt(size_t) const
Definition: DeckItem.hpp:51
virtual const std::vector< float > & getSIFloatData() const
Definition: DeckItem.hpp:95
virtual ~DeckItem()
Definition: DeckItem.hpp:113
std::vector< bool > m_dataPointDefaulted
Definition: DeckItem.hpp:119
DeckItem(const std::string &name, bool m_scalar=true)
virtual float getSIFloat(size_t) const
Definition: DeckItem.hpp:55
virtual float getRawFloat(size_t) const
Definition: DeckItem.hpp:59