Panda3D
|
00001 // Filename: linkedListNode.I 00002 // Created by: drose (16Mar06) 00003 // 00004 //////////////////////////////////////////////////////////////////// 00005 // 00006 // PANDA 3D SOFTWARE 00007 // Copyright (c) Carnegie Mellon University. All rights reserved. 00008 // 00009 // All use of this software is subject to the terms of the revised BSD 00010 // license. You should have received a copy of this license along 00011 // with this source code in a file named "LICENSE." 00012 // 00013 //////////////////////////////////////////////////////////////////// 00014 00015 00016 //////////////////////////////////////////////////////////////////// 00017 // Function: LinkedListNode::Constructor 00018 // Access: Protected 00019 // Description: 00020 //////////////////////////////////////////////////////////////////// 00021 INLINE LinkedListNode:: 00022 LinkedListNode() { 00023 #ifndef NDEBUG 00024 _next = NULL; 00025 _prev = NULL; 00026 #endif 00027 } 00028 00029 //////////////////////////////////////////////////////////////////// 00030 // Function: LinkedListNode::Constructor 2 00031 // Access: Protected 00032 // Description: This constructor should be invoked for any 00033 // LinkedListNodes that will be used to serve as the 00034 // root of a list. It sets up the pointers as an empty 00035 // list. 00036 //////////////////////////////////////////////////////////////////// 00037 INLINE LinkedListNode:: 00038 LinkedListNode(bool) { 00039 _next = this; 00040 _prev = this; 00041 } 00042 00043 //////////////////////////////////////////////////////////////////// 00044 // Function: LinkedListNode::Destructor 00045 // Access: Protected 00046 // Description: 00047 //////////////////////////////////////////////////////////////////// 00048 INLINE LinkedListNode:: 00049 ~LinkedListNode() { 00050 nassertv((_next == NULL && _prev == NULL) || (_next == this && _prev == this)); 00051 } 00052 00053 //////////////////////////////////////////////////////////////////// 00054 // Function: LinkedListNode::is_on_list 00055 // Access: Protected 00056 // Description: Returns true if the node is member of any list, false 00057 // if it has been removed or never added. The head of a 00058 // list generally appears to to always be a member of 00059 // itself. 00060 //////////////////////////////////////////////////////////////////// 00061 INLINE bool LinkedListNode:: 00062 is_on_list() const { 00063 return (_next != NULL); 00064 } 00065 00066 //////////////////////////////////////////////////////////////////// 00067 // Function: LinkedListNode::remove_from_list 00068 // Access: Protected 00069 // Description: Removes a LinkedListNode record from the 00070 // doubly-linked list. 00071 //////////////////////////////////////////////////////////////////// 00072 INLINE void LinkedListNode:: 00073 remove_from_list() { 00074 nassertv(_prev != NULL && _next != NULL); 00075 nassertv(_prev->_next == this && _next->_prev == this); 00076 _prev->_next = _next; 00077 _next->_prev = _prev; 00078 #ifndef NDEBUG 00079 _next = NULL; 00080 _prev = NULL; 00081 #endif 00082 } 00083 00084 //////////////////////////////////////////////////////////////////// 00085 // Function: LinkedListNode::insert_before 00086 // Access: Protected 00087 // Description: Adds a LinkedListNode record before the indicated 00088 // node in the doubly-linked list. 00089 //////////////////////////////////////////////////////////////////// 00090 INLINE void LinkedListNode:: 00091 insert_before(LinkedListNode *node) { 00092 nassertv(node->_prev != NULL && node->_prev->_next == node && node->_next->_prev == node); 00093 nassertv(_prev == (LinkedListNode *)NULL && 00094 _next == (LinkedListNode *)NULL); 00095 _prev = node->_prev; 00096 _next = node; 00097 _prev->_next = this; 00098 node->_prev = this; 00099 } 00100 00101 //////////////////////////////////////////////////////////////////// 00102 // Function: LinkedListNode::insert_after 00103 // Access: Protected 00104 // Description: Adds a LinkedListNode record after the indicated 00105 // node in the doubly-linked list. 00106 //////////////////////////////////////////////////////////////////// 00107 INLINE void LinkedListNode:: 00108 insert_after(LinkedListNode *node) { 00109 nassertv(node->_prev != NULL && node->_prev->_next == node && node->_next->_prev == node); 00110 nassertv(_prev == (LinkedListNode *)NULL && 00111 _next == (LinkedListNode *)NULL); 00112 _next = node->_next; 00113 _prev = node; 00114 _next->_prev = this; 00115 node->_next = this; 00116 } 00117 00118 //////////////////////////////////////////////////////////////////// 00119 // Function: LinkedListNode::take_list_from 00120 // Access: Protected 00121 // Description: Given that this LinkedListNode represents the root of 00122 // a list, and the other pointer represents the root of 00123 // a different list, move all of the nodes (except the 00124 // root itself) from other_root onto this list. 00125 //////////////////////////////////////////////////////////////////// 00126 INLINE void LinkedListNode:: 00127 take_list_from(LinkedListNode *other_root) { 00128 other_root->_next->_prev = _prev; 00129 _prev->_next = other_root->_next; 00130 other_root->_prev->_next = this; 00131 _prev = other_root->_prev; 00132 00133 other_root->_next = other_root; 00134 other_root->_prev = other_root; 00135 }