Added functionality to apply dimensions to ParserItem from JsonConfig.
This commit is contained in:
@@ -242,7 +242,8 @@ namespace Opm {
|
||||
break;
|
||||
case FLOAT:
|
||||
{
|
||||
ParserDoubleItemConstPtr item = ParserDoubleItemConstPtr(new ParserDoubleItem(itemConfig));
|
||||
ParserDoubleItemPtr item = ParserDoubleItemPtr(new ParserDoubleItem(itemConfig));
|
||||
initItemDimension( item , itemConfig );
|
||||
addItem(item);
|
||||
}
|
||||
break;
|
||||
@@ -261,6 +262,24 @@ namespace Opm {
|
||||
addItem(item);
|
||||
}
|
||||
|
||||
|
||||
void ParserKeyword::initItemDimension( ParserDoubleItemPtr item, const Json::JsonObject itemConfig) {
|
||||
if (itemConfig.has_item("dimension")) {
|
||||
const Json::JsonObject dimensionConfig = itemConfig.get_item("dimension");
|
||||
if (dimensionConfig.is_string())
|
||||
item->push_backDimension( dimensionConfig.as_string() );
|
||||
else if (dimensionConfig.is_array()) {
|
||||
for (size_t idim = 0; idim < dimensionConfig.size(); idim++) {
|
||||
Json::JsonObject dimObject = dimensionConfig.get_array_item( idim );
|
||||
item->push_backDimension( dimObject.as_string());
|
||||
}
|
||||
} else
|
||||
throw std::invalid_argument("The dimension: attribute must be a string/list of strings");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
void ParserKeyword::initData(const Json::JsonObject& jsonConfig) {
|
||||
m_fixedSize = 1U;
|
||||
m_keywordSizeType = FIXED;
|
||||
|
||||
@@ -26,6 +26,7 @@
|
||||
#include <opm/json/JsonObject.hpp>
|
||||
|
||||
#include <opm/parser/eclipse/Parser/ParserRecord.hpp>
|
||||
#include <opm/parser/eclipse/Parser/ParserDoubleItem.hpp>
|
||||
#include <opm/parser/eclipse/Parser/ParserEnums.hpp>
|
||||
#include <opm/parser/eclipse/Deck/DeckKeyword.hpp>
|
||||
#include <opm/parser/eclipse/RawDeck/RawKeyword.hpp>
|
||||
@@ -82,6 +83,7 @@ namespace Opm {
|
||||
void commonInit(const std::string& name, ParserKeywordSizeEnum sizeType , ParserKeywordActionEnum action);
|
||||
void addItems( const Json::JsonObject& jsonConfig);
|
||||
void addTableItems();
|
||||
static void initItemDimension( ParserDoubleItemPtr item, const Json::JsonObject itemConfig);
|
||||
};
|
||||
typedef std::shared_ptr<ParserKeyword> ParserKeywordPtr;
|
||||
typedef std::shared_ptr<const ParserKeyword> ParserKeywordConstPtr;
|
||||
|
||||
@@ -442,8 +442,44 @@ BOOST_AUTO_TEST_CASE(ParseKeywordHasDimensionCorrect) {
|
||||
parserKeyword->addItem( itemI );
|
||||
parserKeyword->addItem( item2 );
|
||||
BOOST_CHECK_EQUAL( false , parserKeyword->hasDimension());
|
||||
|
||||
BOOST_CHECK_EQUAL( 0U , itemI->numDimensions() );
|
||||
|
||||
item2->push_backDimension("L*L/t");
|
||||
BOOST_CHECK_EQUAL( true , parserKeyword->hasDimension());
|
||||
BOOST_CHECK_EQUAL( 1U , item2->numDimensions() );
|
||||
}
|
||||
|
||||
|
||||
BOOST_AUTO_TEST_CASE(ConstructFromJsonObject_withDimension) {
|
||||
Json::JsonObject jsonObject("{\"name\": \"BPR\", \"size\" : 100 , \"items\" :[{\"name\":\"ItemX\" , \"size_type\":\"SINGLE\" , \"value_type\" : \"FLOAT\" , \"dimension\" : \"L*L/t\"}]}");
|
||||
ParserKeyword parserKeyword(jsonObject);
|
||||
ParserRecordConstPtr record = parserKeyword.getRecord();
|
||||
ParserItemConstPtr item = record->get("ItemX");
|
||||
|
||||
BOOST_CHECK_EQUAL("BPR" , parserKeyword.getName());
|
||||
BOOST_CHECK_EQUAL( true , parserKeyword.hasFixedSize() );
|
||||
BOOST_CHECK_EQUAL( 100U , parserKeyword.getFixedSize() );
|
||||
|
||||
BOOST_CHECK_EQUAL( 1U , parserKeyword.numItems());
|
||||
BOOST_CHECK( parserKeyword.hasDimension() );
|
||||
BOOST_CHECK( item->hasDimension() );
|
||||
BOOST_CHECK_EQUAL( 1U , item->numDimensions() );
|
||||
}
|
||||
|
||||
|
||||
|
||||
BOOST_AUTO_TEST_CASE(ConstructFromJsonObject_withDimensionList) {
|
||||
Json::JsonObject jsonObject("{\"name\": \"BPR\", \"size\" : 100 , \"items\" :[{\"name\":\"ItemX\" , \"size_type\":\"ALL\" , \"value_type\" : \"FLOAT\" , \"dimension\" : [\"L*L/t\" , \"t\", \"1\"]}]}");
|
||||
ParserKeyword parserKeyword(jsonObject);
|
||||
ParserRecordConstPtr record = parserKeyword.getRecord();
|
||||
ParserItemConstPtr item = record->get("ItemX");
|
||||
|
||||
BOOST_CHECK_EQUAL("BPR" , parserKeyword.getName());
|
||||
BOOST_CHECK_EQUAL( true , parserKeyword.hasFixedSize() );
|
||||
BOOST_CHECK_EQUAL( 100U , parserKeyword.getFixedSize() );
|
||||
|
||||
BOOST_CHECK_EQUAL( 1U , parserKeyword.numItems());
|
||||
BOOST_CHECK( parserKeyword.hasDimension() );
|
||||
BOOST_CHECK( item->hasDimension() );
|
||||
BOOST_CHECK_EQUAL( 3U , item->numDimensions() );
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user