Merge pull request #30 from joakim-hove/data-with-space
Data with space
This commit is contained in:
commit
2ac8bc55a5
@ -24,6 +24,8 @@
|
|||||||
#include <boost/test/unit_test.hpp>
|
#include <boost/test/unit_test.hpp>
|
||||||
#include <opm/parser/eclipse/Deck/DeckRecord.hpp>
|
#include <opm/parser/eclipse/Deck/DeckRecord.hpp>
|
||||||
#include <opm/parser/eclipse/Deck/DeckIntItem.hpp>
|
#include <opm/parser/eclipse/Deck/DeckIntItem.hpp>
|
||||||
|
#include <opm/parser/eclipse/Parser/ParserRecord.hpp>
|
||||||
|
#include <opm/parser/eclipse/Parser/ParserStringItem.hpp>
|
||||||
#include <boost/test/test_tools.hpp>
|
#include <boost/test/test_tools.hpp>
|
||||||
|
|
||||||
using namespace Opm;
|
using namespace Opm;
|
||||||
@ -112,4 +114,14 @@ BOOST_AUTO_TEST_CASE(get_oneoftwo_returnscorrectitem) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
BOOST_AUTO_TEST_CASE(StringsWithSpaceOK) {
|
||||||
|
ParserStringItemPtr itemString(new ParserStringItem(std::string("STRINGITEM1")));
|
||||||
|
ParserRecordPtr record1(new ParserRecord());
|
||||||
|
RawRecordPtr rawRecord(new Opm::RawRecord(" ' VALUE ' /"));
|
||||||
|
record1->addItem( itemString );
|
||||||
|
|
||||||
|
|
||||||
|
DeckRecordConstPtr deckRecord = record1->parse( rawRecord );
|
||||||
|
BOOST_CHECK_EQUAL(" VALUE " , deckRecord->getItem(0)->getString(0));
|
||||||
|
}
|
||||||
|
|
||||||
|
@ -72,6 +72,13 @@ namespace Opm {
|
|||||||
return m_parserKeywords.find(keyword) != m_parserKeywords.end();
|
return m_parserKeywords.find(keyword) != m_parserKeywords.end();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool Parser::dropKeyword(const std::string& keyword) {
|
||||||
|
if (m_parserKeywords.erase( keyword ) == 1)
|
||||||
|
return true;
|
||||||
|
else
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
ParserKeywordConstPtr Parser::getKeyword(const std::string& keyword) const {
|
ParserKeywordConstPtr Parser::getKeyword(const std::string& keyword) const {
|
||||||
if (hasKeyword(keyword)) {
|
if (hasKeyword(keyword)) {
|
||||||
return m_parserKeywords.at(keyword);
|
return m_parserKeywords.at(keyword);
|
||||||
|
@ -47,6 +47,7 @@ namespace Opm {
|
|||||||
/// Method to add ParserKeyword instances, these holding type and size information about the keywords and their data.
|
/// Method to add ParserKeyword instances, these holding type and size information about the keywords and their data.
|
||||||
void addKeyword(ParserKeywordConstPtr parserKeyword);
|
void addKeyword(ParserKeywordConstPtr parserKeyword);
|
||||||
bool hasKeyword(const std::string& keyword) const;
|
bool hasKeyword(const std::string& keyword) const;
|
||||||
|
bool dropKeyword(const std::string& keyword);
|
||||||
ParserKeywordConstPtr getKeyword(const std::string& keyword) const;
|
ParserKeywordConstPtr getKeyword(const std::string& keyword) const;
|
||||||
|
|
||||||
void loadKeywords(const Json::JsonObject& jsonKeywords);
|
void loadKeywords(const Json::JsonObject& jsonKeywords);
|
||||||
|
@ -27,6 +27,7 @@
|
|||||||
|
|
||||||
namespace Opm {
|
namespace Opm {
|
||||||
|
|
||||||
|
|
||||||
ParserIntItem::ParserIntItem(const std::string& itemName) : ParserItem(itemName) {
|
ParserIntItem::ParserIntItem(const std::string& itemName) : ParserItem(itemName) {
|
||||||
m_default = defaultInt();
|
m_default = defaultInt();
|
||||||
}
|
}
|
||||||
|
@ -27,6 +27,10 @@
|
|||||||
|
|
||||||
namespace Opm {
|
namespace Opm {
|
||||||
|
|
||||||
|
template<> void ParserItem::fillVectorFromStringStream<std::string>(std::istringstream& inputStream , std::string& token , std::deque<std::string>& dataVector) const {
|
||||||
|
dataVector.push_back(token);
|
||||||
|
}
|
||||||
|
|
||||||
ParserItem::ParserItem(const std::string& itemName, ParserItemSizeEnum sizeType) {
|
ParserItem::ParserItem(const std::string& itemName, ParserItemSizeEnum sizeType) {
|
||||||
m_name.assign(itemName);
|
m_name.assign(itemName);
|
||||||
m_sizeType = sizeType;
|
m_sizeType = sizeType;
|
||||||
|
@ -17,14 +17,39 @@
|
|||||||
along with OPM. If not, see <http://www.gnu.org/licenses/>.
|
along with OPM. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
Pushing the converted values onto the dataVector is in this seperate
|
||||||
|
function to be able to specialize the implementation for type
|
||||||
|
std::string. The problem is that in the code:
|
||||||
|
|
||||||
|
std::istringstream inputStream(" WITH_SPACE ");
|
||||||
|
inputStream >> stringValue;
|
||||||
|
|
||||||
|
The leading and trailing spaces will be stripped from the final
|
||||||
|
stringValue (have tried manipulating the skipws flag to no
|
||||||
|
avail). To avoid this a specialized
|
||||||
|
fillVectorFromStringStream<std::string> implementation is in
|
||||||
|
ParserItem.cpp.
|
||||||
|
*/
|
||||||
|
|
||||||
|
template<class T> void fillVectorFromStringStream(std::istringstream& inputStream , std::string& token , std::deque<T>& dataVector) const {
|
||||||
|
T value;
|
||||||
|
inputStream >> value;
|
||||||
|
dataVector.push_back(value);
|
||||||
|
|
||||||
|
inputStream.get();
|
||||||
|
if (!inputStream.eof())
|
||||||
|
throw std::invalid_argument("Spurious data at the end of: <" + token + ">");
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
template<class T> void fillVectorFromStringToken(std::string token, std::deque<T>& dataVector, T defaultValue, bool& defaultActive) const {
|
template<class T> void fillVectorFromStringToken(std::string token, std::deque<T>& dataVector, T defaultValue, bool& defaultActive) const {
|
||||||
std::istringstream inputStream(token);
|
std::istringstream inputStream(token);
|
||||||
size_t starPos = token.find('*');
|
size_t starPos = token.find('*');
|
||||||
T value;
|
|
||||||
bool hasStar = (starPos != std::string::npos);
|
bool hasStar = (starPos != std::string::npos);
|
||||||
|
|
||||||
defaultActive = false;
|
defaultActive = false;
|
||||||
|
|
||||||
if (hasStar) {
|
if (hasStar) {
|
||||||
bool singleDefault = (starPos == 0);
|
bool singleDefault = (starPos == 0);
|
||||||
|
|
||||||
@ -37,6 +62,7 @@ template<class T> void fillVectorFromStringToken(std::string token, std::deque<T
|
|||||||
} else {
|
} else {
|
||||||
size_t multiplier;
|
size_t multiplier;
|
||||||
int starChar;
|
int starChar;
|
||||||
|
T value;
|
||||||
|
|
||||||
inputStream >> multiplier;
|
inputStream >> multiplier;
|
||||||
starChar = inputStream.get();
|
starChar = inputStream.get();
|
||||||
@ -53,15 +79,11 @@ template<class T> void fillVectorFromStringToken(std::string token, std::deque<T
|
|||||||
for (size_t i = 0; i < multiplier; i++)
|
for (size_t i = 0; i < multiplier; i++)
|
||||||
dataVector.push_back(value);
|
dataVector.push_back(value);
|
||||||
}
|
}
|
||||||
} else {
|
} else
|
||||||
inputStream >> value;
|
fillVectorFromStringStream(inputStream , token , dataVector);
|
||||||
dataVector.push_back(value);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
inputStream.get();
|
|
||||||
if (!inputStream.eof())
|
|
||||||
throw std::invalid_argument("Spurious data at the end of: <" + token + ">");
|
|
||||||
}
|
|
||||||
|
|
||||||
template<class T> std::deque<T> readFromRawRecord(RawRecordPtr rawRecord, bool scanAll, T defaultValue, bool& defaultActive) const {
|
template<class T> std::deque<T> readFromRawRecord(RawRecordPtr rawRecord, bool scanAll, T defaultValue, bool& defaultActive) const {
|
||||||
std::deque<T> data;
|
std::deque<T> data;
|
||||||
|
@ -216,6 +216,14 @@ BOOST_AUTO_TEST_CASE(loadConfigFromDirectory_default) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
BOOST_AUTO_TEST_CASE(DropKeyword) {
|
||||||
|
ParserPtr parser(new Parser());
|
||||||
|
BOOST_CHECK_EQUAL(false , parser->dropKeyword("DoesNotHaveThis"));
|
||||||
|
BOOST_CHECK_EQUAL(true , parser->dropKeyword("BPR"));
|
||||||
|
BOOST_CHECK_EQUAL(false , parser->dropKeyword("BPR"));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/***************** Simple Int parsing ********************************/
|
/***************** Simple Int parsing ********************************/
|
||||||
|
|
||||||
ParserKeywordPtr setupParserKeywordInt(std::string name, int numberOfItems) {
|
ParserKeywordPtr setupParserKeywordInt(std::string name, int numberOfItems) {
|
||||||
|
@ -1,3 +1,3 @@
|
|||||||
{"name" : "GRIDUNIT" , "size" : 1, "items" :
|
{"name" : "GRIDUNIT" , "size" : 1, "items" :
|
||||||
[{"name" : "LengthUnit" , "value_type" : "STRING" , "default" : "METRES"}]
|
[{"name" : "LengthUnit" , "value_type" : "STRING" , "default" : "METRES"},
|
||||||
}
|
{"name" : "MAP" , "value_type" : "STRING"}]}
|
||||||
|
3
opm/parser/share/keywords/M/MAPUNITS
Normal file
3
opm/parser/share/keywords/M/MAPUNITS
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
{"name" : "MAPUNITS" , "size" : 1 , "items" : [
|
||||||
|
{"name" : "UNIT" , "value_type" : "STRING" , "default" : "METRES"}]}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user