g4tools  5.4.0
Public Member Functions | Protected Member Functions | Protected Attributes | List of all members
tools::sg::group Class Reference
Inheritance diagram for tools::sg::group:
Inheritance graph
[legend]
Collaboration diagram for tools::sg::group:
Collaboration graph
[legend]

Public Member Functions

virtual void render (render_action &a_action)
 
virtual void pick (pick_action &a_action)
 
virtual void bbox (bbox_action &a_action)
 
virtual void event (event_action &a_action)
 
virtual void search (search_action &a_action)
 
virtual void get_matrix (get_matrix_action &a_action)
 
virtual bool write (write_action &a_action)
 
virtual void is_visible (visible_action &a_action)
 
 group ()
 
virtual ~group ()
 
 group (const group &a_from)
 
groupoperator= (const group &a_from)
 
void add (node *a_node)
 
void add_front (node *a_node)
 
void set (unsigned int a_index, node *a_node)
 
bool replace (const node *a_from, node *a_to, bool a_del)
 
void swap (unsigned int a_1, unsigned int a_2)
 
template<class T >
T * search () const
 
void * rsearch_from (const node *a_node, const std::string &a_class, bool a_inc_a_node=true) const
 
bool remove (const node *a_node)
 
bool remove_index (unsigned int a_index)
 
bool delete_from (const node *a_node, bool a_inc_a_node=true)
 
void transfer (group &a_from)
 
void transfer (std::vector< node * > &a_to)
 
void clear ()
 
void raw_clear ()
 
size_t size () const
 
bool empty () const
 
nodeoperator[] (size_t a_index) const
 
const std::vector< node * > & children () const
 
std::vector< node * > & children ()
 
bool insert (unsigned int a_index, node *a_new)
 
template<class T >
T * rsearch () const
 
bool position (const node *a_node, unsigned int &a_index) const
 
nodenode_at (unsigned int a_index) const
 
template<class T >
T * child (unsigned int a_index) const
 
- Public Member Functions inherited from tools::sg::node
virtual void * cast (const std::string &a_class) const
 
virtual const std::string & s_cls () const =0
 
virtual nodecopy () const =0
 
virtual unsigned int cls_version () const
 
virtual const desc_fieldsnode_desc_fields () const
 
virtual bool read (read_action &a_action)
 
virtual void protocol_one_fields (std::vector< field * > &a_fields) const
 
virtual bool draw_in_frame_buffer () const
 
virtual bool touched ()
 
virtual void reset_touched ()
 
 node ()
 
virtual ~node ()
 
void touch ()
 
fieldfield_from_desc (const field_desc &a_desc) const
 
void dump_field_descs (std::ostream &a_out) const
 
fieldfind_field_by_name (const std::string &a_name) const
 

Protected Member Functions

bool write_children (write_action &a_action)
 
- Protected Member Functions inherited from tools::sg::node
 node (const node &)
 
nodeoperator= (const node &)
 
void add_field (field *a_field)
 
bool write_fields (write_action &a_action)
 
bool read_fields (read_action &a_action)
 
field_desc::offset_t field_offset (const field *a_field) const
 
fieldfind_field (const field_desc &a_rdesc) const
 
void check_fields (std::ostream &a_out) const
 

Protected Attributes

std::vector< node * > m_children
 

Detailed Description

Definition at line 21 of file group.

Constructor & Destructor Documentation

◆ group() [1/2]

tools::sg::group::group ( )
inline

Definition at line 80 of file group.

80 :node(){}

◆ ~group()

virtual tools::sg::group::~group ( )
inlinevirtual

Definition at line 81 of file group.

81 {clear();}

◆ group() [2/2]

tools::sg::group::group ( const group a_from)
inline

Definition at line 83 of file group.

84  :node(a_from)
85  {
86  tools_vforcit(node*,a_from.m_children,it) m_children.push_back((*it)->copy());
87  }

Member Function Documentation

◆ add()

void tools::sg::group::add ( node a_node)
inline

Definition at line 96 of file group.

