libcsdbg  1.28
C++ exception (and generic) stack trace debug library
template<class T>
chain< T > & csdbg::chain< T >::add ( T *  d)
virtual

Add a node to the chain.

Parameters
[in]dthe new node data pointer
Returns
*this
Exceptions
std::bad_alloc
csdbg::exception

Definition at line 363 of file chain.hpp.

References likely, csdbg::node< T >::link_to(), csdbg::node< T >::m_link, and unlikely.

Referenced by csdbg::parser::get_dictionary_names(), csdbg::parser::get_style_names(), csdbg::util::getenv(), csdbg::util::init(), and csdbg::string::split().

364 {
365  if ( unlikely(d == NULL) )
366  throw exception("invalid argument: d (=%p)", d);
367 
368  /* If the data pointer already exists in the chain */
369  if ( unlikely(node_with(d) != NULL) )
370  throw exception("chain @ %p already has a node with data @ %p", this, d);
371 
372  node<T> *n = new node<T>(d);
373 
374  /* Add the node to the chain tail */
375  if ( likely(m_head != NULL) ) {
376  n->m_link = m_tail;
377  m_tail->link_to(n);
378  m_tail = n;
379  }
380 
381  /* If it is the first node */
382  else
383  m_head = m_tail = n;
384 
385  m_size++;
386  return *this;
387 }
u32 m_size
Node count.
Definition: chain.hpp:43
#define likely(expr)
Offer a hint (positive) to the pipeline branch predictor.
Definition: config.hpp:344
node< T > * m_tail
Chain tail.
Definition: chain.hpp:41
node< T > * m_head
Chain head.
Definition: chain.hpp:39
#define unlikely(expr)
Offer a hint (negative) to the pipeline branch predictor.
Definition: config.hpp:349
virtual node< T > * node_with(const T *) const
Get the node with m_data == d.
Definition: chain.hpp:137

+ Here is the call graph for this function:

+ Here is the caller graph for this function: