[aGrUM] new BayesNet::changeVariableLabel method

parent ecf97f50
......@@ -314,6 +314,29 @@ namespace gum {
changeVariableName(idFromName(name), new_name);
}
/**
* @brief Changes a variable's label in the gum::BayesNet.
*
* This will change the gum::LabelizedVariable names in the gum::BayesNet.
*
* @throws DuplicateLabel Raised if new_label is already used in this
* gum::LabelizedVariable.
* @throws NotFound Raised if no variable matches id or if the variable is not a
* LabelizedVariable
*/
void changeVariableLabel(NodeId id,
const std::string& old_label,
const std::string& new_label);
/**
* @brief Changes a variable's name.
*/
void changeVariableLabel(const std::string& name,
const std::string& old_label,
const std::string& new_label) {
changeVariableLabel(idFromName(name), old_label, new_label);
}
/**
* @brief Returns a variable's id in the gum::BayesNet.
*
......
......@@ -199,6 +199,19 @@ namespace gum {
__varMap.changeName(id, new_name);
}
template < typename GUM_SCALAR >
INLINE void BayesNet< GUM_SCALAR >::changeVariableLabel(
NodeId id, const std::string& old_label, const std::string& new_label) {
if (variable(id).varType() != VarType::Labelized) {
GUM_ERROR(NotFound, "Variable " << id << " is not a LabelizedVariable.");
}
LabelizedVariable* var = dynamic_cast< LabelizedVariable* >(
const_cast< DiscreteVariable* >(&variable(id)));
var->changeLabel(var->posLabel(old_label), new_label);
}
template < typename GUM_SCALAR >
INLINE NodeId BayesNet< GUM_SCALAR >::nodeId(const DiscreteVariable& var) const {
return __varMap.get(var);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment