GCC Code Coverage Report
Directory: ./ Exec Total Coverage
File: src/is-dirty-visitor.h Lines: 0 17 0.0 %
Date: 2020-05-14 11:23:33 Branches: 0 6 0.0 %

Line Branch Exec Source
1
// Copyright (c) 2019, Joseph Mirabel
2
// Authors: Joseph Mirabel (joseph.mirabel@laas.fr)
3
//
4
// This file is part of gepetto-viewer.
5
// gepetto-viewer is free software: you can redistribute it
6
// and/or modify it under the terms of the GNU Lesser General Public
7
// License as published by the Free Software Foundation, either version
8
// 3 of the License, or (at your option) any later version.
9
//
10
// gepetto-viewer is distributed in the hope that it will be
11
// useful, but WITHOUT ANY WARRANTY; without even the implied warranty
12
// of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13
// General Lesser Public License for more details.  You should have
14
// received a copy of the GNU Lesser General Public License along with
15
// gepetto-viewer. If not, see <http://www.gnu.org/licenses/>.
16
17
#include <gepetto/viewer/node-visitor.h>
18
#include <gepetto/viewer/node.h>
19
20
namespace gepetto {
21
namespace viewer {
22
  class IsDirtyVisitor : public NodeVisitor
23
  {
24
    public:
25
      IsDirtyVisitor () : NodeVisitor (true), isDirty_ (false) {}
26
27
      ~IsDirtyVisitor () {}
28
29
      bool valid (Node& node)
30
      {
31
        if (isDirty_) return false;
32
        return NodeVisitor::valid(node);
33
      }
34
35
      void apply (Node& node)
36
      {
37
        isDirty_ = node.isDirty();
38
        if (isDirty_) return;
39
        // Invisible nodes must be considered, otherwise they do not
40
        // disappear when they become invisible. Their children can be discarded.
41
        if (node.getVisibilityMode() == VISIBILITY_OFF) return;
42
        NodeVisitor::apply (node);
43
      }
44
45
      bool isDirty () const
46
      {
47
        return isDirty_;
48
      }
49
50
    protected:
51
      bool isDirty_;
52
  }; /* class Node */
53
  template <bool SetDirty>
54
  class SetDirtyVisitorTpl : public NodeVisitor
55
  {
56
    public:
57
      SetDirtyVisitorTpl () : NodeVisitor (true) {}
58
59
      ~SetDirtyVisitorTpl () {}
60
61
      void apply (Node& node)
62
      {
63
        node.setDirty(SetDirty);
64
        NodeVisitor::apply (node);
65
      }
66
  }; /* class Node */
67
  typedef SetDirtyVisitorTpl<true > SetDirtyVisitor;
68
  typedef SetDirtyVisitorTpl<false> SetCleanVisitor;
69
} /* namespace viewer */
70
} // namespace gepetto