IntrusiveList.h

Go to the documentation of this file.
00001 /*
00002 // $Id: //open/dev/fennel/common/IntrusiveList.h#10 $
00003 // Fennel is a library of data storage and processing components.
00004 // Copyright (C) 2005-2009 The Eigenbase Project
00005 // Copyright (C) 2005-2009 SQLstream, Inc.
00006 // Copyright (C) 2005-2009 LucidEra, Inc.
00007 // Portions Copyright (C) 1999-2009 John V. Sichi
00008 //
00009 // This program is free software; you can redistribute it and/or modify it
00010 // under the terms of the GNU General Public License as published by the Free
00011 // Software Foundation; either version 2 of the License, or (at your option)
00012 // any later version approved by The Eigenbase Project.
00013 //
00014 // This program is distributed in the hope that it will be useful,
00015 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00016 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00017 // GNU General Public License for more details.
00018 //
00019 // You should have received a copy of the GNU General Public License
00020 // along with this program; if not, write to the Free Software
00021 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00022 */
00023 
00024 #ifndef Fennel_IntrusiveList_Included
00025 #define Fennel_IntrusiveList_Included
00026 
00027 #include "fennel/common/RawIntrusiveList.h"
00028 
00029 FENNEL_BEGIN_NAMESPACE
00030 
00052 template <class T,class DerivedListNode = IntrusiveListNode>
00053 class IntrusiveList : public RawIntrusiveList
00054 {
00055     typedef RawIntrusiveList super;
00056 
00057 public:
00063     void push_front(T &element)
00064     {
00065         super::push_front(static_cast<DerivedListNode &>(element));
00066     }
00067 
00073     void push_back(T &element)
00074     {
00075         super::push_back(static_cast<DerivedListNode &>(element));
00076     }
00077 
00081     T &front() const
00082     {
00083         return static_cast<T &>(
00084             static_cast<DerivedListNode &>(super::front()));
00085     }
00086 
00090     T &back() const
00091     {
00092         return static_cast<T &>(
00093             static_cast<DerivedListNode &>(super::back()));
00094     }
00095 
00103     bool remove(T &element)
00104     {
00105         return super::remove(
00106             static_cast<DerivedListNode &>(element));
00107     }
00108 };
00109 
00113 template <class T,class DerivedListNode = IntrusiveListNode>
00114 class IntrusiveListIter : public RawIntrusiveListIter
00115 {
00116     typedef RawIntrusiveListIter super;
00117 
00118 public:
00122     explicit IntrusiveListIter()
00123     {
00124     }
00125 
00131     explicit IntrusiveListIter(
00132         IntrusiveList<T,DerivedListNode> const &list)
00133         : super(list)
00134     {
00135     }
00136 
00140     T *operator -> () const
00141     {
00142         return static_cast<T *>(
00143             static_cast<DerivedListNode *>(getCurrent()));
00144     }
00145 
00149     operator T * () const
00150     {
00151         return static_cast<T *>(
00152             static_cast<DerivedListNode *>(getCurrent()));
00153     }
00154 
00158     T & operator * () const
00159     {
00160         return *static_cast<T *>(
00161             static_cast<DerivedListNode *>(getCurrent()));
00162     }
00163 
00169     void repositionToFront(
00170         IntrusiveList<T,DerivedListNode> const &list)
00171     {
00172         super::repositionToFront(list);
00173     }
00174 };
00175 
00180 template <class T,class DerivedListNode = IntrusiveListNode>
00181 class IntrusiveListMutator
00182     : public RawIntrusiveListMutator
00183 {
00184     typedef RawIntrusiveListMutator super;
00185 
00186 public:
00190     explicit IntrusiveListMutator()
00191     {
00192     }
00193 
00199     explicit IntrusiveListMutator(
00200         IntrusiveList<T,DerivedListNode> &list)
00201         : super(list)
00202     {
00203     }
00204 
00208     T *operator -> () const
00209     {
00210         return static_cast<T *>(
00211             static_cast<DerivedListNode *>(getCurrent()));
00212     }
00213 
00217     operator T * () const
00218     {
00219         return static_cast<T *>(
00220             static_cast<DerivedListNode *>(getCurrent()));
00221     }
00222 
00226     T & operator * () const
00227     {
00228         return *static_cast<T *>(
00229             static_cast<DerivedListNode *>(getCurrent()));
00230     }
00231 
00238     T *detach()
00239     {
00240         return static_cast<T *>(
00241             static_cast<DerivedListNode *>(super::detach()));
00242     }
00243 
00249     void repositionToFront(
00250         IntrusiveList<T,DerivedListNode> &list)
00251     {
00252         super::repositionToFront(list);
00253     }
00254 
00258     void repositionToFront()
00259     {
00260         super::repositionToFront();
00261     }
00262 };
00263 
00264 FENNEL_END_NAMESPACE
00265 
00266 #endif
00267 
00268 // End IntrusiveList.h

Generated on Mon Jun 22 04:00:18 2009 for Fennel by  doxygen 1.5.1