Default: Implemented ParserxxxItem::scan() with template
This commit is contained in:
@@ -116,55 +116,11 @@ namespace Opm
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/// Scans the rawRecords data according to the ParserItems definition.
|
|
||||||
/// returns a DeckItem object.
|
|
||||||
/// NOTE: data are popped from the rawRecords deque!
|
|
||||||
DeckItemPtr ParserDoubleItem::scan(RawRecordPtr rawRecord) const {
|
DeckItemPtr ParserDoubleItem::scan(RawRecordPtr rawRecord) const {
|
||||||
DeckDoubleItemPtr deckItem(new DeckDoubleItem(name() , scalar()));
|
return ParserItemScan<ParserDoubleItem,DeckDoubleItem,double>(this , rawRecord);
|
||||||
double defaultValue = m_default;
|
|
||||||
|
|
||||||
if (sizeType() == ALL) {
|
|
||||||
while (rawRecord->size() > 0) {
|
|
||||||
std::string token = rawRecord->pop_front();
|
|
||||||
if (tokenContainsStar( token )) {
|
|
||||||
StarToken<double> st(token);
|
|
||||||
double value = defaultValue;
|
|
||||||
if (st.hasValue())
|
|
||||||
value = st.value();
|
|
||||||
deckItem->push_backMultiple( value , st.multiplier() );
|
|
||||||
} else {
|
|
||||||
double value = readValueToken<double>(token);
|
|
||||||
deckItem->push_back(value);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
// The '*' should be interpreted as a default indicator
|
|
||||||
if (rawRecord->size() > 0) {
|
|
||||||
std::string token = rawRecord->pop_front();
|
|
||||||
if (tokenContainsStar( token )) {
|
|
||||||
StarToken<double> st(token);
|
|
||||||
|
|
||||||
if (st.hasValue()) { // Probably never true
|
|
||||||
deckItem->push_back( st.value() );
|
|
||||||
std::string stringValue = boost::lexical_cast<std::string>(st.value());
|
|
||||||
for (size_t i=1; i < st.multiplier(); i++)
|
|
||||||
rawRecord->push_front( stringValue );
|
|
||||||
} else {
|
|
||||||
deckItem->push_backDefault( defaultValue );
|
|
||||||
for (size_t i=1; i < st.multiplier(); i++)
|
|
||||||
rawRecord->push_front( "*" );
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
double value = readValueToken<double>(token);
|
|
||||||
deckItem->push_back(value);
|
|
||||||
}
|
|
||||||
} else
|
|
||||||
deckItem->push_backDefault( defaultValue );
|
|
||||||
}
|
|
||||||
return deckItem;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void ParserDoubleItem::inlineNew(std::ostream& os) const {
|
void ParserDoubleItem::inlineNew(std::ostream& os) const {
|
||||||
os << "new ParserDoubleItem(" << "\"" << name() << "\"" << "," << ParserItemSizeEnum2String( sizeType() );
|
os << "new ParserDoubleItem(" << "\"" << name() << "\"" << "," << ParserItemSizeEnum2String( sizeType() );
|
||||||
if (m_defaultSet)
|
if (m_defaultSet)
|
||||||
os << "," << getDefault();
|
os << "," << getDefault();
|
||||||
|
|||||||
@@ -116,56 +116,11 @@ namespace Opm
|
|||||||
throw std::invalid_argument("Invalid index ");
|
throw std::invalid_argument("Invalid index ");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/// Scans the rawRecords data according to the ParserItems definition.
|
|
||||||
/// returns a DeckItem object.
|
|
||||||
/// NOTE: data are popped from the rawRecords deque!
|
|
||||||
DeckItemPtr ParserFloatItem::scan(RawRecordPtr rawRecord) const {
|
DeckItemPtr ParserFloatItem::scan(RawRecordPtr rawRecord) const {
|
||||||
DeckFloatItemPtr deckItem(new DeckFloatItem(name() , scalar()));
|
return ParserItemScan<ParserFloatItem,DeckFloatItem,float>(this , rawRecord);
|
||||||
float defaultValue = m_default;
|
|
||||||
|
|
||||||
if (sizeType() == ALL) {
|
|
||||||
while (rawRecord->size() > 0) {
|
|
||||||
std::string token = rawRecord->pop_front();
|
|
||||||
if (tokenContainsStar( token )) {
|
|
||||||
StarToken<float> st(token);
|
|
||||||
float value = defaultValue;
|
|
||||||
if (st.hasValue())
|
|
||||||
value = st.value();
|
|
||||||
deckItem->push_backMultiple( value , st.multiplier() );
|
|
||||||
} else {
|
|
||||||
float value = readValueToken<float>(token);
|
|
||||||
deckItem->push_back(value);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
// The '*' should be interpreted as a default indicator
|
|
||||||
if (rawRecord->size() > 0) {
|
|
||||||
std::string token = rawRecord->pop_front();
|
|
||||||
if (tokenContainsStar( token )) {
|
|
||||||
StarToken<float> st(token);
|
|
||||||
|
|
||||||
if (st.hasValue()) { // Probably never true
|
|
||||||
deckItem->push_back( st.value() );
|
|
||||||
std::string stringValue = boost::lexical_cast<std::string>(st.value());
|
|
||||||
for (size_t i=1; i < st.multiplier(); i++)
|
|
||||||
rawRecord->push_front( stringValue );
|
|
||||||
} else {
|
|
||||||
deckItem->push_backDefault( defaultValue );
|
|
||||||
for (size_t i=1; i < st.multiplier(); i++)
|
|
||||||
rawRecord->push_front( "*" );
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
float value = readValueToken<float>(token);
|
|
||||||
deckItem->push_back(value);
|
|
||||||
}
|
|
||||||
} else
|
|
||||||
deckItem->push_backDefault( defaultValue );
|
|
||||||
}
|
|
||||||
return deckItem;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void ParserFloatItem::inlineNew(std::ostream& os) const {
|
void ParserFloatItem::inlineNew(std::ostream& os) const {
|
||||||
os << "new ParserFloatItem(" << "\"" << name() << "\"" << "," << ParserItemSizeEnum2String( sizeType() );
|
os << "new ParserFloatItem(" << "\"" << name() << "\"" << "," << ParserItemSizeEnum2String( sizeType() );
|
||||||
if (m_defaultSet)
|
if (m_defaultSet)
|
||||||
os << "," << getDefault();
|
os << "," << getDefault();
|
||||||
|
|||||||
@@ -58,54 +58,8 @@ namespace Opm {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/// Scans the rawRecords data according to the ParserItems definition.
|
|
||||||
/// returns a DeckItem object.
|
|
||||||
/// NOTE: data are popped from the rawRecords deque!
|
|
||||||
DeckItemPtr ParserIntItem::scan(RawRecordPtr rawRecord) const {
|
DeckItemPtr ParserIntItem::scan(RawRecordPtr rawRecord) const {
|
||||||
DeckIntItemPtr deckItem(new DeckIntItem( name() , scalar() ));
|
return ParserItemScan<ParserIntItem,DeckIntItem,int>(this , rawRecord);
|
||||||
int defaultValue = m_default;
|
|
||||||
|
|
||||||
if (sizeType() == ALL) {
|
|
||||||
// The '*' should be interpreted either as a default indicator in the cases '*' and '5*'
|
|
||||||
// or as multiplier in the case: '5*99'.
|
|
||||||
while (rawRecord->size() > 0) {
|
|
||||||
std::string token = rawRecord->pop_front();
|
|
||||||
if (tokenContainsStar( token )) {
|
|
||||||
StarToken<int> st(token);
|
|
||||||
int value = defaultValue;
|
|
||||||
if (st.hasValue())
|
|
||||||
value = st.value();
|
|
||||||
deckItem->push_backMultiple( value , st.multiplier() );
|
|
||||||
} else {
|
|
||||||
int value = readValueToken<int>(token);
|
|
||||||
deckItem->push_back(value);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
// The '*' should be interpreted as a default indicator
|
|
||||||
if (rawRecord->size() > 0) {
|
|
||||||
std::string token = rawRecord->pop_front();
|
|
||||||
if (tokenContainsStar( token )) {
|
|
||||||
StarToken<int> st(token);
|
|
||||||
|
|
||||||
if (st.hasValue()) { // Probably never true
|
|
||||||
deckItem->push_back( st.value() );
|
|
||||||
std::string stringValue = boost::lexical_cast<std::string>(st.value());
|
|
||||||
for (size_t i=1; i < st.multiplier(); i++)
|
|
||||||
rawRecord->push_front( stringValue );
|
|
||||||
} else {
|
|
||||||
deckItem->push_backDefault( defaultValue );
|
|
||||||
for (size_t i=1; i < st.multiplier(); i++)
|
|
||||||
rawRecord->push_front( "*" );
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
int value = readValueToken<int>(token);
|
|
||||||
deckItem->push_back(value);
|
|
||||||
}
|
|
||||||
} else
|
|
||||||
deckItem->push_backDefault( defaultValue );
|
|
||||||
}
|
|
||||||
return deckItem;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -32,7 +32,7 @@
|
|||||||
#include <opm/parser/eclipse/Parser/ParserEnums.hpp>
|
#include <opm/parser/eclipse/Parser/ParserEnums.hpp>
|
||||||
#include <opm/parser/eclipse/RawDeck/RawRecord.hpp>
|
#include <opm/parser/eclipse/RawDeck/RawRecord.hpp>
|
||||||
#include <opm/parser/eclipse/Deck/DeckItem.hpp>
|
#include <opm/parser/eclipse/Deck/DeckItem.hpp>
|
||||||
|
#include <opm/parser/eclipse/RawDeck/StarToken.hpp>
|
||||||
|
|
||||||
namespace Opm {
|
namespace Opm {
|
||||||
|
|
||||||
@@ -95,6 +95,64 @@ namespace Opm {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/// Scans the rawRecords data according to the ParserItems definition.
|
||||||
|
/// returns a DeckItem object.
|
||||||
|
/// NOTE: data are popped from the rawRecords deque!
|
||||||
|
template<typename ParserItemType , typename DeckItemType , typename valueType>
|
||||||
|
DeckItemPtr ParserItemScan(const ParserItemType * self , RawRecordPtr rawRecord) {
|
||||||
|
std::shared_ptr<DeckItemType> deckItem = std::make_shared<DeckItemType>( self->name() , self->scalar() );
|
||||||
|
|
||||||
|
if (self->sizeType() == ALL) {
|
||||||
|
// The '*' should be interpreted either as a default indicator in the cases '*' and '5*'
|
||||||
|
// or as multiplier in the case: '5*99'.
|
||||||
|
while (rawRecord->size() > 0) {
|
||||||
|
std::string token = rawRecord->pop_front();
|
||||||
|
if (tokenContainsStar( token )) {
|
||||||
|
StarToken<valueType> st(token);
|
||||||
|
valueType value;
|
||||||
|
if (st.hasValue())
|
||||||
|
value = st.value();
|
||||||
|
else
|
||||||
|
value = self->getDefault();
|
||||||
|
|
||||||
|
deckItem->push_backMultiple( value , st.multiplier() );
|
||||||
|
} else {
|
||||||
|
valueType value = readValueToken<valueType>(token);
|
||||||
|
deckItem->push_back(value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// The '*' should be interpreted as a default indicator
|
||||||
|
if (rawRecord->size() > 0) {
|
||||||
|
std::string token = rawRecord->pop_front();
|
||||||
|
if (tokenContainsStar( token )) {
|
||||||
|
StarToken<valueType> st(token);
|
||||||
|
|
||||||
|
if (st.hasValue()) { // Probably never true
|
||||||
|
deckItem->push_back( st.value() );
|
||||||
|
std::string stringValue = boost::lexical_cast<std::string>(st.value());
|
||||||
|
for (size_t i=1; i < st.multiplier(); i++)
|
||||||
|
rawRecord->push_front( stringValue );
|
||||||
|
} else {
|
||||||
|
deckItem->push_backDefault( self->getDefault() );
|
||||||
|
for (size_t i=1; i < st.multiplier(); i++)
|
||||||
|
rawRecord->push_front( "*" );
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
valueType value = readValueToken<valueType>(token);
|
||||||
|
deckItem->push_back(value);
|
||||||
|
}
|
||||||
|
} else
|
||||||
|
deckItem->push_backDefault( self->getDefault() );
|
||||||
|
}
|
||||||
|
return deckItem;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -59,54 +59,11 @@ namespace Opm {
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
/// Scans the rawRecords data according to the ParserItems definition.
|
|
||||||
/// returns a DeckItem object.
|
|
||||||
/// NOTE: data are popped from the rawRecords deque!
|
|
||||||
|
|
||||||
DeckItemPtr ParserStringItem::scan(RawRecordPtr rawRecord) const {
|
DeckItemPtr ParserStringItem::scan(RawRecordPtr rawRecord) const {
|
||||||
DeckStringItemPtr deckItem(new DeckStringItem(name() , scalar()));
|
return ParserItemScan<ParserStringItem,DeckStringItem,std::string>(this , rawRecord);
|
||||||
std::string defaultValue = m_default;
|
|
||||||
|
|
||||||
if (sizeType() == ALL) {
|
|
||||||
while (rawRecord->size() > 0) {
|
|
||||||
std::string token = rawRecord->pop_front();
|
|
||||||
if (tokenContainsStar( token )) {
|
|
||||||
StarToken<std::string> st(token);
|
|
||||||
std::string value = defaultValue;
|
|
||||||
if (st.hasValue())
|
|
||||||
value = st.value();
|
|
||||||
deckItem->push_backMultiple( value , st.multiplier() );
|
|
||||||
} else {
|
|
||||||
std::string value = readValueToken<std::string>(token);
|
|
||||||
deckItem->push_back(value);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
// The '*' should be interpreted as a default indicator
|
|
||||||
if (rawRecord->size() > 0) {
|
|
||||||
std::string token = rawRecord->pop_front();
|
|
||||||
if (tokenContainsStar( token )) {
|
|
||||||
StarToken<std::string> st(token);
|
|
||||||
|
|
||||||
if (st.hasValue()) { // Probably never true
|
|
||||||
deckItem->push_back( st.value() );
|
|
||||||
std::string stringValue = boost::lexical_cast<std::string>(st.value());
|
|
||||||
for (size_t i=1; i < st.multiplier(); i++)
|
|
||||||
rawRecord->push_front( stringValue );
|
|
||||||
} else {
|
|
||||||
deckItem->push_backDefault( defaultValue );
|
|
||||||
for (size_t i=1; i < st.multiplier(); i++)
|
|
||||||
rawRecord->push_front( "*" );
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
std::string value = readValueToken<std::string>(token);
|
|
||||||
deckItem->push_back(value);
|
|
||||||
}
|
|
||||||
} else
|
|
||||||
deckItem->push_backDefault( defaultValue );
|
|
||||||
}
|
|
||||||
return deckItem;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
bool ParserStringItem::equal(const ParserItem& other) const
|
bool ParserStringItem::equal(const ParserItem& other) const
|
||||||
|
|||||||
Reference in New Issue
Block a user