src/hbservers/hbthemeserver/hbdoublelinkedlistinline_p.h
changeset 0 16d8024aca5e
equal deleted inserted replaced
-1:000000000000 0:16d8024aca5e
       
     1 /****************************************************************************
       
     2 **
       
     3 ** Copyright (C) 2008-2010 Nokia Corporation and/or its subsidiary(-ies).
       
     4 ** All rights reserved.
       
     5 ** Contact: Nokia Corporation (developer.feedback@nokia.com)
       
     6 **
       
     7 ** This file is part of the HbServers module of the UI Extensions for Mobile.
       
     8 **
       
     9 ** GNU Lesser General Public License Usage
       
    10 ** This file may be used under the terms of the GNU Lesser General Public
       
    11 ** License version 2.1 as published by the Free Software Foundation and
       
    12 ** appearing in the file LICENSE.LGPL included in the packaging of this file.
       
    13 ** Please review the following information to ensure the GNU Lesser General
       
    14 ** Public License version 2.1 requirements will be met:
       
    15 ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
       
    16 **
       
    17 ** In addition, as a special exception, Nokia gives you certain additional
       
    18 ** rights.  These rights are described in the Nokia Qt LGPL Exception
       
    19 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
       
    20 **
       
    21 ** If you have questions regarding the use of this file, please contact
       
    22 ** Nokia at developer.feedback@nokia.com.
       
    23 **
       
    24 ****************************************************************************/
       
    25 
       
    26 #ifndef HBDOUBLELINKEDLIST_INLINE_P_H
       
    27 #define HBDOUBLELINKEDLIST_INLINE_P_H
       
    28 
       
    29 /*!
       
    30     @hbserver
       
    31     \class HbDLink
       
    32     \brief HbDLink implements a linkage linkage in a doubly-linked list
       
    33 
       
    34 */
       
    35 
       
    36 template<class ElemType> inline
       
    37 HbDLink<ElemType>::HbDLink()
       
    38         : mNext(0), mPrev(0)
       
    39 {
       
    40 }
       
    41 
       
    42 template<class ElemType> inline
       
    43 ElemType*
       
    44 HbDLink<ElemType>::next() const
       
    45 {
       
    46     return mNext;
       
    47 }
       
    48 
       
    49 template<class ElemType> inline
       
    50 ElemType*
       
    51 HbDLink<ElemType>::prev() const
       
    52 {
       
    53     return mPrev;
       
    54 }
       
    55 
       
    56 template<class ElemType> inline
       
    57 void
       
    58 HbDLink<ElemType>::setNext(ElemType *element)
       
    59 {
       
    60     mNext = element;
       
    61 }
       
    62 
       
    63 template<class ElemType> inline
       
    64 void
       
    65 HbDLink<ElemType>::setPrev(ElemType *element)
       
    66 {
       
    67     mPrev = element;
       
    68 }
       
    69 
       
    70 /*!
       
    71     @hbserver
       
    72     \class HbDLinkList
       
    73     \brief HbDLinkList implements a generic doubly link list of ElemType.
       
    74 
       
    75     HbDlinkList class use for List Recently Used policy implementation.
       
    76 */
       
    77 
       
    78 
       
    79 /*!
       
    80     \fn HbDLinkList::HbDLinkList()
       
    81     Constructor
       
    82     Constructs a HbDLinkList obect
       
    83     \a dLink ia a pointer to HbDLink member of ElemType to use for this list.
       
    84  */
       
    85 template<class ElemType> inline
       
    86 HbDLinkList<ElemType>::HbDLinkList(HbDLink<ElemType> ElemType:: *dLink)
       
    87         : listFront(0), listBack(0), mDLink(dLink)
       
    88 {
       
    89 
       
    90 }
       
    91 
       
    92 /*!
       
    93     \fn HbDLinkList::~HbDLinkList()
       
    94     Destructor
       
    95 
       
    96  */
       
    97 template<class ElemType> inline
       
    98 HbDLinkList<ElemType>::~HbDLinkList()
       
    99 {
       
   100     // remove links before remove.
       
   101     if ((listFront != 0) || (listBack != 0)) {
       
   102         removeAll();
       
   103     }
       
   104 }
       
   105 
       
   106 /*!
       
   107     \fn HbDLinkList::insertBack()
       
   108     insert a node after the last node
       
   109     \a newItem denotes the item to be inserted after the last node
       
   110  */
       
   111 template<class ElemType> inline
       
   112 void
       
   113 HbDLinkList<ElemType>::insertBack(ElemType* newItem)
       
   114 {
       
   115     if (newItem == 0) {
       
   116         return;
       
   117     }
       
   118     if (listBack == 0) {
       
   119         insertFrontIfListEmpty(newItem);
       
   120     } else {
       
   121         insertAfter(newItem, listBack);
       
   122     }
       
   123 }
       
   124 
       
   125 /*!
       
   126     \fn HbDLinkList::removeFront()
       
   127     remove the front node
       
   128  */
       
   129 template<class ElemType> inline
       
   130 ElemType*
       
   131 HbDLinkList<ElemType>::removeFront()
       
   132 {
       
   133     ElemType* itemToRemove = listFront;
       
   134     if (itemToRemove != 0) {
       
   135         removeNode(itemToRemove);
       
   136     } else {
       
   137         return 0;
       
   138     }
       
   139     return itemToRemove;
       
   140 }
       
   141 
       
   142 /*!
       
   143     \fn HbDLinkList::removeNode()
       
   144     remove a particular node
       
   145     /a itemToRemove denotesthe cache item to be removed from the list
       
   146  */
       
   147 template<class ElemType> inline
       
   148 void
       
   149 HbDLinkList<ElemType>::removeNode(ElemType* itemToRemove)
       
   150 {
       
   151     if (!itemToRemove) {
       
   152         return;
       
   153     }
       
   154 
       
   155     if (itemToRemove == listFront) {
       
   156         listFront = (listFront->*mDLink).next();
       
   157         if (listFront) {
       
   158             (listFront->*mDLink).mPrev = 0;
       
   159         } else {
       
   160             listBack = 0;
       
   161         }
       
   162     } else if (itemToRemove == listBack) {
       
   163         listBack = (listBack->*mDLink).prev();
       
   164         if (listBack) {
       
   165             (listBack->*mDLink).mNext = 0;
       
   166         }
       
   167     } else {
       
   168         ((itemToRemove->*mDLink).prev()->*mDLink).mNext = (itemToRemove->*mDLink).next();
       
   169         ((itemToRemove->*mDLink).next()->*mDLink).mPrev = (itemToRemove->*mDLink).prev();
       
   170     }
       
   171     (itemToRemove->*mDLink).mNext = 0;
       
   172     (itemToRemove->*mDLink).mPrev = 0;
       
   173 }
       
   174 
       
   175 /*!
       
   176     \fn HbDLinkList::removeAll()
       
   177     remove all the items in the list.
       
   178  */
       
   179 template<class ElemType> inline
       
   180 void
       
   181 HbDLinkList<ElemType>::removeAll()
       
   182 {
       
   183     while (listFront) {
       
   184         removeFront();
       
   185     }
       
   186 }
       
   187 
       
   188 /*!
       
   189     \fn HbDLinkList::isEmpty()
       
   190     Check if list is empty
       
   191  */
       
   192 template<class ElemType> inline
       
   193 bool
       
   194 HbDLinkList<ElemType>::isEmpty() const
       
   195 {
       
   196     if (listFront != 0)
       
   197         return false;
       
   198     else
       
   199         return true;
       
   200 }
       
   201 
       
   202 /*!
       
   203     \fn HbDLinkList::front()
       
   204     Return the node at the front of list
       
   205  */
       
   206 template<class ElemType> inline
       
   207 ElemType*
       
   208 HbDLinkList<ElemType>:: front() const
       
   209 {
       
   210     return listFront;
       
   211 }
       
   212 
       
   213 /*!
       
   214     \fn HbDLinkList::front()
       
   215     Return the last node in the list
       
   216  */
       
   217 template<class ElemType> inline
       
   218 ElemType*
       
   219 HbDLinkList<ElemType>:: back() const
       
   220 {
       
   221     return listBack;
       
   222 }
       
   223 
       
   224 /*!
       
   225     \fn HbDLinkList::insertFrontIfListEmpty()
       
   226     This is a private function. We are only interested in inserting at the back of list.
       
   227     However, when a list is empty both front and back point to the same item.
       
   228     \a newItem denotes the cache item to be inserted at the front of the list
       
   229  */
       
   230 template<class ElemType> inline
       
   231 void
       
   232 HbDLinkList<ElemType>::insertFrontIfListEmpty(ElemType* newItem)
       
   233 {
       
   234     if (listFront == 0) {
       
   235         listFront = newItem;
       
   236         listBack = newItem;
       
   237     }
       
   238 }
       
   239 
       
   240 /*!
       
   241     \fn HbDLinkList::insertAfter()
       
   242     insert a node after a given node
       
   243     \a newItem denotes the new cache item to be inserted
       
   244     \a lastItem denotes the cache item after which the new item is to be inserted
       
   245  */
       
   246 template<class ElemType> inline
       
   247 void
       
   248 HbDLinkList<ElemType>::insertAfter(ElemType *newItem, ElemType *lastItem)
       
   249 {
       
   250     (newItem->*mDLink).mNext = (lastItem->*mDLink).next() ;
       
   251     (newItem->*mDLink).mPrev = lastItem;
       
   252 
       
   253     if ((lastItem->*mDLink).next() == 0) {
       
   254         listBack = newItem;
       
   255     } else {
       
   256         ((lastItem->*mDLink).mNext->*mDLink).mPrev = newItem;
       
   257     }
       
   258     (lastItem->*mDLink).mNext = newItem;
       
   259 }
       
   260 
       
   261 #endif
       
   262