Advertisement
Guest User

MikelSV AutoList

a guest
Nov 11th, 2015
148
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.14 KB | None | 0 0
  1. // Auto List
  2. // 11.11.2015 12:50
  3.  
  4. enum AListOpt{ AListCon = 1, AListDes = 2, AListClear = 4 };
  5.  
  6. template<class T/*, int OT = AListCon | AListDes | AListClear*/>
  7. class AListAllocDef{
  8.     //int opt;
  9.  
  10. public:
  11.     AListAllocDef(){
  12.         //opt = OT;
  13.     }
  14.  
  15.     T* AllocNew(){
  16.         T* t = (T*)malloc(sizeof(T));
  17.         //if(OT & AListCon)
  18.             new(t)T;
  19.         //else
  20.             memset(t, 0, sizeof(T));
  21.  
  22.         return T;
  23.     }
  24.  
  25.     void AllocDel(T *t){
  26.         //if(OT & AListDes)
  27.             t->~T();
  28.         free(t);
  29.         return ;
  30.     }
  31.  
  32. };
  33.  
  34. template<class TAlloc, class T/*, int OT = AListCon | AListDes | AListClear*/>
  35. class AList : public TAlloc, public OMatrixT<T>{
  36.  
  37. public:
  38.     // Constructor
  39.     AList(){
  40.  
  41.     }
  42.  
  43.     ~AList(){
  44.         Clear();
  45.     }
  46.  
  47.     // Memory operations
  48.     T* New(){
  49.         T *t = AllocNew();
  50.         OMAdd(t);
  51.         return t;
  52.     }
  53.  
  54.     void Del(T *t){
  55.         OMDel(t);
  56.         return AllocDel(t);
  57.     }
  58.  
  59.     // Get
  60.     T* GetFirst(){
  61.         return _a;
  62.     }
  63.  
  64.     T* GetLast(){
  65.         return _e;
  66.     }
  67.  
  68.     void Clear(){
  69.         T *t = _a, *d = t;
  70.  
  71.         while(t){
  72.             t = t->_n;
  73.             Del(d);
  74.         }
  75.  
  76.         return ;
  77.     }
  78. };
  79.  
  80.  
  81.  
  82. class TestAList{
  83. public:
  84.     TestAList * _p, *_n;
  85.  
  86.     int i;
  87. };
  88.  
  89.  
  90. AList<AListAllocDef<TestAList>, TestAList> testalist;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement