2013-05-06 09:48:29 +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/>.
|
2013-05-06 12:13:49 +02:00
|
|
|
*/
|
2013-05-06 09:48:29 +02:00
|
|
|
|
2013-05-08 14:31:20 +02:00
|
|
|
#include <boost/lexical_cast.hpp>
|
2013-05-09 12:17:00 +02:00
|
|
|
|
2013-05-13 16:41:09 +02:00
|
|
|
#include <opm/parser/eclipse/Parser/ParserItem.hpp>
|
2013-05-07 21:55:49 +02:00
|
|
|
#include <opm/parser/eclipse/Parser/ParserIntItem.hpp>
|
2013-05-09 12:17:00 +02:00
|
|
|
#include <opm/parser/eclipse/Parser/ParserEnums.hpp>
|
2013-06-20 13:56:11 +02:00
|
|
|
#include <opm/parser/eclipse/Deck/DeckIntItem.hpp>
|
2013-05-06 09:48:29 +02:00
|
|
|
|
2013-05-08 14:31:20 +02:00
|
|
|
|
2013-05-07 21:55:49 +02:00
|
|
|
namespace Opm {
|
2013-05-08 14:31:20 +02:00
|
|
|
|
2013-05-09 14:18:36 +02:00
|
|
|
ParserIntItem::ParserIntItem(const std::string& itemName, ParserItemSizeEnum sizeType) : ParserItem(itemName, sizeType) {
|
|
|
|
|
m_default = defaultInt();
|
|
|
|
|
}
|
2013-06-20 13:56:11 +02:00
|
|
|
|
2013-05-09 14:18:36 +02:00
|
|
|
ParserIntItem::ParserIntItem(const std::string& itemName, ParserItemSizeEnum sizeType, int defaultValue) : ParserItem(itemName, sizeType) {
|
|
|
|
|
m_default = defaultValue;
|
|
|
|
|
}
|
2013-06-20 13:56:11 +02:00
|
|
|
|
|
|
|
|
DeckItemConstPtr ParserIntItem::scan(size_t expectedItems, RawRecordPtr rawRecord) const {
|
|
|
|
|
return scan__(expectedItems, false, rawRecord);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
DeckItemConstPtr ParserIntItem::scan(RawRecordPtr rawRecord) const {
|
|
|
|
|
if (sizeType() == SINGLE)
|
|
|
|
|
return scan(1U, rawRecord);
|
|
|
|
|
else if (sizeType() == ALL)
|
|
|
|
|
return scan__(0, true, rawRecord);
|
|
|
|
|
else
|
|
|
|
|
throw std::invalid_argument("Unsupported size type, only support SINGLE and ALL. Use scan( numTokens , rawRecord) instead ");
|
|
|
|
|
}
|
2013-05-09 12:17:00 +02:00
|
|
|
|
2013-05-08 14:31:20 +02:00
|
|
|
/// Scans the rawRecords data according to the ParserItems definition.
|
2013-05-24 10:09:59 +02:00
|
|
|
/// returns a DeckItem object.
|
2013-05-08 14:31:20 +02:00
|
|
|
/// NOTE: data are popped from the rawRecords deque!
|
2013-06-20 13:56:11 +02:00
|
|
|
|
|
|
|
|
DeckItemConstPtr ParserIntItem::scan__(size_t expectedItems, bool scanAll, RawRecordPtr rawRecord) const {
|
|
|
|
|
if (sizeType() == SINGLE && expectedItems > 1) {
|
2013-05-13 16:41:09 +02:00
|
|
|
throw std::invalid_argument("Can only ask for one item when sizeType == SINGLE");
|
2013-06-20 13:56:11 +02:00
|
|
|
}
|
2013-05-13 16:41:09 +02:00
|
|
|
|
2013-05-09 12:17:00 +02:00
|
|
|
{
|
2013-05-23 12:42:59 +02:00
|
|
|
DeckIntItemPtr deckItem(new DeckIntItem(name()));
|
2013-06-20 13:56:11 +02:00
|
|
|
|
|
|
|
|
if ((expectedItems > 0) || scanAll) {
|
2013-05-10 13:56:41 +02:00
|
|
|
bool defaultActive;
|
2013-06-20 13:56:11 +02:00
|
|
|
std::vector<int> intsPreparedForDeckItem = readFromRawRecord(rawRecord, scanAll, expectedItems, m_default, defaultActive);
|
|
|
|
|
|
2013-05-13 16:41:09 +02:00
|
|
|
if (scanAll)
|
|
|
|
|
deckItem->push_back(intsPreparedForDeckItem);
|
|
|
|
|
else if (intsPreparedForDeckItem.size() >= expectedItems) {
|
2013-06-20 13:56:11 +02:00
|
|
|
deckItem->push_back(intsPreparedForDeckItem, expectedItems);
|
|
|
|
|
|
|
|
|
|
if (intsPreparedForDeckItem.size() > expectedItems)
|
|
|
|
|
pushBackToRecord(rawRecord, intsPreparedForDeckItem, expectedItems, defaultActive);
|
2013-05-13 16:41:09 +02:00
|
|
|
|
2013-05-10 13:56:41 +02:00
|
|
|
} else {
|
2013-05-09 12:17:00 +02:00
|
|
|
std::string preparedInts = boost::lexical_cast<std::string>(intsPreparedForDeckItem.size());
|
|
|
|
|
std::string parserSizeValue = boost::lexical_cast<std::string>(expectedItems);
|
|
|
|
|
throw std::invalid_argument("The number of parsed ints (" + preparedInts + ") did not correspond to the expected number of items:(" + parserSizeValue + ")");
|
|
|
|
|
}
|
2013-05-10 13:56:41 +02:00
|
|
|
|
2013-05-08 15:29:58 +02:00
|
|
|
}
|
2013-06-20 13:56:11 +02:00
|
|
|
|
2013-05-09 12:17:00 +02:00
|
|
|
return deckItem;
|
2013-05-08 14:31:20 +02:00
|
|
|
}
|
2013-05-07 21:55:49 +02:00
|
|
|
}
|
2013-05-08 15:29:58 +02:00
|
|
|
|
2013-05-06 09:48:29 +02:00
|
|
|
}
|