diff --git a/opm/parser/eclipse/Units/Dimension.cpp b/opm/parser/eclipse/Units/Dimension.cpp index 64d369605..018c0ba3d 100644 --- a/opm/parser/eclipse/Units/Dimension.cpp +++ b/opm/parser/eclipse/Units/Dimension.cpp @@ -47,10 +47,11 @@ namespace Opm { return m_name; } - Dimension Dimension::makeComposite(const std::string& dim , double SIfactor) { - Dimension dimension; - dimension.m_name = dim; - dimension.m_SIfactor = SIfactor; + + Dimension * Dimension::newComposite(const std::string& dim , double SIfactor) { + Dimension * dimension = new Dimension(); + dimension->m_name = dim; + dimension->m_SIfactor = SIfactor; return dimension; } diff --git a/opm/parser/eclipse/Units/Dimension.hpp b/opm/parser/eclipse/Units/Dimension.hpp index bea732fa3..87fbc0c14 100644 --- a/opm/parser/eclipse/Units/Dimension.hpp +++ b/opm/parser/eclipse/Units/Dimension.hpp @@ -29,7 +29,7 @@ namespace Opm { Dimension(const std::string& name, double SI_factor); double getSIScaling() const; const std::string& getName() const; - static Dimension makeComposite(const std::string& dim , double SIfactor); + static Dimension * newComposite(const std::string& dim , double SIfactor); private: Dimension(); diff --git a/opm/parser/eclipse/Units/UnitSystem.cpp b/opm/parser/eclipse/Units/UnitSystem.cpp index 5ade6492a..14dc11f7d 100644 --- a/opm/parser/eclipse/Units/UnitSystem.cpp +++ b/opm/parser/eclipse/Units/UnitSystem.cpp @@ -61,7 +61,7 @@ namespace Opm { } - Dimension UnitSystem::parseFactor(const std::string& dimension) const { + std::shared_ptr UnitSystem::parseFactor(const std::string& dimension) const { std::vector dimensionList; boost::split(dimensionList , dimension , boost::is_any_of("*")); double SIfactor = 1.0; @@ -69,12 +69,12 @@ namespace Opm { Dimension dim = getDimension( *iter ); SIfactor *= dim.getSIScaling(); } - return Dimension::makeComposite( dimension , SIfactor ); + return std::shared_ptr(Dimension::newComposite( dimension , SIfactor )); } - Dimension UnitSystem::parse(const std::string& dimension) const { + std::shared_ptr UnitSystem::parse(const std::string& dimension) const { bool haveDivisor; { size_t divCount = std::count( dimension.begin() , dimension.end() , '/' ); @@ -89,10 +89,10 @@ namespace Opm { if (haveDivisor) { std::vector parts; boost::split(parts , dimension , boost::is_any_of("/")); - Dimension dividend = parseFactor( parts[0] ); - Dimension divisor = parseFactor( parts[1] ); + std::shared_ptr dividend = parseFactor( parts[0] ); + std::shared_ptr divisor = parseFactor( parts[1] ); - return Dimension::makeComposite( dimension , dividend.getSIScaling() / divisor.getSIScaling() ); + return std::shared_ptr( Dimension::newComposite( dimension , dividend->getSIScaling() / divisor->getSIScaling() )); } else { return parseFactor( dimension ); } diff --git a/opm/parser/eclipse/Units/UnitSystem.hpp b/opm/parser/eclipse/Units/UnitSystem.hpp index 76921036f..69abf1de4 100644 --- a/opm/parser/eclipse/Units/UnitSystem.hpp +++ b/opm/parser/eclipse/Units/UnitSystem.hpp @@ -22,6 +22,7 @@ #include #include +#include #include @@ -36,13 +37,13 @@ namespace Opm { const Dimension& getDimension(const std::string& dimension) const; bool hasDimension(const std::string& dimension) const; - Dimension parse(const std::string& dimension) const; + std::shared_ptr parse(const std::string& dimension) const; static UnitSystem * newMETRIC(); static UnitSystem * newFIELD(); private: - Dimension parseFactor(const std::string& dimension) const; - + std::shared_ptr parseFactor(const std::string& dimension) const; + const std::string m_name; std::map m_dimensions; }; diff --git a/opm/parser/eclipse/Units/tests/UnitTests.cpp b/opm/parser/eclipse/Units/tests/UnitTests.cpp index 6094ab349..462ea2e5e 100644 --- a/opm/parser/eclipse/Units/tests/UnitTests.cpp +++ b/opm/parser/eclipse/Units/tests/UnitTests.cpp @@ -18,14 +18,15 @@ */ #define BOOST_TEST_MODULE UnitTests -#include #include #include #include #include +#include +#include using namespace Opm; @@ -36,9 +37,9 @@ BOOST_AUTO_TEST_CASE(CreateDimension) { } BOOST_AUTO_TEST_CASE(makeComposite) { - Dimension composite = Dimension::makeComposite("L*L*L/t" , 100); - BOOST_CHECK_EQUAL("L*L*L/t" , composite.getName()); - BOOST_CHECK_EQUAL(100 , composite.getSIScaling()); + std::shared_ptr composite(Dimension::newComposite("L*L*L/t" , 100)); + BOOST_CHECK_EQUAL("L*L*L/t" , composite->getName()); + BOOST_CHECK_EQUAL(100 , composite->getSIScaling()); } @@ -96,9 +97,9 @@ BOOST_AUTO_TEST_CASE(UnitSystemParseInvalidThrows) { system.addDimension("L" , 3.00 ); system.addDimension("t" , 9.0 ); - Dimension volumePerTime = system.parse("L*L*L/t"); - BOOST_CHECK_EQUAL("L*L*L/t" , volumePerTime.getName() ); - BOOST_CHECK_EQUAL(3.0 , volumePerTime.getSIScaling()); + std::shared_ptr volumePerTime = system.parse("L*L*L/t"); + BOOST_CHECK_EQUAL("L*L*L/t" , volumePerTime->getName() ); + BOOST_CHECK_EQUAL(3.0 , volumePerTime->getSIScaling()); }