Add function Deck::makeDeckPath()

This commit is contained in:
Joakim Hove
2018-10-18 10:45:27 +02:00
parent 24bd410313
commit fd36bf88fb
3 changed files with 17 additions and 0 deletions

View File

@@ -147,6 +147,7 @@ namespace Opm {
const std::string& getInputPath() const;
const std::string& getDataFile() const;
void setDataFile(const std::string& dataFile);
std::string makeDeckPath(const std::string& path) const;
iterator begin();
iterator end();

View File

@@ -217,6 +217,17 @@ namespace Opm {
return this->input_path;
}
std::string Deck::makeDeckPath(const std::string& path) const {
if (path.size() > 0 && path[0] == '/')
return path;
if (this->input_path.size() == 0)
return path;
else
return this->input_path + "/" + path;
}
void Deck::setDataFile(const std::string& dataFile) {
this->m_dataFile = dataFile;

View File

@@ -167,10 +167,15 @@ BOOST_AUTO_TEST_CASE(set_and_get_data_file) {
Deck deck;
BOOST_CHECK_EQUAL("", deck.getDataFile());
BOOST_CHECK_EQUAL("", deck.getInputPath());
BOOST_CHECK_EQUAL("some/path", deck.makeDeckPath("some/path"));
BOOST_CHECK_EQUAL("/abs/path", deck.makeDeckPath("/abs/path"));
std::string file("/path/to/file.DATA");
deck.setDataFile( file );
BOOST_CHECK_EQUAL(file, deck.getDataFile());
BOOST_CHECK_EQUAL("/path/to", deck.getInputPath());
BOOST_CHECK_EQUAL("/path/to/some/path", deck.makeDeckPath("some/path"));
BOOST_CHECK_EQUAL("/abs/path", deck.makeDeckPath("/abs/path"));
deck.setDataFile("FILE");
BOOST_CHECK_EQUAL("FILE", deck.getDataFile());