Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Auto List
- // 11.11.2015 12:50
- enum AListOpt{ AListCon = 1, AListDes = 2, AListClear = 4 };
- template<class T/*, int OT = AListCon | AListDes | AListClear*/>
- class AListAllocDef{
- //int opt;
- public:
- AListAllocDef(){
- //opt = OT;
- }
- T* AllocNew(){
- T* t = (T*)malloc(sizeof(T));
- //if(OT & AListCon)
- new(t)T;
- //else
- memset(t, 0, sizeof(T));
- return T;
- }
- void AllocDel(T *t){
- //if(OT & AListDes)
- t->~T();
- free(t);
- return ;
- }
- };
- template<class TAlloc, class T/*, int OT = AListCon | AListDes | AListClear*/>
- class AList : public TAlloc, public OMatrixT<T>{
- public:
- // Constructor
- AList(){
- }
- ~AList(){
- Clear();
- }
- // Memory operations
- T* New(){
- T *t = AllocNew();
- OMAdd(t);
- return t;
- }
- void Del(T *t){
- OMDel(t);
- return AllocDel(t);
- }
- // Get
- T* GetFirst(){
- return _a;
- }
- T* GetLast(){
- return _e;
- }
- void Clear(){
- T *t = _a, *d = t;
- while(t){
- t = t->_n;
- Del(d);
- }
- return ;
- }
- };
- class TestAList{
- public:
- TestAList * _p, *_n;
- int i;
- };
- AList<AListAllocDef<TestAList>, TestAList> testalist;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement