Horizon Official Technical Documentation
Horizon::Structures::LinkedList::Head Class Reference

LinkedList Head class. This class is used to manage a linked list of Elements. It is used as a base class for other classes that need to manage a linked list. It is not intended to be used directly. More...

#include <Head.hpp>

+ Inheritance diagram for Horizon::Structures::LinkedList::Head:
+ Collaboration diagram for Horizon::Structures::LinkedList::Head:

Classes

class  Iterator
 

Public Types

typedef Iterator< Elementiterator
 

Public Member Functions

 Head ()
 
bool is_empty () const
 Returns true if the list is empty. More...
 
Elementfirst ()
 Returns the first Element in the list. More...
 
Element const * first () const
 
Elementlast ()
 Returns the last Element in the list. More...
 
Element const * last () const
 
void push_front (Element *pElem)
 push_front() and push_back() are used to add an Element to the list. More...
 
void push_back (Element *pElem)
 
uint32_t get_size () const
 returns the number of Elements in the list (not including the head and tail Elements or the first and last Elements) More...
 
void inc_size ()
 
void dec_size ()
 

Protected Member Functions

 ~Head ()
 

Private Member Functions

 Head (Head const &)=delete
 
Headoperator= (Head const &)=delete
 

Private Attributes

Element _first
 
Element _last
 
uint32_t _size
 

Detailed Description

LinkedList Head class. This class is used to manage a linked list of Elements. It is used as a base class for other classes that need to manage a linked list. It is not intended to be used directly.

Parameters
ElementThe Element type that will be managed by this Head.
_firstThe first Element in the list.
_lastThe last Element in the list.
_sizeThe size of the list. Thread safety: This class is not thread safe and is not intended to be used in a multi-threaded environment.

Member Typedef Documentation

◆ iterator

Constructor & Destructor Documentation

◆ Head() [1/2]

Horizon::Structures::LinkedList::Head::Head ( )
inline
33 : _size(0)
34 {
35 // create empty list
36
39 }
Element * _next
Definition: Element.hpp:22
Element * _prev
Definition: Element.hpp:23
uint32_t _size
Definition: Head.hpp:30
Element _first
Definition: Head.hpp:28
Element _last
Definition: Head.hpp:29

References _first, _last, Horizon::Structures::LinkedList::Element::_next, and Horizon::Structures::LinkedList::Element::_prev.

◆ Head() [2/2]

Horizon::Structures::LinkedList::Head::Head ( Head const &  )
privatedelete

◆ ~Head()

Horizon::Structures::LinkedList::Head::~Head ( )
inlineprotected
207{ }

Member Function Documentation

◆ dec_size()

void Horizon::Structures::LinkedList::Head::dec_size ( )
inline
89{ --_size; }

References _size.

◆ first() [1/2]

Element * Horizon::Structures::LinkedList::Head::first ( )
inline

Returns the first Element in the list.

46{ return (is_empty() ? nullptr : _first._next); }
bool is_empty() const
Returns true if the list is empty.
Definition: Head.hpp:43

References _first, Horizon::Structures::LinkedList::Element::_next, and is_empty().

Referenced by Horizon::Structures::LinkedList::RefManager< TO, FROM >::first(), and get_size().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ first() [2/2]

Element const * Horizon::Structures::LinkedList::Head::first ( ) const
inline
47{ return (is_empty() ? nullptr : _first._next); }

References _first, Horizon::Structures::LinkedList::Element::_next, and is_empty().

+ Here is the call graph for this function:

◆ get_size()

uint32_t Horizon::Structures::LinkedList::Head::get_size ( ) const
inline

returns the number of Elements in the list (not including the head and tail Elements or the first and last Elements)

70 {
71 if (!_size)
72 {
73 uint32_t result = 0;
74 Element const* e = first();
75
76 while (e != nullptr)
77 {
78 e = e->next();
79 if (e)
80 ++result;
81 }
82 return result;
83 }
84 else
85 return _size;
86 }
Element * first()
Returns the first Element in the list.
Definition: Head.hpp:46

References _size, first(), and Horizon::Structures::LinkedList::Element::next().

Referenced by BOOST_AUTO_TEST_CASE(), GridUnitExistenceNotifier::notify(), GridUnitSpawnNotifier::notify(), GridUnitMovementNotifier::notify(), GridUnitSkillUseNotifier::notify(), GridUnitBasicAttackNotifier::notify(), GridUnitMovementStopNotifier::notify(), and GridUnitItemDropNotifier::notify().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ inc_size()

void Horizon::Structures::LinkedList::Head::inc_size ( )
inline
88{ ++_size; }

References _size.

◆ is_empty()

bool Horizon::Structures::LinkedList::Head::is_empty ( ) const
inline

Returns true if the list is empty.

Returns
True if the list is empty.
43{ return(_first._next == &_last); }

References _first, _last, and Horizon::Structures::LinkedList::Element::_next.

Referenced by first(), and last().

+ Here is the caller graph for this function:

◆ last() [1/2]

Element * Horizon::Structures::LinkedList::Head::last ( )
inline

Returns the last Element in the list.

50{ return(is_empty() ? nullptr : _last._prev); }

References _last, Horizon::Structures::LinkedList::Element::_prev, and is_empty().

Referenced by BOOST_AUTO_TEST_CASE().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ last() [2/2]

Element const * Horizon::Structures::LinkedList::Head::last ( ) const
inline
51{ return(is_empty() ? nullptr : _last._prev); }

References _last, Horizon::Structures::LinkedList::Element::_prev, and is_empty().

+ Here is the call graph for this function:

◆ operator=()

Head & Horizon::Structures::LinkedList::Head::operator= ( Head const &  )
privatedelete

◆ push_back()

void Horizon::Structures::LinkedList::Head::push_back ( Element pElem)
inline
Parameters
pElemThe Element to add to the list.
Note
The Element must not already be in a list.
64 {
65 _last.push_before(pElem);
66 }
void push_before(Element *pElem)
Pushes this Element before the given Element.
Definition: Element.hpp:64

References _last, and Horizon::Structures::LinkedList::Element::push_before().

+ Here is the call graph for this function:

◆ push_front()

void Horizon::Structures::LinkedList::Head::push_front ( Element pElem)
inline

push_front() and push_back() are used to add an Element to the list.

Parameters
pElemThe Element to add to the list.
Note
The Element must not already be in a list.
57 {
58 _first.push_after(pElem);
59 }
void push_after(Element *pElem)
Pushes this Element after the given Element.
Definition: Element.hpp:75

References _first, and Horizon::Structures::LinkedList::Element::push_after().

Referenced by BOOST_AUTO_TEST_CASE().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

Member Data Documentation

◆ _first

Element Horizon::Structures::LinkedList::Head::_first
private

Referenced by first(), Head(), is_empty(), and push_front().

◆ _last

Element Horizon::Structures::LinkedList::Head::_last
private

Referenced by Head(), is_empty(), last(), and push_back().

◆ _size

uint32_t Horizon::Structures::LinkedList::Head::_size
private

Referenced by dec_size(), get_size(), and inc_size().


The documentation for this class was generated from the following file: