lldlinked.h

Go to the documentation of this file.
00001 
00031 #ifndef LL_LLDLINKED_H
00032 #define LL_LLDLINKED_H
00033 
00034 template <class Type> class LLDLinked
00035 {
00036         LLDLinked* mNextp;
00037         LLDLinked* mPrevp;
00038 public:
00039 
00040         Type*   getNext()  { return (Type*)mNextp; }
00041         Type*   getPrev()  { return (Type*)mPrevp; }
00042         Type*   getFirst() { return (Type*)mNextp; }
00043 
00044         void    init()
00045         {
00046                 mNextp = mPrevp = NULL;
00047         }
00048 
00049         void    unlink()
00050         {
00051                 if (mPrevp) mPrevp->mNextp = mNextp;
00052                 if (mNextp) mNextp->mPrevp = mPrevp;
00053         }
00054 
00055          LLDLinked() { mNextp = mPrevp = NULL; }
00056         virtual ~LLDLinked() { unlink(); }
00057 
00058         virtual void    deleteAll()
00059         {
00060                 Type *curp = getFirst();
00061                 while(curp)
00062                 {
00063                         Type *nextp = curp->getNext();
00064                         curp->unlink();
00065                         delete curp;
00066                         curp = nextp;
00067                 }
00068         }
00069 
00070         void relink(Type &after)
00071         {
00072                 LLDLinked *afterp = (LLDLinked*)&after;
00073                 afterp->mPrevp = this;
00074                 mNextp = afterp;
00075         }
00076 
00077         virtual void    append(Type& after)
00078         {
00079                 LLDLinked *afterp = (LLDLinked*)&after;
00080                 afterp->mPrevp    = this;
00081                 afterp->mNextp    = mNextp;
00082                 if (mNextp) mNextp->mPrevp = afterp;
00083                 mNextp            = afterp;
00084         }
00085 
00086         virtual void    insert(Type& before)
00087         {
00088                 LLDLinked *beforep = (LLDLinked*)&before;
00089                 beforep->mNextp    = this;
00090                 beforep->mPrevp    = mPrevp;
00091                 if (mPrevp) mPrevp->mNextp = beforep;
00092                 mPrevp             = beforep;
00093         }
00094 
00095         virtual void    put(Type& obj) { append(obj); }
00096 };
00097 
00098 #endif

Generated on Thu Jul 1 06:08:24 2010 for Second Life Viewer by  doxygen 1.4.7