make UDQFunctionTable constructible from variables

also make it default constructible, add accessors
and equality operator
This commit is contained in:
Arne Morten Kvarving
2019-12-12 11:18:21 +01:00
parent c0183ae78a
commit dab5f226e1
2 changed files with 51 additions and 3 deletions

View File

@@ -30,14 +30,24 @@ namespace Opm {
class UDQFunctionTable {
public:
using FunctionMap = std::unordered_map<std::string,
std::shared_ptr<UDQFunction>>;
explicit UDQFunctionTable(const UDQParams& params);
UDQFunctionTable();
UDQFunctionTable(const UDQParams& param,
const FunctionMap& map);
bool has_function(const std::string& name) const;
const UDQFunction& get(const std::string& name) const;
const UDQParams& getParams() const;
const FunctionMap& functionMap() const;
bool operator==(const UDQFunctionTable& data) const;
private:
void insert_function(std::shared_ptr<const UDQFunction> func);
void insert_function(std::shared_ptr<UDQFunction> func);
UDQParams params;
std::unordered_map<std::string, std::shared_ptr<const UDQFunction>> function_table;
FunctionMap function_table;
};
}
#endif

View File

@@ -91,8 +91,13 @@ UDQFunctionTable::UDQFunctionTable(const UDQParams& params_arg) :
this->insert_function( std::make_shared<UDQBinaryFunction>("UMAX", UDQBinaryFunction::UMAX ));
}
UDQFunctionTable::UDQFunctionTable(const UDQParams& param,
const FunctionMap& map) :
params(param),
function_table(map)
{}
void UDQFunctionTable::insert_function(std::shared_ptr<const UDQFunction> func) {
void UDQFunctionTable::insert_function(std::shared_ptr<UDQFunction> func) {
auto name = func->name();
this->function_table.emplace( std::move(name), std::move(func) );
}
@@ -111,4 +116,37 @@ const UDQFunction& UDQFunctionTable::get(const std::string& name) const {
const auto& pair_ptr = this->function_table.find(name);
return *pair_ptr->second;
}
const UDQParams& UDQFunctionTable::getParams() const {
return this->params;
}
const UDQFunctionTable::FunctionMap& UDQFunctionTable::functionMap() const {
return this->function_table;
}
bool UDQFunctionTable::operator==(const UDQFunctionTable& data) const {
if (!(this->getParams() == data.getParams()))
return false;
if (this->functionMap().size() != data.functionMap().size())
return false;
auto tIt = this->functionMap().begin();
auto dIt = data.functionMap().begin();
for (; tIt != this->functionMap().end(); ++tIt, ++dIt) {
if (tIt->first != dIt->first)
return false;
if ((tIt->second && !dIt->second) || (!tIt->second && dIt->second))
return false;
if (tIt->second && !(*tIt->second == *dIt->second))
return false;
}
return true;
}
}