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

Assignment operator.

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

Definition at line 211 of file stack.hpp.

References likely, csdbg::stack< T >::m_top, csdbg::stack< T >::node_with(), and unlikely.

212 {
213  if ( unlikely(this == &rval) )
214  return *this;
215 
216  /* Check if the stacks overlap and detach shared data pointers */
217  for (node<T> *n = m_top; likely(n != NULL); n = n->m_link)
218  if ( unlikely(rval.node_with(n->m_data) != NULL) )
219  n->detach();
220 
221  clear();
222  for (node<T> *n = rval.m_top; likely(n != NULL); n = n->m_link) {
223  T *copy = NULL;
224  try {
225  copy = new T(*n->m_data);
226  push(copy);
227  }
228 
229  catch (...) {
230  delete copy;
231  throw;
232  }
233  }
234 
235  return *this;
236 }
#define likely(expr)
Offer a hint (positive) to the pipeline branch predictor.
Definition: config.hpp:344
node< T > * m_top
Stack top.
Definition: stack.hpp:34
virtual stack & clear()
Empty the stack.
Definition: stack.hpp:310
virtual stack & push(T *)
Push a node on the stack.
Definition: stack.hpp:266
#define unlikely(expr)
Offer a hint (negative) to the pipeline branch predictor.
Definition: config.hpp:349

+ Here is the call graph for this function: