Logo Search packages:      
Sourcecode: ktechlab version File versions  Download package

void FlowPart::handleIfElse ( FlowCode code,
const QString &  case1Statement,
const QString &  case2Statement,
const QString &  case1,
const QString &  case2 
) [inherited]

Handles the addition of a if-else statement to the given FlowCode. This will order the code as necessary, adding the branches in the appropriate places

Parameters:
code The FlowCode where the if-else will be added
case1Statement The statement (e.g. "PORTA.0 is high") used for the first case
case2Statement The logically opposite statement (e.g. "PORTA.0 is low") (note that only one of the two statements will be used.
case1 The internal node id for case1
case2 The internal node id for case2

Definition at line 474 of file flowpart.cpp.

References FlowCode::addCode(), FlowCode::addCodeBranch(), FlowCode::addStopPart(), FlowPart::endPart(), FlowCode::isValidBranch(), FlowPart::outputPart(), and FlowCode::removeStopPart().

{
      if (!code) return;
      
      FlowPart *stop = 0l;
      FlowPart *part1 = outputPart(case1);
      FlowPart *part2 = outputPart(case2);
      
      if ( part1 && part2 ) stop = endPart( QStringList::split( ',', case1+","+case2 ) );
      
      if ( (!part1 && !part2) || (part1 == stop && part2 == stop) ) return;
      
      code->addStopPart(stop);
      
      if ( part1 && part1 != stop && code->isValidBranch(part1) )
      {
            // Use the case1 statement
            code->addCode( "if "+case1Statement+" then "+"\n{" );
            code->addCodeBranch(part1);
            code->addCode("}");
            
            if ( part2 && part2 != stop && code->isValidBranch(part2) )
            {
                  code->addCode( "else\n{" );
                  code->addCodeBranch(part2);
                  code->addCode("}");
            }
      }
      else if ( code->isValidBranch(part2) )
      {
            // Use the case2 statement
            code->addCode( "if "+case2Statement+" then "+"\n{" );
            code->addCodeBranch(part2);
            code->addCode("}");
      }
      
      code->removeStopPart(stop);
      code->addCodeBranch(stop);
}


Generated by  Doxygen 1.6.0   Back to index