7 #ifndef __core_List_h__ 8 #define __core_List_h__ 11 #define FE_LIST_REF_DEBUG FALSE 14 #ifndef FE_LIST_STORE_CHECKPOINTER 15 #define FE_LIST_STORE_CHECKPOINTER TRUE 18 #if FE_CODEGEN<=FE_DEBUG && FE_LIST_STORE_CHECKPOINTER 19 #define FE_LIST_CHECKPOINTER TRUE 21 #define FE_LIST_CHECKPOINTER FALSE 58 U32
size(
void)
const {
return m_length; }
66 {
return coreMoveNode(
true,from,to); }
70 {
return coreMoveNode(
false,from,to); }
109 #if FE_LIST_STORE_CHECKPOINTER 110 FE_MAYBE_UNUSED(m_pListCore);
113 setCurrent(operand.m_pCurrent);
121 m_pCurrent->decRef();
140 #if FE_LIST_CHECKPOINTER 165 m_pCurrent->decRef();
168 FEASSERT(set->valid());
191 if(!m_pCurrent || m_pCurrent->valid())
195 NodeCore* heir=m_pCurrent;
196 while(heir && !heir->valid())
200 if(heir && heir->valid())
204 setAtTailNull(
false);
210 setAtTailNull(
false);
214 NodeCore* m_pCurrent;
217 #if FE_LIST_CHECKPOINTER 222 void setCorePointer(
const ListCore *pSet)
231 BWORD checkCorePointer(
const ListCore *pCheck)
const 233 if(pCheck && m_pListCore && m_pListCore!=pCheck)
234 feLog(
"Context::CheckCorePointer" 235 "(%p) does not match %p\n",
237 FEASSERT(!pCheck || !m_pListCore ||
238 m_pListCore==pCheck);
239 return (!pCheck || !m_pListCore ||
240 m_pListCore==pCheck);
243 #if FE_LIST_STORE_CHECKPOINTER 251 class FE_DL_EXPORT NodeCore:
public Counted 263 virtual ~NodeCore(
void) {}
268 void setPrevious(NodeCore*
set) { m_pPrevious=
set; }
272 NodeCore* previous(
void)
const {
return m_pPrevious;}
277 void setNext(NodeCore*
set) { m_pNext=
set; }
281 NodeCore* next(
void)
const {
return m_pNext; }
286 void setHeir(NodeCore*
set) { m_pHeir=
set; }
290 NodeCore* heir(
void)
const {
return m_pHeir; }
295 void setValid(BWORD
set) { m_valid=
set;}
299 BWORD valid(
void)
const {
return m_valid; }
309 const int references=releaseInternal();
310 #if FE_LIST_REF_DEBUG 311 feLog(
"%p Node::Abandon() %d\n",
325 #if FE_LIST_REF_DEBUG 326 feLog(
"%p Node heir=%p\n",
this,m_pHeir);
342 #if FE_LIST_REF_DEBUG 343 const int references=releaseInternal();
344 feLog(
"%p Node::IncRef() %d->%d\n",
345 this,references,references+1);
358 NodeCore* m_pPrevious;
363 NodeCore* coreGetElement(I32 index)
const;
364 NodeCore* coreInsert(BWORD before,
Context& rContext,
365 NodeCore* existingNode);
366 BWORD coreRemoveNode(NodeCore* node);
372 BWORD m_autodestruct;
375 virtual NodeCore* newNode(
void)
const =0;
376 void internalToHead(
Context& rContext)
const;
377 void internalPostIncrement(
Context& rContext)
const;
378 void internalDetachNode(NodeCore* node);
379 NodeCore* internalGetCurrent(
Context& rContext)
const 381 #if FE_LIST_CHECKPOINTER 382 rContext.checkCorePointer(
this);
495 template <
typename T>
500 class FE_DL_EXPORT Node:
public NodeCore
505 m_entry=defaultByType<T>(T());
507 setName(FE_TYPESTRING(T));
508 trackReference(*(
void**)&m_entry,
this,verboseName());
514 untrackReference(*(
void**)&m_entry,
this);
521 void setEntry(T&
set)
524 untrackReference(*(
void**)&m_entry,
this);
525 trackReference(*(
void**)&
set,
this,verboseName());
532 T entry(
void)
const {
return m_entry; }
536 T* storage(
void) {
return &m_entry; }
538 #if FE_COUNTED_STORE_TRACKER 539 const String verboseName(
void)
const 540 {
return "List::Node "+name(); }
547 virtual NodeCore* newNode(
void)
const 549 NodeCore* pNode=
new Node();
551 pNode->trackReference(
552 const_cast<void*>((
const void*)
this),
623 m_pList(rOperand.m_pList) {}
625 { Context::operator=(rOperand);
626 m_pList=rOperand.m_pList;
630 {
return operator*()==rOperand.operator*(); }
633 {
return operator*()!=rOperand.operator*(); }
636 {
return m_pList->current(*
this); }
639 {
return m_pList->current(*
this); }
642 { m_pList->preIncrement(*
this);
646 { m_pList->preDecrement(*
this);
651 m_pList->postIncrement(*
this);
656 m_pList->postDecrement(*
this);
660 T
toHead(
void) {
return m_pList->toHead(*
this); }
662 T
toTail(
void) {
return m_pList->toTail(*
this); }
665 {
return m_pList->isAtHeadNull(*
this); }
668 {
return m_pList->isAtTailNull(*
this); }
671 {
return m_pList->insertBefore(*
this,pEntry); }
674 {
return m_pList->insertAfter(*
this,pEntry); }
678 {
return m_pList->moveNodeBefore(*
this,rOperand); }
682 {
return m_pList->moveNodeAfter(*
this,rOperand); }
685 {
return m_pList->removeCurrent(*
this); }
690 {
return m_pList->replaceCurrent(*
this,pSubstitute); }
693 {
return m_pList->deleteCurrent(*
this); }
697 {
return m_pList->searchForElement(*
this,pEntry); }
701 {
return m_pList->searchForContent(*
this,pValue); }
702 List* list(
void) {
return m_pList; }
711 { Node* pNode=(Node *)coreInsert(
true,rContext,NULL);
712 pNode->setEntry(pEntry);
return pNode->storage(); }
717 { Node* pNode=(Node *)coreInsert(
false,rContext,NULL);
718 pNode->setEntry(pEntry);
return pNode->storage(); }
726 #if FE_LIST_CHECKPOINTER 727 rContext.setCorePointer(
this);
729 Node* pNode=(Node*)coreInsert(
true,rContext,NULL);
732 pNode->setEntry(pEntry);
733 return pNode->storage();
742 #if FE_LIST_CHECKPOINTER 743 rContext.setCorePointer(
this);
745 Node* pNode=(Node*)coreInsert(
false,rContext,NULL);
748 pNode->setEntry(pEntry);
749 return pNode->storage();
767 BWORD
remove(T pEntry)
773 internalToHead(context);
774 while((pNode=(Node*)internalGetCurrent(context)) != NULL
775 && (pEntry2=pNode->entry()) !=
776 defaultByType<T>(T()))
779 return coreRemoveNode(context.
current());
781 internalPostIncrement(context);
793 #if FE_LIST_CHECKPOINTER 794 hint.checkCorePointer(
this);
798 if((pNodeCore=hint.current()))
800 if(((Node*)pNodeCore)->entry()==pEntry)
801 return coreRemoveNode(pNodeCore);
802 else if(pNodeCore->next() &&
803 ((Node*)pNodeCore->next())->entry()==pEntry)
804 return coreRemoveNode(pNodeCore->next());
805 else if(pNodeCore->previous() &&
806 ((Node*)pNodeCore->previous())->entry()==pEntry)
807 return coreRemoveNode(pNodeCore->previous());
810 return remove(pEntry);
817 Node* pNode=(Node*)rContext.
current();
821 T ptr=pNode->entry();
822 BWORD success=coreRemoveNode(pNode);
833 Node* pNode=(Node*)rContext.
current();
836 T pCurrent=pNode->entry();
837 pNode->setEntry(pSubstitute);
840 return defaultByType<T>(T());
850 while( m_pHead != NULL)
852 T pEntry=((Node*)m_pHead)->entry();
853 #if FE_CODEGEN<=FE_DEBUG 856 coreRemoveNode(m_pHead);
859 deleteByType(pEntry);
870 T pEntry=node->entry();
871 BWORD success=coreRemoveNode(node);
874 deleteByType(pEntry);
885 BWORD result=
remove(pEntry);
886 deleteByType(pEntry);
896 #if FE_LIST_CHECKPOINTER 897 rContext.setCorePointer(
this);
899 return current(rContext);
907 #if FE_LIST_CHECKPOINTER 908 rContext.setCorePointer(
this);
910 return current(rContext);
923 internalToHead(rContext);
924 while((pNode=(Node*)internalGetCurrent(rContext)) != NULL
925 && (pEntry2=pNode->entry()) !=
926 defaultByType<T>(T()))
929 return ((Node*)rContext.
current())->storage();
931 internalPostIncrement(rContext);
952 while( (pEntry2=current(rContext)) != NULL)
954 if(*pEntry2==*pValue)
955 return ((Node*)rContext.
current())->storage();
957 postIncrement(rContext);
968 if((pNode=(Node*)rContext.
current())!=NULL)
970 rContext.
setCurrent(pNext=(Node*)pNode->next());
973 return (pNode->entry());
975 else if(!isAtTailNull(rContext))
978 return defaultByType<T>(T());
985 Node* pNode=(Node*)rContext.
current();
991 return pNode->entry();
993 else if(isAtTailNull(rContext))
997 return defaultByType<T>(T());
1003 ((Node*)m_pHead)->entry(): defaultByType<T>(T()); }
1008 ((Node*)m_pTail)->entry(): defaultByType<T>(T()); }
1013 #if FE_LIST_CHECKPOINTER 1014 rContext.checkCorePointer(
this);
1016 Node* pNode=(Node*)rContext.
current();
1017 return pNode? pNode->entry(): defaultByType<T>(T());
1024 { postIncrement(rContext);
1025 return current(rContext); }
1029 { postDecrement(rContext);
1030 return current(rContext); }
1035 { Node* pNode=(Node*)coreGetElement(index);
1036 return pNode? pNode->entry(): defaultByType<T>(T()); }
1041 #endif // __core_List_h__ BWORD removeCurrent(Context &rContext)
Remove the current node on the given context.
Definition: List.h:815
Iterator & operator--(void)
Pre Decrement.
Definition: List.h:645
T toHead(Context &rContext) const
Rewind the context to the beginning of the list and return the first element.
Definition: List.h:893
BWORD autoDestruct(void)
Get the AutoDestruct flag.
Definition: List.h:55
Fully Bidirectional Doubly-Linked List.
Definition: List.h:496
T searchForElement(const T pEntry)
Point the iterator at the first entry with a given pointer.
Definition: List.h:696
BWORD moveNodeAfter(Context &from, Context &to)
Moves the node at the first context after the node at the second context.
Definition: List.h:69
void init(void)
Reinitialize state.
Definition: List.h:136
T * prepend(T pEntry)
Insert a new element at the beginning of the list.
Definition: List.h:722
Context(const Context &operand)
Copy constructor.
Definition: List.h:107
T * append(T pEntry)
Insert a new element at the end of the list.
Definition: List.h:738
T * insertAfter(Context &rContext, T pEntry)
Insert a new element after the context.
Definition: List.h:716
BWORD moveCurrentAfter(const Iterator &rOperand)
Move the entry at this iterator to the position after the argument.
Definition: List.h:681
Context & operator=(Context &operand)
Copy state from another context.
Definition: List.h:125
Heap-based support for classes participating in fe::ptr <>
Definition: Counted.h:35
kernel
Definition: namespace.dox:3
BWORD deleteElement(T pEntry)
Remove and delete the first entry that matches the argument.
Definition: List.h:883
T operator[](I32 index) const
Get an element by index.
Definition: List.h:1034
T operator->(void)
Use the entry pointed at.
Definition: List.h:635
BWORD checkValid(const T &a_value)
Definition: Vector.h:79
T * insertAfter(T pEntry)
Add a new entry directly after this iterator.
Definition: List.h:673
T toTail(Context &rContext) const
Move the context to the end of the list and return the last element.
Definition: List.h:904
void deleteAll(void)
Remove all nodes and delete their pointers.
Definition: List.h:848
void append(List< T > &list)
Append a copy of an entire list of identical type.
Definition: List.h:753
BWORD operator==(const Iterator &rOperand) const
Compare by content (not by pointer)
Definition: List.h:629
NodeCore * current(void)
Get current position on list.
Definition: List.h:148
BWORD moveCurrentBefore(const Iterator &rOperand)
Move the entry at this iterator to the position before the argument.
Definition: List.h:677
T head(void) const
Return the first element of the list (no context required)
Definition: List.h:1001
T searchForContent(const T pValue)
Point the iterator at the first entry equivalent to the given pointed-to value.
Definition: List.h:700
T toHead(void)
Point the iterator at the first entry.
Definition: List.h:660
void setAtTailNull(BWORD set)
Set whether context is after the tail.
Definition: List.h:177
T toTail(void)
Point the iterator at the last entry.
Definition: List.h:662
T tail(void) const
Return the last element of the list (no context required)
Definition: List.h:1006
BWORD isAtTailNull(Context &rContext) const
Returns TRUE if the context is after the last element.
Definition: List.h:77
A view state into an fe::List <>
Definition: List.h:101
T operator*(void)
Return the entry pointed at.
Definition: List.h:638
BWORD deleteCurrent(Context &rContext)
Remove and delete the current node on the given context.
Definition: List.h:864
Iterator & operator++(void)
Pre Increment.
Definition: List.h:641
T * insertBefore(Context &rContext, T pEntry)
Insert a new element before the context.
Definition: List.h:710
void setAutoDestruct(BWORD set)
Set the AutoDestruct flag.
Definition: List.h:52
Automatically reference-counted string container.
Definition: String.h:128
Iterator operator--(int)
Post Decrement.
Definition: List.h:654
T replaceCurrent(Context &rContext, T pSubstitute)
Replace the current pointer on the given context.
Definition: List.h:831
T replace(T pSubstitute)
Replace this entry with a new object.
Definition: List.h:689
Type-nonspecific Base Functionality of fe::List <>
Definition: List.h:40
Type-specific Iterator for an fe::List <>
Definition: List.h:618
T postDecrement(Context &rContext) const
Return the current element before decrementing to the previous.
Definition: List.h:983
T postIncrement(Context &rContext) const
Return the current element before incrementing to the next.
Definition: List.h:964
BWORD isAtTailNull(void) const
Get whether context is after the tail.
Definition: List.h:182
T current(Context &rContext) const
Return the current element of the context.
Definition: List.h:1011
T preIncrement(Context &rContext) const
Increment the context and return the next element.
Definition: List.h:1023
BWORD isAtTailNull(void)
Returns TRUE if pointing to the tail NULL.
Definition: List.h:667
T * searchForContent(Context &rContext, const T pValue) const
Return the location of the first pointed-to element with the same value.
Definition: List.h:944
BWORD operator!=(const Iterator &rOperand) const
Inverse compare by content (not by pointer)
Definition: List.h:632
Iterator operator++(int)
Post Increment.
Definition: List.h:649
void setCurrent(NodeCore *set)
Set current position on list.
Definition: List.h:157
BWORD moveNodeBefore(Context &from, Context &to)
Moves the node at the first context before the node at the second context.
Definition: List.h:65
T * insertBefore(T pEntry)
Add a new entry directly before this iterator.
Definition: List.h:670
U32 size(void) const
Returns the number of elements on the list.
Definition: List.h:58
BWORD deleteEntry(void)
Remove this entry from the list and delete it.
Definition: List.h:692
T preDecrement(Context &rContext) const
Decrement the context and return the previous element.
Definition: List.h:1028
BWORD isAtHeadNull(void)
Returns TRUE if pointing to the head NULL.
Definition: List.h:664
T * searchForElement(Context &rContext, const T pEntry) const
Return the location of the first element matching the given pointer or smart pointer.
Definition: List.h:918
BWORD isAtHeadNull(Context &rContext) const
Returns TRUE if the context is before the first element.
Definition: List.h:73