Merge pull request #1235 from joakim-hove/fp-keys

Add FieldPropsManager::keys<T>() method for iteration
This commit is contained in:
Joakim Hove 2019-11-27 10:06:23 +01:00 committed by GitHub
commit ca95ff1b86
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 44 additions and 0 deletions

View File

@ -81,6 +81,9 @@ public:
template <typename T>
bool has(const std::string& keyword) const;
template <typename T>
std::vector<std::string> keys() const;
template <typename T>
std::vector<T> get_global(const std::string& keyword) const;

View File

@ -408,6 +408,23 @@ bool FieldProps::has<int>(const std::string& keyword) const {
return (this->int_data.count(keyword) != 0);
}
template <>
std::vector<std::string> FieldProps::keys<double>() const {
std::vector<std::string> klist;
for (const auto& data_pair : this->double_data)
klist.push_back(data_pair.first);
return klist;
}
template <>
std::vector<std::string> FieldProps::keys<int>() const {
std::vector<std::string> klist;
for (const auto& data_pair : this->int_data)
klist.push_back(data_pair.first);
return klist;
}
template <>
void FieldProps::erase<int>(const std::string& keyword) {
this->int_data.erase(keyword);

View File

@ -128,6 +128,9 @@ public:
template <typename T>
bool has(const std::string& keyword) const;
template <typename T>
std::vector<std::string> keys() const;
template <typename T>
const FieldData<T>* try_get(const std::string& keyword) {
const FieldData<T> * field_data;

View File

@ -90,6 +90,13 @@ const std::string& FieldPropsManager::default_region() const {
return this->fp->default_region();
}
template <typename T>
std::vector<std::string> FieldPropsManager::keys() const {
return this->fp->keys<T>();
}
template bool FieldPropsManager::supported<int>(const std::string&);
template bool FieldPropsManager::supported<double>(const std::string&);
@ -99,6 +106,9 @@ template bool FieldPropsManager::has<double>(const std::string&) const;
template std::vector<bool> FieldPropsManager::defaulted<int>(const std::string&) const;
template std::vector<bool> FieldPropsManager::defaulted<double>(const std::string&) const;
template std::vector<std::string> FieldPropsManager::keys<int>() const;
template std::vector<std::string> FieldPropsManager::keys<double>() const;
template std::vector<int> FieldPropsManager::get_global(const std::string& keyword) const;
template std::vector<double> FieldPropsManager::get_global(const std::string& keyword) const;

View File

@ -97,6 +97,17 @@ PERMX
// PERMX keyword is not fully initialized
BOOST_CHECK(!fpm.try_get<double>("PERMX"));
BOOST_CHECK(!fpm.has<double>("PERMX"));
{
const auto& keys = fpm.keys<double>();
BOOST_CHECK_EQUAL(keys.size(), 1);
BOOST_CHECK(std::find(keys.begin(), keys.end(), "PORO") != keys.end());
BOOST_CHECK(std::find(keys.begin(), keys.end(), "PERMX") == keys.end());
}
{
const auto& keys = fpm.keys<int>();
BOOST_CHECK_EQUAL(keys.size(), 0);
}
}