libcsdbg  1.28
C++ exception (and generic) stack trace debug library
template<class T >
chain< T > & csdbg::chain< T >::operator= ( const chain< T > &  rval)
virtual

Assignment operator.

Parameters
[in]rvalthe assigned object
Returns
*this
Exceptions
std::bad_alloc
Note
Automatically resolves collisions when the chains overlap (when they have nodes with the same data pointer)

Definition at line 296 of file chain.hpp.

References csdbg::node< T >::detach(), likely, csdbg::node< T >::link(), csdbg::node< T >::m_data, csdbg::chain< T >::m_head, csdbg::chain< T >::node_with(), and unlikely.

Referenced by csdbg::dictionary::operator=().

297 {
298  if ( unlikely(this == &rval) )
299  return *this;
300 
301  /* Check if the chains overlap and detach shared data pointers */
302  node<T> *cur = m_head, *prev = NULL, *next;
303  while ( likely(cur != NULL) ) {
304  if ( unlikely(rval.node_with(cur->m_data) != NULL) )
305  cur->detach();
306 
307  next = cur->link(prev);
308  prev = cur;
309  cur = next;
310  }
311 
312  clear();
313  cur = rval.m_head;
314  prev = NULL;
315  while ( likely(cur != NULL) ) {
316  T *copy = NULL;
317  try {
318  copy = new T(*cur->m_data);
319  add(copy);
320  }
321 
322  catch (...) {
323  delete copy;
324  throw;
325  }
326 
327  next = cur->link(prev);
328  prev = cur;
329  cur = next;
330  }
331 
332  return *this;
333 }
virtual chain & clear()
Empty the chain.
Definition: chain.hpp:413
#define likely(expr)
Offer a hint (positive) to the pipeline branch predictor.
Definition: config.hpp:344
node< T > * m_head
Chain head.
Definition: chain.hpp:39
virtual chain & add(T *)
Add a node to the chain.
Definition: chain.hpp:363
#define unlikely(expr)
Offer a hint (negative) to the pipeline branch predictor.
Definition: config.hpp:349

+ Here is the call graph for this function:

+ Here is the caller graph for this function: