1 /* 2 * PROPRIETARY INFORMATION. This software is proprietary to POWDER 3 * Development, and is not to be reproduced, transmitted, or disclosed 4 * in any way without written permission. 5 * 6 * Produced by: Jeff Lait 7 * 8 * POWDER Development 9 * 10 * NAME: itemstack.h ( POWDER Library, C++ ) 11 * 12 * COMMENTS: 13 * This provides a method to get a stack of items, 14 * for example, all the items at a given square. 15 * It avoids dynamic allocation up to the minsize, 16 * but will happily transparently go to dynamic allocation 17 * where necessary. 18 */ 19 20 #ifndef __itemstack_h__ 21 #define __itemstack_h__ 22 23 class ITEM; 24 class MOB; 25 26 #define PTRSTACK_MINSIZE 20 27 28 template <typename PTR> 29 class PTRSTACK 30 { 31 public: 32 PTRSTACK(); 33 ~PTRSTACK(); 34 35 void append(PTR item); 36 37 // Reverses the order of the stack. 38 void reverse(); 39 40 // Empties the stack 41 void clear(); 42 43 // Collapses all entries that evaluate ! as true (ie, zero) 44 void collapse(); 45 46 PTR operator()(int idx) const; 47 int entries() const; 48 49 void set(int idx, PTR item); 50 51 void setEntries(int entries); 52 53 private: 54 PTR *myExtraList; 55 int myEntries; 56 int myExtraSize; 57 PTR myLocal[PTRSTACK_MINSIZE]; 58 }; 59 60 typedef PTRSTACK<ITEM *> ITEMSTACK; 61 typedef PTRSTACK<MOB *> MOBSTACK; 62 63 // For crappy platforms: 64 #include "itemstack.cpp" 65 66 #endif 67