Graphite  Version 3
An experimental 3D geometry processing program
node.h
Go to the documentation of this file.
1 /*
2  * GXML/Graphite: Geometry and Graphics Programming Library + Utilities
3  * Copyright (C) 2000 Bruno Levy
4  *
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation; either version 2 of the License, or
8  * (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program; if not, write to the Free Software
17  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18  *
19  * If you modify this software, you should include a notice giving the
20  * name of the person performing the modification, the date of modification,
21  * and the reason for such modification.
22  *
23  * Contact: Bruno Levy
24  *
25  * levy@loria.fr
26  *
27  * ISA Project
28  * LORIA, INRIA Lorraine,
29  * Campus Scientifique, BP 239
30  * 54506 VANDOEUVRE LES NANCY CEDEX
31  * FRANCE
32  *
33  * Note that the GNU General Public License does not permit incorporating
34  * the Software into proprietary programs.
35  */
36 
37 
38 #ifndef H_OGF_GOM_TYPES_NODE_H
39 #define H_OGF_GOM_TYPES_NODE_H
40 
41 #include <OGF/gom/common/common.h>
42 #include <OGF/gom/types/object.h>
43 
49 namespace OGF {
50 
51 //_________________________________________________________
52 
58  gom_class GOM_API Node : public Object {
59  public:
60 
66  explicit Node(Node* parent = nullptr) ;
67 
71  virtual ~Node() ;
72 
80  virtual void add_child(Node* child) ;
81 
86  virtual void remove_child(Node* child) ;
87 
88  gom_slots:
95  Node* ith_child(index_t i) const {
96  ogf_assert(i < get_nb_children()) ;
97  return children_[i] ;
98  }
99 
100  gom_properties:
105  size_t get_nb_children() const {
106  return children_.size();
107  }
108 
114  Node* get_parent() const {
115  return parent_;
116  }
117 
118  protected:
123  void swap_children(Node* n1, Node* n2) {
124  index_t i = NO_INDEX;
125  index_t j = NO_INDEX;
126  for(index_t k=0; k<children_.size(); ++k) {
127  if(children_[k] == n1) {
128  i = k;
129  }
130  if(children_[k] == n2) {
131  j = k;
132  }
133  }
134  geo_assert(i != NO_INDEX && j != NO_INDEX);
135  std::swap(children_[i], children_[j]);
136  }
137 
138  private:
139  std::vector< SmartPointer<Node> > children_ ;
140  Node* parent_ ;
141  } ;
142 
147 
148 //_________________________________________________________
149 
150 }
151 #endif
152 
#define geo_assert(x)
Verifies that a condition is met.
Definition: assert.h:149
A smart pointer with reference-counted copy semantics.
Definition: smart_pointer.h:76
A composite object in the GOM system.
Definition: node.h:58
virtual void remove_child(Node *child)
Removes a child from this Node. \parma[in] child a pointer to the child to be removed.
virtual void add_child(Node *child)
Adds a child to this Node.
Node * get_parent() const
Gets the parent.
Definition: node.h:114
void swap_children(Node *n1, Node *n2)
Swaps two children by indices.
Definition: node.h:123
Node(Node *parent=nullptr)
Node constructor.
virtual ~Node()
Node destructor.
Base class for all objects in the GOM system.
Definition: object.h:65
geo_index_t index_t
The type for storing and manipulating indices.
Definition: numeric.h:329
Global Graphite namespace.
Definition: common.h:76
SmartPointer< Node > Node_var
An automatic reference-counted pointer to a Node.
Definition: node.h:146
The base class for all objects in the GOM system.
Definitions common to all include files in the gom library.