lundi 26 décembre 2022

C++ use an Object instance to execute or skip succeeding lines of code

I'm looking for a creative way to abide by the framework of my current project. I'm kinda stuck with it, here is the situation.

The developer's code needs to be always enclosed within an if statement because there is an external control by the framework that allows the user to skip or execute a code/procedure.

if (condition) {
  int s;
  std::string myprocedurename;
}

instead of doing that always, I would like to explore a way to implement a class that will in effect handle the if() condition requirement so that the user code for procedures will look something like:

void myProcedure
{
  ConditionalExecuteContext cxt;
  
  int s;
  std::string myprocedurename;
}

I'm trying to "emulate" the if() condition effect in the ConditionalExecuteContext class but to no success. Maybe someone will have a better idea? If only I can change the framework and implement something better than the if statement I would, but since I arrived late to the party we're kind stuck with it. :)

Aucun commentaire:

Enregistrer un commentaire