vsg: include/vsg/nodes/Switch.h Source File

vsg 1.1.10 VulkanSceneGraph library |

Loading...
Searching...
No Matches
Switch.h
1#pragma once
2
3/* <editor-fold desc="MIT License">
4
5Copyright(c) 2018 Robert Osfield
6
7Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
8
9The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
10
11THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
12
13</editor-fold> */
14
15#include <vsg/core/ref_ptr.h>
16#include <vsg/nodes/Node.h>
17
18#include <vector>
19
20namespace vsg
21{
22
24 class VSG_DECLSPEC Switch : public Inherit<Node, Switch>
25 {
26 public:
27 Switch();
28 Switch(const Switch& rhs, const CopyOp& copyop = {});
29
30 struct Child
31 {
32 Mask mask = MASK_ALL;
33 ref_ptr<Node> node;
34 };
35
36 using Children = std::vector<Child>;
37 Children children;
38
40 void addChild(Mask mask, ref_ptr<Node> child);
41
43 void addChild(bool enabled, ref_ptr<Node> child);
44
46 void setAllChildren(bool enabled);
47
49 void setSingleChildOn(size_t index);
50
51 public:
52 ref_ptr<Object> clone(const CopyOp& copyop = {}) const override { return Switch::create(*this, copyop); }
53 int compare(const Object& rhs) const override;
54
55 template<class N, class V>
56 static void t_traverse(N& node, V& visitor)
57 {
58 for (auto& child : node.children)
59 {
60 if ((visitor.traversalMask & (visitor.overrideMask | child.mask)) != MASK_OFF) child.node->accept(visitor);
61 }
62 }
63
64 void traverse(Visitor& visitor) override { t_traverse(*this, visitor); }
65 void traverse(ConstVisitor& visitor) const override { t_traverse(*this, visitor); }
66 void traverse(RecordTraversal& visitor) const override { t_traverse(*this, visitor); }
67
68 void read(Input& input) override;
69 void write(Output& output) const override;
70
71 protected:
72 virtual ~Switch();
73 };
74 VSG_type_name(vsg::Switch);
75
76 inline Mask boolToMask(bool enabled) { return enabled ? MASK_ALL : MASK_OFF; }
77
78} // namespace vsg
vsg::CopyOp
Definition Object.h:42
vsg::Object
Definition Object.h:60
vsg::Switch::addChild
void addChild(bool enabled, ref_ptr< Node > child)
add a child to the back of the children list.
vsg::Switch::setSingleChildOn
void setSingleChildOn(size_t index)
set specified child to be on and all other children off.
vsg::Switch::addChild
void addChild(Mask mask, ref_ptr< Node > child)
add a child to the back of the children list.
vsg::Switch::setAllChildren
void setAllChildren(bool enabled)
set all children to specified state.
vsg::Switch::clone
ref_ptr< Object > clone(const CopyOp &copyop={}) const override
Definition Switch.h:52
vsg::Switch::compare
int compare(const Object &rhs) const override
compare two objects, return -1 if this object is less than rhs, return 0 if it's equal,...
vsg::ref_ptr
Definition ref_ptr.h:22
vsg::Switch::Child
Definition Switch.h:31