Optimizing if case in c++ for calling member functions

122 views Asked by At
HRESULT Block::SendAlarm(const std::string& variableName, USHORT value)
{
    if (variableName == aAtt_name_Fault)      builder.Alarms().Fault(value);
    if (variableName == aAtt_name_BATT)       builder.Alarms().BATT(value);
    if (variableName == aAtt_name_PWR)        builder.Alarms().PWR(value);
    if (variableName == aAtt_name_OCCLUSION)  builder.Alarms().OCCLUSION(value);
 ... many if statements follows
        
        return S_OK;
}

I have the above code, in which builder is a Ventilator object and Alarms() is member class and object of builder. Now am comparing the input strings and calling the member functions of builder.Alarms() using If condition. Is any other better way to do this?

0

There are 0 answers