11#ifndef PH_ITEM_LIST_H
22#define PH_ITEM_LIST_H
3+ #include " xrCore/xrDebug_macros.h" // for pragma todo. Remove once resolved.
34/*
4- #define DECLARE_PHLIST_ITEM(class_name) public:\
5+ #define DECLARE_PHLIST_ITEM(class_name) public:\
56 class CPHListItem\
67 {\
78 friend class CPHItemList<class_name>;\
2122 friend class CPHItemStack<class_name>; \
2223 u16 stack_pos;
2324
24- // #define TPI(item) ((T::CPHListItem*)item)
25+ // #define TPI(item) ((T::CPHListItem*)item)
2526
2627template <class T >
2728class CPHItemList
@@ -33,8 +34,7 @@ class CPHItemList
3334 u16 size;
3435
3536public:
36- class iterator ;
37- typedef class iterator
37+ class iterator
3838 {
3939 T* my_ptr;
4040
@@ -49,24 +49,27 @@ class CPHItemList
4949 u16 count () { return size; }
5050 void push_back (T* item)
5151 {
52+ VERIFY2 (size < 65535 , " CPHItemList overflow" );
5253 *(last_tome) = item;
5354 item->tome = last_tome;
5455 last_tome = &((item)->next );
5556 item->next = 0 ;
5657 size++;
5758 }
58- void move_items (CPHItemList<T>& sourse_list )
59+ void move_items (CPHItemList<T>& source_list )
5960 {
60- if (!sourse_list .first_next )
61+ if (!source_list .first_next )
6162 return ;
62- *(last_tome) = sourse_list.first_next ;
63- sourse_list.first_next ->tome = last_tome;
64- last_tome = sourse_list.last_tome ;
65- size = size + sourse_list.size ;
66- sourse_list.empty ();
63+ VERIFY2 (size + source_list.size < 65535 , " CPHItemList overflow" );
64+ *(last_tome) = source_list.first_next ;
65+ source_list.first_next ->tome = last_tome;
66+ last_tome = source_list.last_tome ;
67+ size += source_list.size ;
68+ source_list.empty ();
6769 }
6870 void erase (iterator i)
6971 {
72+ VERIFY2 (size != 0 , " CPHItemList underflow" );
7073 T* item = *i;
7174 T* next = item->next ;
7275 *(item->tome ) = next;
@@ -96,10 +99,11 @@ class CPHItemStack : public CPHItemList<T>
9699 CPHItemList<T>::push_back (item);
97100 }
98101};
99- #define DEFINE_PHITEM_LIST (T, N, I ) \
100- typedef CPHItemList<T> N; \
102+ #define DEFINE_PHITEM_LIST (T, N, I )\
103+ typedef CPHItemList<T> N;\
101104 typedef CPHItemList<T>::iterator I;
102- #define DEFINE_PHITEM_STACK (T, N, I ) \
103- typedef CPHItemStack<T> N; \
105+ #define DEFINE_PHITEM_STACK (T, N, I )\
106+ typedef CPHItemStack<T> N;\
104107 typedef CPHItemStack<T>::iterator I;
105- #endif
108+
109+ #endif // PH_ITEM_LIST_H
0 commit comments