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>
|
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
|
|
|
|
2016-10-23 16:14:02 +02:00
|
|
|
class RawRecord;
|
|
|
|
|
|
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 );
|
|
|
|
|
|
|
|
|
|
explicit ParserItem( const std::string& name );
|
|
|
|
|
ParserItem( const std::string& name, item_size );
|
|
|
|
|
template< typename T >
|
|
|
|
|
ParserItem( const std::string& item_name, T val ) :
|
|
|
|
|
ParserItem( item_name, item_size::SINGLE, std::move( val ) ) {}
|
|
|
|
|
ParserItem( const std::string& name, item_size, int defaultValue );
|
|
|
|
|
ParserItem( const std::string& name, item_size, double defaultValue );
|
|
|
|
|
ParserItem( const std::string& name, item_size, std::string defaultValue );
|
|
|
|
|
|
2013-12-17 15:56:12 +01:00
|
|
|
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& );
|
|
|
|
|
const std::string& getDimension(size_t index) const;
|
|
|
|
|
bool hasDimension() const;
|
|
|
|
|
size_t numDimensions() 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;
|
2014-01-10 10:57:35 +01:00
|
|
|
std::string getDescription() const;
|
2014-04-10 22:29:18 +02:00
|
|
|
bool scalar() const;
|
2014-01-10 10:57:35 +01:00
|
|
|
void setDescription(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. */
|
|
|
|
|
template< typename T > void setType( T );
|
|
|
|
|
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
|
|
|
|
2016-10-23 16:14:02 +02:00
|
|
|
DeckItem scan( RawRecord& rawRecord ) const;
|
|
|
|
|
const std::string className() const;
|
|
|
|
|
std::string createCode() const;
|
|
|
|
|
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;
|
|
|
|
|
std::vector< std::string > dimensions;
|
|
|
|
|
|
2013-12-09 20:19:29 +01:00
|
|
|
std::string m_name;
|
2016-10-23 16:14:02 +02:00
|
|
|
item_size m_sizeType;
|
2014-01-10 10:57:35 +01:00
|
|
|
std::string m_description;
|
2015-04-23 11:31:10 +02:00
|
|
|
|
2016-10-23 16:14:02 +02:00
|
|
|
type_tag type = type_tag::unknown;
|
|
|
|
|
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;
|
|
|
|
|
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
|