96  {
97  //WARNING : take ownership of a_node.
98  m_children.push_back(a_node);
99  }

◆ add_front()

void tools::sg::group::add_front ( node a_node)
inline

Definition at line 100 of file group.

100  {
101  //WARNING : take ownership of a_node.
102  m_children.insert(m_children.begin(),a_node);
103  }

◆ bbox()

virtual void tools::sg::group::bbox ( bbox_action a_action)
inlinevirtual

Reimplemented from tools::sg::node.

Reimplemented in tools::sg::separator, and tools::sg::_switch.

Definition at line 42 of file group.

42  {
43  tools_vforcit(node*,m_children,it) (*it)->bbox(a_action);
44  }

◆ child()

template<class T >
T* tools::sg::group::child ( unsigned int  a_index) const
inline

Definition at line 302 of file group.

302  {
303  if(a_index>=m_children.size()) return 0;
304  node* _node = m_children[a_index];
305  if(!_node) return 0;
306  return safe_cast<node,T>(*_node);
307  }

◆ children() [1/2]

std::vector<node*>& tools::sg::group::children ( )
inline

Definition at line 250 of file group.

250 {return m_children;}

◆ children() [2/2]

const std::vector<node*>& tools::sg::group::children ( ) const
inline

Definition at line 249 of file group.

249 {return m_children;}

◆ clear()

void tools::sg::group::clear ( )
inline

Definition at line 235 of file group.

235 {safe_reverse_clear<node>(m_children);}

◆ delete_from()

bool tools::sg::group::delete_from ( const node a_node,
bool  a_inc_a_node = true 
)
inline

Definition at line 194 of file group.

194  {
195  bool found = false;
196  std::vector<node*>::iterator it;
197  for(it=m_children.begin();it!=m_children.end();) {
198  if(!found) {
199  if(*it==a_node) {
200  found = true;
201  if(!a_inc_a_node) {it++;continue;} //skip a_node
202  }
203  }
204  if(found) {
205  node* old = *it;
206  it = m_children.erase(it);
207  delete old;
208  } else {
209  it++;
210  }
211  }
212  return found;
213  }

◆ empty()

bool tools::sg::group::empty ( ) const
inline

Definition at line 244 of file group.

244 {return m_children.size()?false:true;}

◆ event()

virtual void tools::sg::group::event ( event_action a_action)
inlinevirtual

Reimplemented from tools::sg::node.

Reimplemented in tools::sg::separator, and tools::sg::_switch.

Definition at line 45 of file group.

45  {
47  (*it)->event(a_action);
48  if(a_action.done()) break;
49  }
50  }

◆ get_matrix()

virtual void tools::sg::group::get_matrix ( get_matrix_action a_action)
inlinevirtual

Reimplemented from tools::sg::node.

Reimplemented in tools::sg::separator.

Definition at line 61 of file group.

61  {
63  (*it)->get_matrix(a_action);
64  if(a_action.done()) return;
65  }
66  }

◆ insert()

bool tools::sg::group::insert ( unsigned int  a_index,
node a_new 
)
inline

Definition at line 252 of file group.

252  { //iv2sg
253  if(a_index==m_children.size()) {
254  m_children.push_back(a_new);
255  return true;
256  }
257  unsigned int index = 0;
258  std::vector<node*>::iterator it;
259  for(it=m_children.begin();it!=m_children.end();++it,index++) {
260  if(index==a_index) {
261  m_children.insert(it,a_new);
262  return true;
263  }
264  }
265  return false;
266  }

◆ is_visible()

virtual void tools::sg::group::is_visible ( visible_action a_action)
inlinevirtual

Reimplemented from tools::sg::node.

Reimplemented in tools::sg::separator.

Definition at line 74 of file group.

74  {
76  (*it)->is_visible(a_action);
77  }
78  }

◆ node_at()

node* tools::sg::group::node_at ( unsigned int  a_index) const
inline

Definition at line 296 of file group.

296  {
297  if(a_index>=m_children.size()) return 0;
298  return m_children[a_index];
299  }

◆ operator=()

