2013-05-06 12:13:49 +02:00
|
|
|
/*
|
|
|
|
|
Copyright 2013 Statoil ASA.
|
|
|
|
|
|
|
|
|
|
This file is part of the Open Porous Media project (OPM).
|
|
|
|
|
|
|
|
|
|
OPM is free software: you can redistribute it and/or modify
|
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
|
the Free Software Foundation, either version 3 of the License, or
|
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
|
|
OPM is distributed in the hope that it will be useful,
|
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
|
along with OPM. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
*/
|
|
|
|
|
#ifndef PARSER_ITEM_H
|
|
|
|
|
#define PARSER_ITEM_H
|
|
|
|
|
|
2016-10-23 16:14:02 +02:00
|
|
|
#include <iosfwd>
|
2013-05-06 12:13:49 +02:00
|
|
|
#include <string>
|
2016-10-23 16:14:02 +02:00
|
|
|
#include <vector>
|
2013-05-13 16:41:09 +02:00
|
|
|
|
2013-05-24 10:09:59 +02:00
|
|
|
#include <opm/parser/eclipse/Deck/DeckItem.hpp>
|
2016-10-23 16:14:02 +02:00
|
|
|
#include <opm/parser/eclipse/Utility/Typetools.hpp>
|
2019-03-27 07:39:59 +01:00
|
|
|
#include <opm/parser/eclipse/Parser/ParserEnums.hpp>
|
2013-05-06 12:13:49 +02:00
|
|
|
|
2016-01-24 21:49:39 +01:00
|
|
|
namespace Json {
|
|
|
|
|
class JsonObject;
|
|
|
|
|
}
|
|
|
|
|
|
2013-05-06 12:13:49 +02:00
|
|
|
namespace Opm {
|
2014-12-08 16:34:28 +01:00
|
|
|
|
2019-09-16 08:12:13 +02:00
|
|
|
class UnitSystem;
|
2016-10-23 16:14:02 +02:00
|
|
|
class RawRecord;
|
|
|
|
|
|
2019-03-27 07:39:59 +01:00
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
The ParserItem class describes one item handled by the parser. A parser
|
|
|
|
|
item is the schema for parsing values from the deck, when configuring the
|
|
|
|
|
ParserItem *two* types are in action:
|
|
|
|
|
|
|
|
|
|
InputType: These are the types specified when instantiating a
|
|
|
|
|
ParserItem, the available types are currently: INT, DOUBLE, STRING,
|
|
|
|
|
RAW_STRING and UDA.
|
|
|
|
|
|
|
|
|
|
DataType: This the C++ type of items generated when parsing the deck,
|
2019-08-10 16:18:29 +02:00
|
|
|
currently the available datatypes are int, double, std::string and
|
|
|
|
|
the user defined type UDAValue.
|
2019-03-27 07:39:59 +01:00
|
|
|
|
|
|
|
|
Splitting the type treatment in two layers in this way enables
|
|
|
|
|
properties/transformations to be added to the data before they are
|
|
|
|
|
internalized as data in a DataType instance; e.g. the difference between
|
|
|
|
|
STRING and RAW_STRING is that for the latter quotes and '*' tokens are
|
|
|
|
|
retained.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
2013-12-09 20:19:29 +01:00
|
|
|
class ParserItem {
|
|
|
|
|
public:
|
2016-10-23 16:14:02 +02:00
|
|
|
enum class item_size { ALL, SINGLE };
|
|
|
|
|
static item_size size_from_string( const std::string& );
|
|
|
|
|
static std::string string_from_size( item_size );
|
|
|
|
|
|
2019-08-10 16:18:29 +02:00
|
|
|
enum class itype {UNKNOWN, DOUBLE, INT, STRING, RAW_STRING, UDA, CODE};
|
2019-03-27 07:39:59 +01:00
|
|
|
static itype from_string(const std::string& string_value);
|
|
|
|
|
static std::string to_string(itype input_type);
|
|
|
|
|
std::string type_literal() const;
|
2016-10-23 16:14:02 +02:00
|
|
|
|
2019-03-27 07:39:59 +01:00
|
|
|
|
|
|
|
|
explicit ParserItem( const std::string& name, ParserItem::itype input_type );
|
|
|
|
|
explicit ParserItem( const Json::JsonObject& jsonConfig );
|
2013-12-11 13:24:27 +01:00
|
|
|
|
2016-10-23 16:14:02 +02:00
|
|
|
void push_backDimension( const std::string& );
|
2019-09-16 09:28:51 +02:00
|
|
|
const std::vector<std::string>& dimensions() const;
|
2013-12-09 20:19:29 +01:00
|
|
|
const std::string& name() const;
|
2016-10-23 16:14:02 +02:00
|
|
|
item_size sizeType() const;
|
2019-04-13 09:10:24 +02:00
|
|
|
type_tag dataType() const;
|
2019-03-27 07:39:59 +01:00
|
|
|
void setSizeType(item_size size_type);
|
2014-01-10 10:57:35 +01:00
|
|
|
std::string getDescription() const;
|
2014-04-10 22:29:18 +02:00
|
|
|
bool scalar() const;
|
2019-03-27 07:39:59 +01:00
|
|
|
void setDescription(const std::string& helpText);
|
2014-01-09 13:33:32 +01:00
|
|
|
|
2016-10-23 16:14:02 +02:00
|
|
|
template< typename T > void setDefault( T );
|
|
|
|
|
/* set type without a default value. will reset dimension etc. */
|
2019-03-27 07:39:59 +01:00
|
|
|
void setInputType( itype input_type );
|
2018-03-26 17:35:52 +02:00
|
|
|
bool parseRaw() const;
|
2016-10-23 16:14:02 +02:00
|
|
|
bool hasDefault() const;
|
|
|
|
|
template< typename T > const T& getDefault() const;
|
2014-09-13 11:02:23 +02:00
|
|
|
|
2016-10-23 16:14:02 +02:00
|
|
|
bool operator==( const ParserItem& ) const;
|
|
|
|
|
bool operator!=( const ParserItem& ) const;
|
2014-09-13 11:02:23 +02:00
|
|
|
|
2019-09-16 08:12:13 +02:00
|
|
|
DeckItem scan( RawRecord& rawRecord, UnitSystem& active_unitsystem, UnitSystem& default_unitsystem) const;
|
2019-03-27 07:39:59 +01:00
|
|
|
|
|
|
|
|
std::string size_literal() const;
|
2016-10-23 16:14:02 +02:00
|
|
|
const std::string className() const;
|
2019-03-27 07:39:59 +01:00
|
|
|
std::string createCode(const std::string& indent) const;
|
2016-10-23 16:14:02 +02:00
|
|
|
std::ostream& inlineClass(std::ostream&, const std::string& indent) const;
|
|
|
|
|
std::string inlineClassInit(const std::string& parentClass,
|
|
|
|
|
const std::string* defaultValue = nullptr ) const;
|
2013-05-13 16:41:09 +02:00
|
|
|
|
2013-12-09 20:19:29 +01:00
|
|
|
private:
|
2016-10-23 16:14:02 +02:00
|
|
|
double dval;
|
|
|
|
|
int ival;
|
|
|
|
|
std::string sval;
|
2019-04-13 09:10:24 +02:00
|
|
|
UDAValue uval;
|
2019-09-16 09:28:51 +02:00
|
|
|
std::vector< std::string > m_dimensions;
|
2016-10-23 16:14:02 +02:00
|
|
|
|
2013-12-09 20:19:29 +01:00
|
|
|
std::string m_name;
|
2019-03-27 07:39:59 +01:00
|
|
|
item_size m_sizeType = item_size::SINGLE;
|
2014-01-10 10:57:35 +01:00
|
|
|
std::string m_description;
|
2015-04-23 11:31:10 +02:00
|
|
|
|
2019-03-27 07:39:59 +01:00
|
|
|
type_tag data_type = type_tag::unknown;
|
|
|
|
|
itype input_type = itype::UNKNOWN;
|
2016-10-23 16:14:02 +02:00
|
|
|
bool m_defaultSet;
|
2014-08-21 14:41:49 +02:00
|
|
|
|
2016-10-23 16:14:02 +02:00
|
|
|
template< typename T > T& value_ref();
|
|
|
|
|
template< typename T > const T& value_ref() const;
|
2019-03-27 07:39:59 +01:00
|
|
|
template< typename T > void setDataType( T );
|
2016-10-23 16:14:02 +02:00
|
|
|
friend std::ostream& operator<<( std::ostream&, const ParserItem& );
|
|
|
|
|
};
|
2014-12-08 16:34:28 +01:00
|
|
|
|
2016-10-23 16:14:02 +02:00
|
|
|
std::ostream& operator<<( std::ostream&, const ParserItem::item_size& );
|
2014-08-21 14:41:49 +02:00
|
|
|
|
2013-05-08 14:31:20 +02:00
|
|
|
}
|
2013-05-06 12:13:49 +02:00
|
|
|
|
2013-05-08 14:31:20 +02:00
|
|
|
#endif
|