00001 /* 00002 FALCON - The Falcon Programming Language. 00003 FILE: ltree.h 00004 00005 Inlined tree linked list templates. 00006 ------------------------------------------------------------------- 00007 Author: Giancarlo Niccolai 00008 Begin: Sat Feb 26 08:45:59 CET 2005 00009 00010 ------------------------------------------------------------------- 00011 (C) Copyright 2004: the FALCON developers (see list in AUTHORS file) 00012 00013 See LICENSE file for licensing details. 00014 */ 00015 00020 #ifndef FLC_LTREE_H 00021 #define FLC_LTREE_H 00022 00023 #include <falcon/setup.h> 00024 #include <falcon/types.h> 00025 #include <falcon/basealloc.h> 00026 00027 namespace Falcon { 00028 00029 class StrongList; 00030 00033 class FALCON_DYN_CLASS SLElement: public BaseAlloc 00034 { 00035 SLElement *m_next; 00036 SLElement *m_prev; 00037 StrongList *m_parent; 00038 00039 public: 00040 00041 SLElement( SLElement *prev=0, SLElement *next=0 ): 00042 m_next( next ), 00043 m_prev( prev ), 00044 m_parent(0) 00045 {} 00046 00047 SLElement( StrongList *parent, SLElement *prev=0, SLElement *next=0 ): 00048 m_next( next ), 00049 m_prev( prev ), 00050 m_parent(parent) 00051 {} 00052 00053 SLElement *next() const { return m_next; } 00054 void next( SLElement *n ) { m_next = n; } 00055 SLElement *prev() const { return m_prev; } 00056 void prev( SLElement *p ) { m_prev = p; } 00057 00058 StrongList *owner() const { return m_parent; } 00059 void owner( StrongList *lt ) { m_parent = lt; } 00060 00061 void remove(); 00062 }; 00063 00067 class FALCON_DYN_CLASS StrongList: public BaseAlloc 00068 { 00069 SLElement *m_head; 00070 SLElement *m_tail; 00071 uint32 m_size; 00072 00073 public: 00074 StrongList(): 00075 m_head(0), 00076 m_tail(0), 00077 m_size(0) 00078 {} 00079 00080 void push_front( SLElement *e ); 00081 00082 void push_back( SLElement *e ); 00083 00084 SLElement *front() const { return m_head; } 00085 SLElement *back() const { return m_tail; } 00086 00087 SLElement *pop_front(); 00088 SLElement *pop_back(); 00089 void remove( SLElement *e ); 00090 00091 uint32 size() const { return m_size; } 00092 bool empty() const { return m_size == 0; } 00093 }; 00094 00095 inline void SLElement::remove() { 00096 if (m_parent!=0) 00097 m_parent->remove( this ); 00098 } 00099 00100 } 00101 00102 #endif 00103 00104 /* end of llist.h */