DiscussionsIssue archiveOCCT:Application Framework

Archived issue #0026832

TFunction_Iterator won't work if ExecutionStatus is Standard_False.

CommunityOCCT:Application Frameworkclosed18 public notes

Search issues

Description

There are several functions created, but the loop of below will never be entered. "iterator.More()" always returns false.

for(TFunction_Iterator iterator(aLabel); iterator.More(); iterator.Next())
{
    // This loop never entered
}

if change the usage as below, it will work:

TFunction_Iterator iterator;
iterator.SetUsageOfExecutionStatus(Standard_True);
for(iterator.Init(aLabel); iterator.More(); iterator.Next())
{
   // Works well
}

Steps to reproduce

Dear Szy, could you please review the modification: CR26832.

Public activity

18 archived notes

Participants are labeled by their role within this record.

01Author
The simplest way to reproduce this bug is to create just one function and iterate the function with TFunction_Iterator.
02Commenter 2
Could you check it.
03Commenter 2
It seems it is not truth... the method More() of the function iterator returns true while the graph of functions is not iterated completely. If the execution status is used, it takes into account the status of the function and iterates only through not executed yet functions. Otherwise, it iterates the whole graph of functions.
You may look at a sample here : #0024665 Insert your iteration code at the end of createDefaultModel1() or createDefaultModel2() methods of MainWindow.cpp and check how it behaves. Any questions are welcome!
04Author
Dear vro,

The sample is different about the iterator usage. The bug just occurs in for loop form, it works well if using like below, i'm sure it will be reproducible use in for loop.

    while (!fIterator.Current().IsEmpty())
    {
        const TDF_LabelList& funcs = fIterator.Current();
        if (funcs.Extent() > nbx)
            nbx = funcs.Extent();
        nby++;
        fIterator.Next();
    }
05Author
for(TFunction_Iterator iterator(aLabel); iterator.More(); iterator.Next())
 {
     // This loop never entered
 }
06Commenter 2
So, if there is no bugs, we may close the issue, I suppose. Any proposals for improvement of the code are welcome!
07Author
Dear vro,

Below for look desn't work as my previous stated. This does not align with OCCT methodnology. OCCT iterator might work in style as below:

for(TFunction_Iterator iterator(aLabel); iterator.More(); iterator.Next())
  {
      // This loop never entered
  }

Actually, there is a bug, but the sample escape it. For a normal user, there should be no way to make it work.
08Author
I propose to implement the TFunction_Iterator::More() by just returning {!fIterator.Current().IsEmpty()} if it doesn't consider the executing status.
09Commenter 2
If you add your code-snippet to the sample application and run it in debug mode, you would see that the iterator perfectly works in spite of the execution status.
I don't see any reason to change the method More() of the iterator. It works as expected. And it works fine. Did you check it in the sample application?
10Author
Dear vro,

please check your implementation as below, if there is just one function, the last line "myPassedFunctions.Extent() < myScope->GetFunctions().Extent();" should never be true, becasue there are equal.


Standard_Boolean TFunction_Iterator::More() const
{
  if (myUsageOfExecutionStatus)
  {
    TFunction_DoubleMapIteratorOfDoubleMapOfIntegerLabel itrm(myScope->GetFunctions());
    for (; itrm.More(); itrm.Next())
    {
      const TDF_Label& L = itrm.Key2();
      if (GetStatus(L) == TFunction_ES_NotExecuted)
    return Standard_True;
    }
    return Standard_False;
  }
  return myPassedFunctions.Extent() < myScope->GetFunctions().Extent();
}
11Commenter 2
Hello Vico! Many thanks! Now I see the bug. Indeed, for the case of one function the iterator doesn't return it. I will fix it, thanks again!
12Commenter 3
Branch [archived branch] has been created by Commenter 2.

[revision removed]


Detailed log of new commits:

Author: Commenter 2
Date: Fri Feb 19 12:21:43 2016 +0300

    0026832: TFunction_Iterator won't work if ExecutionStatus is Standard_False.
    The method TFunction_Iterator::More() is corrected().
13Commenter 2
There is no test-case or a draw-command. Testing is possible only through a new FuncDemo application.
14Commenter 14
Reviewed.
15Commenter 3
Branch [archived branch] has been updated forcibly by Participant.

[revision removed]
16Commenter 16
Branch [archived branch] has been rebased on the current master
17Commenter 17
Dear Commenter 1,

Branch CR26832 from occt git-repository (and master from products git-repository) was compiled on Linux, MacOS and Windows platforms and tested.
[revision removed]

Number of compiler warnings:
occt component:
   Linux: 0 (0 on master)
   Windows: 0 (0 on master)
   MacOS: 0 (0 on master)
products component:
   Linux: 68
   Windows: 0
   MacOS: 1133

Regressions/Differences:
Not detected

Testing cases:
Not needed

Testing on Linux:
Total MEMORY difference: 89390901 / 90308255 [-1.02%]
Total CPU difference: 19330.12000000004 / 19527.04000000009 [-1.01%]

Testing on Windows:
Total MEMORY difference: 57456303 / 57486237 [-0.05%]
Total CPU difference: 17932.82975329875 / 17687.752182298846 [+1.39%]
18Commenter 3
Branch [archived branch] has been deleted by Participant.

[revision removed]