00001 #ifndef __FTList__ 00002 #define __FTList__ 00003 00004 #include "FTGL.h" 00005 00009 template <typename FT_LIST_ITEM_TYPE> 00010 class FTGL_EXPORT FTList 00011 { 00012 public: 00013 typedef FT_LIST_ITEM_TYPE value_type; 00014 typedef value_type& reference; 00015 typedef const value_type& const_reference; 00016 typedef size_t size_type; 00017 00021 FTList() 00022 : listSize(0), 00023 tail(0) 00024 { 00025 tail = NULL; 00026 head = new Node; 00027 } 00028 00032 ~FTList() 00033 { 00034 Node* next; 00035 00036 for( Node *walk = head; walk; walk = next) 00037 { 00038 next = walk->next; 00039 delete walk; 00040 } 00041 } 00042 00046 size_type size() const 00047 { 00048 return listSize; 00049 } 00050 00054 void push_back( const value_type& item) 00055 { 00056 Node* node = new Node( item); 00057 00058 if( head->next == NULL) 00059 { 00060 head->next = node; 00061 } 00062 00063 if( tail) 00064 { 00065 tail->next = node; 00066 } 00067 tail = node; 00068 ++listSize; 00069 } 00070 00074 reference front() const 00075 { 00076 return head->next->payload; 00077 } 00078 00082 reference back() const 00083 { 00084 return tail->payload; 00085 } 00086 00087 private: 00088 struct Node 00089 { 00090 Node() 00091 : next(NULL) 00092 {} 00093 00094 Node( const value_type& item) 00095 : next(NULL) 00096 { 00097 payload = item; 00098 } 00099 00100 Node* next; 00101 00102 value_type payload; 00103 }; 00104 00105 size_type listSize; 00106 00107 Node* head; 00108 Node* tail; 00109 }; 00110 00111 #endif // __FTList__ 00112