vsg  1.1.0
VulkanSceneGraph library
Group.h
1 #pragma once
2 
3 /* <editor-fold desc="MIT License">
4 
5 Copyright(c) 2018 Robert Osfield
6 
7 Permission 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 
9 The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
10 
11 THE 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/Allocator.h>
16 #include <vsg/nodes/Node.h>
17 
18 #include <vector>
19 namespace vsg
20 {
21 
23  class VSG_DECLSPEC Group : public Inherit<Node, Group>
24  {
25  public:
26  explicit Group(size_t numChildren = 0);
27 
28  template<typename Iterator>
29  Group(Iterator begin, Iterator end)
30  {
31  for (Iterator itr = begin; itr != end; ++itr) addChild(*itr);
32  }
33 
34  template<class N, class V>
35  static void t_traverse(N& node, V& visitor)
36  {
37  for (auto& child : node.children) child->accept(visitor);
38  }
39 
40  void traverse(Visitor& visitor) override { t_traverse(*this, visitor); }
41  void traverse(ConstVisitor& visitor) const override { t_traverse(*this, visitor); }
42  void traverse(RecordTraversal& visitor) const override { t_traverse(*this, visitor); }
43 
44  int compare(const Object& rhs) const override;
45 
46  void read(Input& input) override;
47  void write(Output& output) const override;
48 
49  using Children = std::vector<ref_ptr<Node>, allocator_affinity_nodes<ref_ptr<Node>>>;
50  Children children;
51 
52  void addChild(vsg::ref_ptr<Node> child)
53  {
54  children.push_back(child);
55  }
56 
57  protected:
58  virtual ~Group();
59  };
60  VSG_type_name(vsg::Group);
61 
62 } // namespace vsg
Definition: ConstVisitor.h:147
Group node provides a list of children.
Definition: Group.h:24
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,...
Definition: Inherit.h:28
Definition: Input.h:44
Definition: Object.h:42
Definition: Output.h:41
RecordTraversal traverses a scene graph doing view frustum culling and invoking state/commands to rec...
Definition: RecordTraversal.h:61
Definition: Visitor.h:147
Definition: ref_ptr.h:22
std container adapter for allocating with MEMORY_AFFINITY_NODES
Definition: Allocator.h:138