original 1.0.1 release
[xwelltris.git] / src / include / bilist.h
blob789050705956891f3a348d2906797c3944bf6923
1 #ifndef BILIST_H
2 #define BILIST_H
4 template < class TC > class bilist
6 TC object;
7 bool usable;
8 bilist<TC> *next,*prev;
9 public:
10 bilist<TC>() { next=prev=0;usable=false;};
11 bilist<TC>(TC& obj) { next=prev=0;object=obj;usable=true;};
13 bool add(bilist<TC> *plist);
14 bilist<TC>* del(TC& obj);
15 bool del_self()
17 if(next)
18 next->set_prev(prev);
19 if(prev)
20 prev->set_next(next);
21 return true;
24 bool is_last() {return next==0;};
25 bool is_first() {return prev==0;};
27 bilist<TC> *get_next() { return next;};
28 bilist<TC> *get_prev() { return prev;};
30 void set_prev(bilist<TC> *plist) { prev=plist;};
31 void set_next(bilist<TC> *plist) { next=plist;};
33 TC& get_object() { return object;};
36 //here we are using while for searching end of list
37 template <class TC> bool bilist<TC>::add(bilist<TC> *plist)
39 bilist<TC> *ptr=this;
40 while(ptr->get_next()!=0)
41 ptr=ptr->get_next();
42 ptr->set_next(plist);
43 plist->set_prev(ptr);
44 return true;
47 //and here lets make recursion for diff :)
48 template <class TC> bilist<TC>* bilist<TC>::del(TC& obj)
50 if(obj==object)
52 del_self();
53 return this;
55 if(next)
56 return next->del(obj);
57 return 0; //Can't find object in list.
60 #endif