Remove unused functionality for directory loading of keywords

This commit is contained in:
Joakim Hove
2018-07-11 10:20:07 +02:00
parent 903118736a
commit 3c90adeea9
3 changed files with 2 additions and 112 deletions

View File

@@ -40,14 +40,9 @@ namespace Opm {
bool hasKeyword(const std::string& keyword) const;
std::shared_ptr<const ParserKeyword> getKeyword(const std::string& keyword) const;
std::string getJsonFile(const std::string& keyword) const;
size_t loadKeywordDirectory(const std::string& pathname);
size_t loadKeywordDirectory(boost::filesystem::path& path);
void loadKeyword(const std::string& filename);
void loadKeyword(boost::filesystem::path& path);
static std::vector<std::string> sortSubdirectories( const std::string& directory );
size_t loadMultipleKeywordDirectories(const std::string& directory);
std::map<std::string , std::shared_ptr<ParserKeyword> >::const_iterator keyword_begin( ) const;
std::map<std::string , std::shared_ptr<ParserKeyword> >::const_iterator keyword_end( ) const;
private:

View File

@@ -67,43 +67,6 @@ namespace Opm {
}
size_t KeywordLoader::loadKeywordDirectory(boost::filesystem::path& path) {
size_t loadCount = 0;
if (boost::filesystem::is_directory( path )) {
boost::filesystem::directory_iterator end_iterator;
for (boost::filesystem::directory_iterator iter(path); iter != end_iterator; ++iter) {
boost::filesystem::path iter_path = iter->path();
if (boost::filesystem::is_directory( iter_path )) {
loadCount += loadKeywordDirectory( iter_path );
} else {
std::string internalName = iter_path.filename().string();
if (ParserKeyword::validInternalName(internalName)) {
if (m_verbose)
std::cout << "Loading keyword " << internalName << " from file: " << iter_path << "....";
loadKeyword( iter_path );
if (m_verbose)
std::cout << std::endl;
loadCount += 1;
} else {
if (m_verbose)
std::cout << "Ignoring file " << iter_path << " - incorrectly formatted name." << std::endl;
}
}
}
} else
throw std::invalid_argument("Input does not correspond to existing directory\n");
return loadCount;
}
size_t KeywordLoader::loadKeywordDirectory(const std::string& directory) {
boost::filesystem::path path( directory );
return loadKeywordDirectory( path );
}
void KeywordLoader::loadKeyword(boost::filesystem::path& path) {
std::shared_ptr<Json::JsonObject> jsonConfig = std::make_shared<Json::JsonObject>( path );
std::shared_ptr<ParserKeyword> parserKeyword = std::make_shared<ParserKeyword>(*jsonConfig);
@@ -114,19 +77,10 @@ namespace Opm {
}
size_t KeywordLoader::loadMultipleKeywordDirectories(const std::string& directory) {
std::vector<std::string> directories = sortSubdirectories( directory );
size_t load_count = 0;
for (auto iter = directories.begin(); iter != directories.end(); ++iter)
load_count += loadKeywordDirectory(*iter);
return load_count;
}
void KeywordLoader::loadKeyword(const std::string& filename) {
boost::filesystem::path path( filename );
if (m_verbose)
std::cout << "Loading keyword from file: " << filename << std::endl;
return loadKeyword( path );
}
@@ -144,22 +98,6 @@ namespace Opm {
}
std::vector<std::string> KeywordLoader::sortSubdirectories( const std::string& root_path) {
boost::filesystem::path root(root_path);
if (boost::filesystem::is_directory( root )) {
std::vector<std::string> paths_in_root;
boost::filesystem::directory_iterator end_iterator;
for (boost::filesystem::directory_iterator iter(root); iter != end_iterator; ++iter) {
if (boost::filesystem::is_directory( iter->path() ))
paths_in_root.push_back(iter->path().string());
}
std::sort(paths_in_root.begin(), paths_in_root.end());
return paths_in_root;
} else
throw std::invalid_argument("Input argument is not a directory");
}
std::map<std::string , std::shared_ptr<ParserKeyword> >::const_iterator KeywordLoader::keyword_begin( ) const {
return m_keywords.begin( );

View File

@@ -64,46 +64,3 @@ BOOST_AUTO_TEST_CASE(LoadKeyword) {
BOOST_AUTO_TEST_CASE(LoadKeywordDirectory) {
Opm::KeywordLoader loader(false);
BOOST_CHECK_THROW( loader.loadKeywordDirectory("does/not/exists") , std::invalid_argument );
BOOST_CHECK_THROW( loader.loadKeywordDirectory(prefix() + "invalid.json") , std::invalid_argument);
BOOST_CHECK_EQUAL( 4 , loader.loadKeywordDirectory( prefix() + "loader/001_ECLIPSE100"));
BOOST_CHECK( loader.hasKeyword("ADDREG") );
BOOST_CHECK( loader.hasKeyword("ACTNUM") );
BOOST_CHECK( loader.hasKeyword("BOX") );
BOOST_CHECK( loader.hasKeyword("BLOCK_PROBE") );
{
auto kw = loader.getKeyword("ADDREG");
auto record = kw->getRecord(0);
BOOST_CHECK( !record.hasItem("REGION_NUMBER") );
}
}
BOOST_AUTO_TEST_CASE(DirectorySort) {
BOOST_CHECK_THROW( Opm::KeywordLoader::sortSubdirectories( prefix() + "loader/ZCORN") , std::invalid_argument );
std::vector<std::string> dir_list = Opm::KeywordLoader::sortSubdirectories( prefix() + "loader");
namespace fs = boost::filesystem;
BOOST_CHECK_EQUAL( 2U , dir_list.size());
BOOST_CHECK_EQUAL( fs::path( dir_list[0] ), fs::path( prefix() + "loader/001_ECLIPSE100" ) );
BOOST_CHECK_EQUAL( fs::path( dir_list[1] ), fs::path( prefix() + "loader/002_ECLIPSE300" ) );
}
BOOST_AUTO_TEST_CASE(BigLoad) {
Opm::KeywordLoader loader(false);
BOOST_CHECK_THROW( loader.loadMultipleKeywordDirectories("does/not/exists") , std::invalid_argument );
BOOST_CHECK_THROW( loader.loadMultipleKeywordDirectories(prefix() + "invalid.json") , std::invalid_argument);
loader.loadMultipleKeywordDirectories(prefix() + "loader");
BOOST_CHECK( loader.hasKeyword("EQUIL"));
{
auto kw = loader.getKeyword("ADDREG");
auto record = kw->getRecord(0);
BOOST_CHECK( record.hasItem("REGION_NUMBER"));
}
}