group& tools::sg::group::operator= ( const group a_from)
inline

Definition at line 88 of file group.

88  {
89  node::operator=(a_from);
90  if(&a_from==this) return *this;
91  clear();
92  tools_vforcit(node*,a_from.m_children,it) m_children.push_back((*it)->copy());
93  return *this;
94  }

◆ operator[]()

node* tools::sg::group::operator[] ( size_t  a_index) const
inline

Definition at line 245 of file group.

245  {
246  //WARNING : no check is done on a_index.
247  return m_children[a_index];
248  }

◆ pick()

virtual void tools::sg::group::pick ( pick_action a_action)
inlinevirtual

Reimplemented from tools::sg::node.

Reimplemented in tools::sg::separator, and tools::sg::_switch.

Definition at line 36 of file group.

36  {
38  (*it)->pick(a_action);
39  if(a_action.done()) break;
40  }
41  }

◆ position()

bool tools::sg::group::position ( const node a_node,
unsigned int &  a_index 
) const
inline

Definition at line 287 of file group.

287  {
288  a_index = 0;
290  if(a_node==(*it)) return true;
291  a_index++;
292  }
293  return false;
294  }

◆ raw_clear()

void tools::sg::group::raw_clear ( )
inline

Definition at line 237 of file group.

237  { //used for sg coming from exlib/rroot/vis_volume.
238  tools::raw_clear<node>(m_children); //inlib:: is needed.
239  }

◆ remove()

bool tools::sg::group::remove ( const node a_node)
inline

Definition at line 174 of file group.

174  {
175  //NOTE : no delete on a_node is performed.
177  if(a_node==(*it)) {
178  m_children.erase(it);
179  return true;
180  }
181  }
182  return false;
183  }

◆ remove_index()

bool tools::sg::group::remove_index ( unsigned int  a_index)
inline

Definition at line 185 of file group.

185  {
186  //NOTE : no delete on node at a_index is performed.
187  std::vector<node*>::iterator it = m_children.begin();
188  it += a_index;
189  if(it>=m_children.end()) return false;
190  m_children.erase(it);
191  return true;
192  }

◆ render()

virtual void tools::sg::group::render ( render_action a_action)
inlinevirtual

Reimplemented from tools::sg::node.

Reimplemented in tools::sg::separator, and tools::sg::_switch.

Definition at line 24 of file group.

24  {
25 #ifdef TOOLS_SG_GROUP_DEBUG
26  std::ostream& out = a_action.out();
28  out << "debug : tools::sg::group::render : children : " << (*it)->s_cls() << " begin : " << std::endl;
29  (*it)->render(a_action);
30  out << "debug : tools::sg::group::render : children : " << (*it)->s_cls() << " end," << std::endl;
31  }
32 #else
33  tools_vforcit(node*,m_children,it) (*it)->render(a_action);
34 #endif
35  }

◆ replace()

bool tools::sg::group::replace ( const node a_from,
node a_to,
bool  a_del 
)
inline

Definition at line 110 of file group.

110  {
112  if((*it)==a_from) {
113  node* old = *it;
114  (*it) = a_to;
115  if(a_del) delete old;
116  return true;
117  }
118  }
119  return false;
120  }

◆ rsearch()

template<class T >
T* tools::sg::group::rsearch ( ) const
inline

Definition at line 279 of file group.

279  { //used in agora.
281  T* o = safe_cast<node,T>(*(*it));
282  if(o) return o;
283  }
284  return 0;
285  }

◆ rsearch_from()

void* tools::sg::group::rsearch_from ( const node a_node,
const std::string &  a_class,
bool  a_inc_a_node = true 
) const
inline

Definition at line 154 of file group.

156  {
157  bool found = false;
159  // the below logic permits to test a_node.
160  if(!found) {
161  if(*it==a_node) {
162  found = true;
163  if(!a_inc_a_node) continue; //skip a_node
164  }
165  }
166  if(found) {
167  void* p = (*it)->cast(a_class);
168  if(p) return p;
169  }
170  }
171  return 0;
172  }

◆ search() [1/2]

