18 #ifndef B2_INTRUSIVE_LIST
19 #define B2_INTRUSIVE_LIST
27 #ifndef B2_INTRUSIVE_LIST_VALIDATE
28 #define B2_INTRUSIVE_LIST_VALIDATE 0
29 #endif // B2_INTRUSIVE_LIST_VALIDATE
71 #if B2_INTRUSIVE_LIST_VALIDATE
73 #endif // B2_INTRUSIVE_LIST_VALIDATE
80 #if B2_INTRUSIVE_LIST_VALIDATE
82 #endif // B2_INTRUSIVE_LIST_VALIDATE
89 node->m_next = m_next;
91 m_next->m_prev = node;
100 node->m_prev = m_prev;
101 m_prev->m_next = node;
114 m_prev->m_next = m_next;
115 m_next->m_prev = m_prev;
138 node != terminator; node = node->
GetNext())
161 #if B2_INTRUSIVE_LIST_VALIDATE
162 if (m_magic != k_magic)
return false;
166 if (node->m_magic != k_magic)
return false;
168 #endif // B2_INTRUSIVE_LIST_VALIDATE
179 if (nodeToFind == node)
return true;
193 #if B2_INTRUSIVE_LIST_VALIDATE
195 #endif // B2_INTRUSIVE_LIST_VALIDATE
202 #if B2_INTRUSIVE_LIST_VALIDATE
203 static const uint32 k_magic = 0x7157ac01;
204 #endif // B2_INTRUSIVE_LIST_VALIDATE
210 #define B2_INTRUSIVE_LIST_GET_NODE(NodeMemberName) \
211 b2IntrusiveListNode* GetListNode() { return &NodeMemberName; } \
212 const b2IntrusiveListNode* GetListNode() const { return &NodeMemberName; }
217 #define B2_INTRUSIVE_LIST_NODE_GET_CLASS_ACCESSOR( \
218 Class, NodeMemberName, FunctionName) \
219 static Class* FunctionName(b2IntrusiveListNode *node) \
225 return reinterpret_cast<Class*>((uint8*)(node) - \
226 (uint8*)(&cls->NodeMemberName)); \
229 static const Class* FunctionName(const b2IntrusiveListNode *node) \
231 return FunctionName(const_cast<b2IntrusiveListNode*>(node)); \
237 #define B2_INTRUSIVE_LIST_NODE_GET_CLASS(Class, NodeMemberName) \
238 B2_INTRUSIVE_LIST_NODE_GET_CLASS_ACCESSOR(Class, NodeMemberName, \
239 GetInstanceFromListNode)
282 GetListNode()->InsertAfter(obj->GetListNode());
289 GetListNode()->InsertBefore(obj->GetListNode());
311 return (T*)GetListNode();
324 return GetListNode()->InList();
330 return GetListNode()->IsEmpty();
336 return GetListNode()->GetLength();
339 B2_INTRUSIVE_LIST_GET_NODE(m_node);
351 return (T*)((uint8*)node - GetNodeOffset(node));
363 int32 nodeOffset = (int32)((uint8*)&obj->m_node - (uint8*)obj);
368 #endif // B2_INTRUSIVE_LIST
T * GetPrevious() const
Definition: b2IntrusiveList.h:301
static T * GetInstanceFromListNode(b2IntrusiveListNode *const node)
Get a pointer to the instance of T that contains "node".
Definition: b2IntrusiveList.h:347
bool ValidateList() const
Definition: b2IntrusiveList.h:159
uint32 GetLength() const
Calculate the length of the list.
Definition: b2IntrusiveList.h:334
b2IntrusiveListNode()
Initialize the node.
Definition: b2IntrusiveList.h:68
b2IntrusiveListNode * Remove()
Remove this node from the list it's currently in.
Definition: b2IntrusiveList.h:112
bool InList() const
Determine whether this object is in a list.
Definition: b2IntrusiveList.h:322
Definition: b2IntrusiveList.h:64
b2IntrusiveListNode * GetPrevious() const
Get the previous node in the list.
Definition: b2IntrusiveList.h:152
T * GetNext() const
Definition: b2IntrusiveList.h:294
uint32 GetLength() const
Calculate the length of the list.
Definition: b2IntrusiveList.h:133
void InsertAfter(T *const obj)
Insert this object after the specified object.
Definition: b2IntrusiveList.h:279
Definition: b2IntrusiveList.h:272
bool FindNodeInList(b2IntrusiveListNode *const nodeToFind) const
Determine whether the specified node is present in this list.
Definition: b2IntrusiveList.h:173
T * Remove()
Remove this object from the list it's currently in.
Definition: b2IntrusiveList.h:315
b2IntrusiveListNode * GetNext() const
Get the next node in the list.
Definition: b2IntrusiveList.h:146
void InsertBefore(T *const obj)
Insert this object before the specified object.
Definition: b2IntrusiveList.h:286
bool InList() const
Determine whether this node is in a list or the list contains nodes.
Definition: b2IntrusiveList.h:127
bool IsEmpty() const
Determine whether this list is empty or the node isn't in a list.
Definition: b2IntrusiveList.h:121
void InsertBefore(b2IntrusiveListNode *const node)
Insert this node before the specified node.
Definition: b2IntrusiveList.h:96
const b2IntrusiveListNode * GetTerminator() const
Get the terminator of the list.
Definition: b2IntrusiveList.h:106
~b2IntrusiveListNode()
If the node is in a list, remove it from the list.
Definition: b2IntrusiveList.h:77
T * GetTerminator() const
Definition: b2IntrusiveList.h:309
void InsertAfter(b2IntrusiveListNode *const node)
Insert this node after the specified node.
Definition: b2IntrusiveList.h:86