template<class T >
T* tools::sg::group::search ( ) const
inline

Definition at line 130 of file group.

130  {
132  T* o = safe_cast<node,T>(*(*it));
133  if(o) return o;
134  }
135  return 0;
136  }

◆ search() [2/2]

virtual void tools::sg::group::search ( search_action a_action)
inlinevirtual

Reimplemented from tools::sg::node.

Reimplemented in tools::sg::_switch.

Definition at line 51 of file group.

51  {
52  parent::search(a_action);
53  if(a_action.done()) return;
54  if(a_action.do_path()) a_action.path_push(this);
56  (*it)->search(a_action);
57  if(a_action.done()) return;
58  }
59  if(a_action.do_path()) a_action.path_pop();
60  }

◆ set()

void tools::sg::group::set ( unsigned int  a_index,
node a_node 
)
inline

Definition at line 104 of file group.

104  {
105  //WARNING : take ownership of a_node.
106  //WARNING : no check is done on a_index.
107  m_children[a_index] = a_node;
108  }

◆ size()

size_t tools::sg::group::size ( ) const
inline

Definition at line 243 of file group.

243 {return m_children.size();}

◆ swap()

void tools::sg::group::swap ( unsigned int  a_1,
unsigned int  a_2 
)
inline

Definition at line 122 of file group.

122  {
123  // WARNING : no check is done on a_1,a_2.
124  node* tmp = m_children[a_1];
125  m_children[a_1] = m_children[a_2];
126  m_children[a_2] = tmp;
127  }

◆ transfer() [1/2]

void tools::sg::group::transfer ( group a_from)
inline

Definition at line 215 of file group.

215  {
216  if(&a_from==this) return;
217  clear();
218  m_children.resize(a_from.size());
219  std::vector<node*>::iterator it = m_children.begin();
220  std::vector<node*>::iterator fit = a_from.m_children.begin();
221  for(;fit!=a_from.m_children.end();++it,++fit) {
222  *it = *fit;
223  *fit = 0;
224  }
225  a_from.m_children.clear();
226  }

◆ transfer() [2/2]

void tools::sg::group::transfer ( std::vector< node * > &  a_to)
inline

Definition at line 228 of file group.

228  {
229  a_to = m_children;
230  m_children.clear();
231  //touch();
232  }

◆ write()

virtual bool tools::sg::group::write ( write_action a_action)
inlinevirtual

Reimplemented from tools::sg::node.

Reimplemented in tools::sg::separator, and tools::sg::_switch.

Definition at line 67 of file group.

67  {
68  if(!a_action.beg_node(*this)) return false;
69  if(!write_fields(a_action)) return false;
70  if(!write_children(a_action)) return false;
71  if(!a_action.end_node(*this)) return false;
72  return true;
73  }

◆ write_children()

bool tools::sg::group::write_children ( write_action a_action)
inlineprotected

Definition at line 311 of file group.

311  {
313  if(!(*it)->write(a_action)) return false;
314  }
315  return true;
316  }

Member Data Documentation

◆ m_children

std::vector<node*> tools::sg::group::m_children
protected

Definition at line 318 of file group.


The documentation for this class was generated from the following file:
tools::sg::group::m_children
std::vector< node * > m_children
Definition: group:318
tools::sg::node::operator=
node & operator=(const node &)
Definition: node:124
tools_vforcrit
#define tools_vforcrit(a__T, a__v, a__it)
Definition: forit:16
tools_vforit
#define tools_vforit(a__T, a__v, a__it)
Definition: forit:13
tools::file::found
bool found(const std::string &a_file, const std::string &a_what, std::vector< std::string > &a_found)
Definition: file:507
tools::sg::group::clear
void clear()
Definition: group:235
tools::sg::node::write_fields
bool write_fields(write_action &a_action)
Definition: node:132
tools_vforcit
#define tools_vforcit(a__T, a__v, a__it)
Definition: forit:7
tools::sg::group::write_children
bool write_children(write_action &a_action)
Definition: group:311
tools::sg::node::node
node()
Definition: node:106