Fixed memory leak of _ListViewModel
authorHyeonmi Kim <hm_85.kim@samsung.com>
Thu, 28 Mar 2013 05:08:13 +0000 (14:08 +0900)
committerHyeonmi Kim <hm_85.kim@samsung.com>
Thu, 28 Mar 2013 05:08:13 +0000 (14:08 +0900)
Change-Id: I63ca78e3b111248dee68d6fce3826626df63880e
Signed-off-by: Hyeonmi Kim <hm_85.kim@samsung.com>
src/ui/controls/FUiCtrl_ListViewModel.cpp
src/ui/inc/FUiCtrl_LinkedList.h
src/ui/inc/FUiCtrl_ListViewModel.h

index 61c4c46..1caf98e 100644 (file)
@@ -61,17 +61,17 @@ _ListViewModel::~_ListViewModel(void)
                __pTemporaryItemBuffer = null;
        }
 
-       if (__backupGroupNodes.empty() == false)
+       if (!__backupGroupNodes.empty())
        {
                _ListViewGroupNode* pBackupedListGroupNode = null;
-               for (int i = 0; i < __backupGroupNodes.size(); i++)
+               int count = __backupGroupNodes.size();
+               for (int i = 0; i < count; i++)
                {
-                       pBackupedListGroupNode = __backupGroupNodes.at(i);
+                       pBackupedListGroupNode = __backupGroupNodes.back();
+                       __backupGroupNodes.pop_back();
 
                        delete pBackupedListGroupNode;
                }
-
-               __backupGroupNodes.clear();
        }
 
        DeleteAllGroupAndItem();
@@ -178,13 +178,14 @@ _ListViewModel::GetItemFromContainer(int groupIndex, int itemIndex) const
        SysTryReturn(NID_UI_CTRL, pListGroupNode != null, null, GetLastResult(),
                                 "[%s] Propagating.", GetErrorMessage(GetLastResult()));
 
-       _LinkedList <_IListItemCommon*>::_Iterator theIter = pListGroupNode->__items.begin();
-
-       _IListItemCommon* pItem = null;
        int temporaryGroupIndex = -1;
        int temporaryItemIndex = -1;
 
-       while (theIter != pListGroupNode->__items.end())
+       _IListItemCommon* pItem = null;
+       _LinkedList <_IListItemCommon*>::_Iterator theIter = pListGroupNode->__items.begin();
+       _LinkedList <_IListItemCommon*>::_Iterator theEndIter = pListGroupNode->__items.end();
+
+       while (theIter != theEndIter)
        {
                pItem = *theIter;
                pItem->GetItemIndex(temporaryGroupIndex, temporaryItemIndex);
@@ -227,28 +228,19 @@ _ListViewModel::LoadItem(int groupIndex, int itemIndex)
                return null;
        }
 
-       // if loaded item, call GetItemFromContainer()
-       if (IsLoadedItem(groupIndex, itemIndex) == true)
-       {
-               return GetItemFromContainer(groupIndex, itemIndex);
-       }
-
-       _IListItemCommon* pItemCommon = __pListProviderAdaptor->LoadItem(groupIndex, itemIndex);
-       if (pItemCommon != null)
+       // load item
+       _IListItemCommon* pItemCommon = GetItemFromContainer(groupIndex, itemIndex);
+       if (pItemCommon == null)
        {
-               if (IsItemChecked(groupIndex, itemIndex) == true)
+               pItemCommon = __pListProviderAdaptor->LoadItem(groupIndex, itemIndex);
+               if (pItemCommon != null)
                {
-                       pItemCommon->SetChecked(true);
-               }
+                       pItemCommon->SetChecked(IsItemChecked(groupIndex, itemIndex));
+                       pItemCommon->SetItemEnabled(IsItemEnabled(groupIndex, itemIndex));
+                       pItemCommon->SetItemIndex(groupIndex, itemIndex);
 
-               if (IsItemEnabled(groupIndex, itemIndex) == false)
-               {
-                       pItemCommon->SetItemEnabled(false);
+                       LoadItemToContainer(groupIndex, itemIndex, *pItemCommon);
                }
-
-               // push item to container
-               pItemCommon->SetItemIndex(groupIndex, itemIndex);
-               LoadItemToContainer(groupIndex, itemIndex, *pItemCommon);
        }
 
        return pItemCommon;
@@ -257,19 +249,14 @@ _ListViewModel::LoadItem(int groupIndex, int itemIndex)
 result
 _ListViewModel::LoadItemToContainer(int groupIndex, int itemIndex, _IListItemCommon& item)
 {
-       _ListViewGroupNode* pListGroupNode = GetGroupNode(groupIndex);
+       _ListViewGroupNode* pListGroupNode = __groupNodes.at(groupIndex);
        SysTryReturn(NID_UI_CTRL, pListGroupNode != null, GetLastResult(), GetLastResult(),
                                 "[%s] Propagating.", GetErrorMessage(GetLastResult()));
 
-       _LinkedList <_IListItemCommon*>::_Iterator theIter = pListGroupNode->__items.begin();
-
-       _IListItemCommon* pItem = null;
-       int temporaryGroupIndex = -1;
-       int temporaryItemIndex = -1;
        int overCount = 0;
        bool pushToTopOrMiddle = true;
 
-       if (pListGroupNode->__items.empty() == true)
+       if (pListGroupNode->__items.empty())
        {
                int loadedGroups = GetAllGroupCount();
                _ListViewGroupNode* pTemporaryGroupNode = null;
@@ -295,7 +282,12 @@ _ListViewModel::LoadItemToContainer(int groupIndex, int itemIndex, _IListItemCom
        }
        else
        {
-               while (theIter != pListGroupNode->__items.end())
+               int temporaryGroupIndex = -1;
+               int temporaryItemIndex = -1;
+               _IListItemCommon* pItem = null;
+               _LinkedList <_IListItemCommon*>::_Iterator theIter = pListGroupNode->__items.begin();
+               _LinkedList <_IListItemCommon*>::_Iterator theEndIter = pListGroupNode->__items.end();
+               while (theIter != theEndIter)
                {
                        pItem = *theIter;
                        pItem->GetItemIndex(temporaryGroupIndex, temporaryItemIndex);
@@ -317,25 +309,19 @@ _ListViewModel::LoadItemToContainer(int groupIndex, int itemIndex, _IListItemCom
 
                                return E_SUCCESS;
                        }
+                       ++theIter;
+               }
 
-                       if (pItem == pListGroupNode->__items.back())
-                       {
-                               int lastLoadedItemIndex = -1;
-                               int lastLoadedGroupIndex = -1;
-                               GetLastLoadedItemIndex(lastLoadedGroupIndex,lastLoadedItemIndex);
-                               if (lastLoadedGroupIndex == temporaryGroupIndex && lastLoadedItemIndex == temporaryItemIndex)
-                               {
-                                       pushToTopOrMiddle = false;
-                               }
-                               else
-                               {
-                                       pushToTopOrMiddle = true;
-                               }
-
-                               break;
-                       }
-
-                       theIter++;
+               int lastLoadedItemIndex = -1;
+               int lastLoadedGroupIndex = -1;
+               GetLastLoadedItemIndex(lastLoadedGroupIndex, lastLoadedItemIndex);
+               if (lastLoadedGroupIndex == temporaryGroupIndex && lastLoadedItemIndex == temporaryItemIndex)
+               {
+                       pushToTopOrMiddle = false;
+               }
+               else
+               {
+                       pushToTopOrMiddle = true;
                }
        }
 
@@ -385,12 +371,14 @@ _ListViewModel::IsLoadedItem(int groupIndex, int itemIndex) const
        SysTryReturn(NID_UI_CTRL, (itemIndex < pListGroupNode->__itemCountInGroup), false, E_INVALID_ARG,
                                "[E_INVALID_ARG] Wrong item index(%d).", itemIndex);
 
-       _LinkedList <_IListItemCommon*>::_Iterator theIter = pListGroupNode->__items.begin();
-
-       _IListItemCommon* pItem = null;
        int temporaryGroupIndex = -1;
        int temporaryItemIndex = -1;
-       while (theIter != pListGroupNode->__items.end())
+
+       _IListItemCommon* pItem = null;
+       _LinkedList <_IListItemCommon*>::_Iterator theIter = pListGroupNode->__items.begin();
+       _LinkedList <_IListItemCommon*>::_Iterator theEndIter = pListGroupNode->__items.end();
+
+       while (theIter != theEndIter)
        {
                pItem = *theIter;
                pItem->GetItemIndex(temporaryGroupIndex, temporaryItemIndex);
@@ -440,7 +428,7 @@ _ListViewModel::InsertGroup(int groupIndex, int itemCount, bool usingRadioStyle)
 
        SysTryReturn(NID_UI_CTRL, itemCount >= 0, E_INVALID_ARG, E_INVALID_ARG, "[E_INVALID_ARG] The itemCount is not valid.");
 
-       if (__groupNodes.empty() == true || groupIndex == GetAllGroupCount())
+       if (__groupNodes.empty() || groupIndex == GetAllGroupCount())
        {
                return AddGroup(itemCount);
        }
@@ -489,7 +477,7 @@ _ListViewModel::InsertGroup(int groupIndex, int itemCount, bool usingRadioStyle)
 result
 _ListViewModel::UnloadAllItem(void)
 {
-       if (__groupNodes.empty() == true)
+       if (__groupNodes.empty())
        {
                return E_SUCCESS;
        }
@@ -510,7 +498,7 @@ _ListViewModel::UnloadAllItem(void)
                        itemCount = pListGroupNode->__items.size();
                        for (int j = itemCount - 1; j >= 0; j--)
                        {
-                               pItem = pListGroupNode->__items.at(j);
+                               pItem = pListGroupNode->__items.back();
                                pListGroupNode->__items.pop_back();
 
                                if (pItem != null)
@@ -519,8 +507,6 @@ _ListViewModel::UnloadAllItem(void)
                                        __pListProviderAdaptor->UnloadItem(pItem, groupIndex, itemIndex);
                                }
                        }
-
-                       pListGroupNode->__items.clear();
                }
        }
 
@@ -536,14 +522,20 @@ _ListViewModel::DeleteAllGroupAndItem(void)
 result
 _ListViewModel::RemoveAllItem(bool internalDestroy, bool backupItemStatus)
 {
-       if (__groupNodes.empty() == true)
+       if (__groupNodes.empty())
        {
                return E_SUCCESS;
        }
 
        __onRemovingAllItems = true;
 
-       int groupCount = GetAllGroupCount();
+       _LinkedList <_ListViewGroupNode*> backupGroupNodes;
+       backupGroupNodes = __groupNodes;
+
+       __countOfAllGroups = 0;
+       __countOfAllItems = 0;
+
+       int groupCount = backupGroupNodes.size();
        int itemCount = 0;
 
        _ListViewGroupNode* pListGroupNode = null;
@@ -553,7 +545,7 @@ _ListViewModel::RemoveAllItem(bool internalDestroy, bool backupItemStatus)
        int itemIndex = -1;
        for (int i = groupCount - 1; i >= 0; i--)
        {
-               pListGroupNode = GetGroupNode(i);
+               pListGroupNode = backupGroupNodes.at(i);
 
                if (pListGroupNode != null)
                {
@@ -561,14 +553,14 @@ _ListViewModel::RemoveAllItem(bool internalDestroy, bool backupItemStatus)
 
                        for (int j = itemCount - 1; j >= 0; j--)
                        {
-                               pItem = pListGroupNode->__items.at(j);
+                               pItem = pListGroupNode->__items.back();
                                pListGroupNode->__items.pop_back();
 
                                if (pItem != null)
                                {
                                        pItem->GetItemIndex(groupIndex, itemIndex);
 
-                                       if (internalDestroy == false)
+                                       if (!internalDestroy)
                                        {
                                                __pListProviderAdaptor->UnloadItem(pItem, groupIndex, itemIndex);
                                        }
@@ -579,10 +571,9 @@ _ListViewModel::RemoveAllItem(bool internalDestroy, bool backupItemStatus)
                                }
                        }
 
-                       pListGroupNode->__items.clear();
                        pListGroupNode->__itemCountInGroup = 0;
 
-                       if (backupItemStatus == false)
+                       if (!backupItemStatus)
                        {
                                __groupNodes.remove(pListGroupNode);
                                delete pListGroupNode;
@@ -591,16 +582,9 @@ _ListViewModel::RemoveAllItem(bool internalDestroy, bool backupItemStatus)
                }
        }
 
-       __countOfAllGroups = 0;
-       __countOfAllItems = 0;
-
-       if (backupItemStatus == false)
-       {
-               __groupNodes.clear();
-       }
-       else
+       if (backupItemStatus)
        {
-               __backupGroupNodes = __groupNodes;
+               __backupGroupNodes = backupGroupNodes;
        }
 
        __onRemovingAllItems = false;
@@ -610,7 +594,7 @@ _ListViewModel::RemoveAllItem(bool internalDestroy, bool backupItemStatus)
 void
 _ListViewModel::RestoreItemStatus(void)
 {
-       if (__backupGroupNodes.empty() == true)
+       if (__backupGroupNodes.empty())
        {
                return;
        }
@@ -644,22 +628,18 @@ _ListViewModel::UnloadItem(int groupIndex, int itemIndex)
        SysTryReturn(NID_UI_CTRL, (groupIndex >= 0 && groupIndex < __countOfAllGroups), E_INVALID_ARG, E_INVALID_ARG,
                                "[E_INVALID_ARG] Wrong group index(%d).", groupIndex);
 
-       if (IsLoadedItem(groupIndex, itemIndex) == false)
-       {
-               return E_SUCCESS;
-       }
-
        _ListViewGroupNode* pListGroupNode = GetGroupNode(groupIndex);
        SysTryReturn(NID_UI_CTRL, pListGroupNode != null, GetLastResult(), GetLastResult(),
                                 "[%s] Propagating.", GetErrorMessage(GetLastResult()));
 
-       _LinkedList <_IListItemCommon*>::_Iterator theIter = pListGroupNode->__items.begin();
-
-       _IListItemCommon* pItem = null;
        int temporaryGroupIndex = -1;
        int temporaryItemIndex = -1;
 
-       while (theIter != pListGroupNode->__items.end())
+       _IListItemCommon* pItem = null;
+       _LinkedList <_IListItemCommon*>::_Iterator theIter = pListGroupNode->__items.begin();
+       _LinkedList <_IListItemCommon*>::_Iterator theEndIter = pListGroupNode->__items.end();
+
+       while (theIter != theEndIter)
        {
                pItem = *theIter;
                pItem->GetItemIndex(temporaryGroupIndex, temporaryItemIndex);
@@ -686,41 +666,30 @@ _ListViewModel::RemoveItemAt(int groupIndex, int itemIndex, bool internalDestroy
        SysTryReturn(NID_UI_CTRL, (groupIndex >= 0 && groupIndex < __countOfAllGroups), E_INVALID_ARG, E_INVALID_ARG,
                                "[E_INVALID_ARG] Wrong group index(%d).", groupIndex);
 
-       _ListViewGroupNode* pListGroupNode = GetGroupNode(groupIndex);
-       SysTryReturn(NID_UI_CTRL, pListGroupNode != null, GetLastResult(), GetLastResult(),
-                                "[%s] Propagating.", GetErrorMessage(GetLastResult()));
-
        if (itemIndex == -1)
        {
                return RemoveGroup(groupIndex);
        }
 
-       _IListItemCommon* pItem = GetItemFromContainer(groupIndex, itemIndex);
-       if (pItem != null)
-       {
-               pListGroupNode->__items.remove(pItem);
+       _ListViewGroupNode* pListGroupNode = GetGroupNode(groupIndex);
+       SysTryReturn(NID_UI_CTRL, pListGroupNode != null, GetLastResult(), GetLastResult(),
+                                "[%s] Propagating.", GetErrorMessage(GetLastResult()));
 
-               if (internalDestroy == false)
-               {
-                       __pListProviderAdaptor->UnloadItem(pItem, groupIndex, itemIndex);
-               }
-               else
-               {
-                       __pListProviderAdaptor->DeleteItem(pItem, groupIndex, itemIndex);
-               }
-       }
+
+       _IListItemCommon* pItem = GetItemFromContainer(groupIndex, itemIndex);
 
        int temporaryGroupIndex = -1;
        int temporaryItemIndex = -1;
+       _IListItemCommon* pTemporaryItem = null;
        _LinkedList <_IListItemCommon*>::_Iterator theIter = pListGroupNode->__items.begin();
        while (theIter != pListGroupNode->__items.end())
        {
-               pItem = *theIter;
-               pItem->GetItemIndex(temporaryGroupIndex, temporaryItemIndex);
+               pTemporaryItem = *theIter;
+               pTemporaryItem->GetItemIndex(temporaryGroupIndex, temporaryItemIndex);
 
                if (temporaryItemIndex > itemIndex)
                {
-                       pItem->SetItemIndex(temporaryGroupIndex, temporaryItemIndex - 1);
+                       pTemporaryItem->SetItemIndex(temporaryGroupIndex, temporaryItemIndex - 1);
                }
 
                theIter++;
@@ -731,6 +700,19 @@ _ListViewModel::RemoveItemAt(int groupIndex, int itemIndex, bool internalDestroy
 
        MoveCheckedAndDisabledItemIndex(pListGroupNode, itemIndex, -1);
 
+       if (pItem != null)
+       {
+               pListGroupNode->__items.remove(pItem);
+               if (internalDestroy == false)
+               {
+                       __pListProviderAdaptor->UnloadItem(pItem, groupIndex, itemIndex);
+               }
+               else
+               {
+                       __pListProviderAdaptor->DeleteItem(pItem, groupIndex, itemIndex);
+               }
+       }
+
        return E_SUCCESS;
 }
 
@@ -741,38 +723,25 @@ _ListViewModel::RemoveGroup(int groupIndex)
        SysTryReturn(NID_UI_CTRL, (groupIndex >= 0 && groupIndex < __countOfAllGroups), E_INVALID_ARG, E_INVALID_ARG,
                                "[E_INVALID_ARG] Wrong group index(%d).", groupIndex);
 
-       _ListViewGroupNode* pListGroupNode = GetGroupNode(groupIndex);
-       SysTryReturn(NID_UI_CTRL, pListGroupNode != null, GetLastResult(), GetLastResult(),
+       _ListViewGroupNode* pRemoveGroupNode = GetGroupNode(groupIndex);
+       SysTryReturn(NID_UI_CTRL, pRemoveGroupNode != null, GetLastResult(), GetLastResult(),
                                 "[%s] Propagating.", GetErrorMessage(GetLastResult()));
 
-       // remove group
-       _IListItemCommon* pItem = null;
-       int temporaryGroupIndex = -1;
-       int temporaryItemIndex = -1;
-       int itemCount = pListGroupNode->__items.size();
-
-       for (int i = itemCount - 1; i >= 0; i--)
-       {
-               pItem = pListGroupNode->__items.at(i);
-               pListGroupNode->__items.pop_back();
-
-               if (pItem != null)
-               {
-                       pItem->GetItemIndex(temporaryGroupIndex, temporaryItemIndex);
-                       __pListProviderAdaptor->UnloadItem(pItem, temporaryGroupIndex, temporaryItemIndex);
-               }
-       }
-       pListGroupNode->__items.clear();
+       // remove group from model
+       __groupNodes.erase(__groupNodes.begin() + groupIndex);
 
-       __countOfAllItems -= (pListGroupNode->__itemCountInGroup + 1);
+       __countOfAllItems -= (pRemoveGroupNode->__itemCountInGroup + 1);
        __countOfAllGroups--;
 
-       __groupNodes.erase(__groupNodes.begin() + groupIndex);
+       _IListItemCommon* pItem = null;
+       _ListViewGroupNode* pListGroupNode = null;
 
-       delete pListGroupNode;
+       int itemCount = 0;
+       int temporaryGroupIndex = -1;
+       int temporaryItemIndex = -1;
 
        // reset item index
-       int groupCount = GetAllGroupCount();
+       int groupCount = __groupNodes.size();
        for (int i = groupCount - 1; i >= groupIndex; i--)
        {
                pListGroupNode = GetGroupNode(i);
@@ -794,6 +763,23 @@ _ListViewModel::RemoveGroup(int groupIndex)
                }
        }
 
+       // remove group
+       itemCount = pRemoveGroupNode->__items.size();
+
+       for (int i = itemCount - 1; i >= 0; i--)
+       {
+               pItem = pRemoveGroupNode->__items.at(i);
+               pRemoveGroupNode->__items.pop_back();
+
+               if (pItem != null)
+               {
+                       pItem->GetItemIndex(temporaryGroupIndex, temporaryItemIndex);
+                       __pListProviderAdaptor->UnloadItem(pItem, temporaryGroupIndex, temporaryItemIndex);
+               }
+       }
+
+       delete pRemoveGroupNode;
+
        return E_SUCCESS;
 }
 
@@ -817,13 +803,13 @@ _ListViewModel::GetMaxCachingSize(void) const
 int
 _ListViewModel::GetOverflowCount(void) const
 {
-       int loadedGroups = GetAllGroupCount();
        int loadedItems = 0;
+       int loadedGroups = __groupNodes.size();
 
        _ListViewGroupNode* pListGroupNode = null;
        for (int i = 0; i < loadedGroups; i++)
        {
-               pListGroupNode = GetGroupNode(i);
+               pListGroupNode = __groupNodes.at(i);
                if (pListGroupNode != null)
                {
                        loadedItems += pListGroupNode->__items.size();
@@ -1203,7 +1189,7 @@ bool
 _ListViewModel::IsItemChecked(int groupIndex, int itemIndex) const
 {
        // check validation
-       if (IsValidItem(groupIndex, itemIndex) == false)
+       if (!IsValidItem(groupIndex, itemIndex))
        {
                return false;
        }
@@ -1213,7 +1199,7 @@ _ListViewModel::IsItemChecked(int groupIndex, int itemIndex) const
                                 "[%s] Propagating.", GetErrorMessage(GetLastResult()));
 
        //radio style
-       if (pListGroupNode->__usingRadioStyle == true)
+       if (pListGroupNode->__usingRadioStyle)
        {
                if (pListGroupNode->__radioCheckedItemIndex == itemIndex)
                {
@@ -1474,24 +1460,24 @@ _ListViewModel::SetItem(_IListItemCommon& item, int groupIndex, int itemIndex)
 
 // origin & destination item must be loaded
 result
-_ListViewModel::MoveItem(_ListItemPos originPosition, _ListItemPos destinationPosition)
+_ListViewModel::MoveItem(int originGroupIndex, int originItemIndex, int destinationGroupIndex, int destinationItemIndex)
 {
-       if (IsValidItem(originPosition.groupIndex, originPosition.itemIndex) == false
-               || IsValidItem(destinationPosition.groupIndex, destinationPosition.itemIndex - 1) == false)
+       if (IsValidItem(originGroupIndex, originItemIndex) == false
+               || IsValidItem(destinationGroupIndex, destinationItemIndex - 1) == false)
        {
                SysLogException(NID_UI_CTRL, E_INVALID_ARG, "[E_INVALID_ARG] Item index is not valid.");
                return E_SYSTEM;
        }
 
-       _ListViewGroupNode* pOriginGroupNode = GetGroupNode(originPosition.groupIndex);
+       _ListViewGroupNode* pOriginGroupNode = GetGroupNode(originGroupIndex);
        SysTryReturn(NID_UI_CTRL, pOriginGroupNode != null, GetLastResult(), GetLastResult(),
                                 "[%s] Propagating.", GetErrorMessage(GetLastResult()));
 
-       _ListViewGroupNode* pDestinationGroupNode = GetGroupNode(destinationPosition.groupIndex);
+       _ListViewGroupNode* pDestinationGroupNode = GetGroupNode(destinationGroupIndex);
        SysTryReturn(NID_UI_CTRL, pDestinationGroupNode != null, GetLastResult(), GetLastResult(),
                                 "[%s] Propagating.", GetErrorMessage(GetLastResult()));
 
-       _IListItemCommon* pItem = GetItemFromContainer(originPosition.groupIndex, originPosition.itemIndex);
+       _IListItemCommon* pItem = GetItemFromContainer(originGroupIndex, originItemIndex);
        SysTryReturn(NID_UI_CTRL, pItem != null, GetLastResult(), GetLastResult(),
                                 "[%s] Propagating.", GetErrorMessage(GetLastResult()));
 
@@ -1501,7 +1487,7 @@ _ListViewModel::MoveItem(_ListItemPos originPosition, _ListItemPos destinationPo
        int indexCount = 0;
        bool isFound = false;
 
-       if (originPosition.groupIndex != destinationPosition.groupIndex)        // different group
+       if (originGroupIndex != destinationGroupIndex)  // different group
        {
                pOriginGroupNode->__items.remove(pItem);
 
@@ -1511,7 +1497,7 @@ _ListViewModel::MoveItem(_ListItemPos originPosition, _ListItemPos destinationPo
                        pTemporaryItem = *theIter;
                        pTemporaryItem->GetItemIndex(temporaryGroupIndex, temporaryItemIndex);
 
-                       if (temporaryItemIndex > originPosition.itemIndex)
+                       if (temporaryItemIndex > originItemIndex)
                        {
                                pTemporaryItem->SetItemIndex(temporaryGroupIndex, temporaryItemIndex - 1);
                        }
@@ -1519,7 +1505,7 @@ _ListViewModel::MoveItem(_ListItemPos originPosition, _ListItemPos destinationPo
                        theIter++;
                }
 
-               pItem->SetItemIndex(destinationPosition.groupIndex, destinationPosition.itemIndex);
+               pItem->SetItemIndex(destinationGroupIndex, destinationItemIndex);
 
                _LinkedList <_IListItemCommon*>::_Iterator destinationIter = pDestinationGroupNode->__items.begin();
                while (destinationIter != pDestinationGroupNode->__items.end())
@@ -1527,11 +1513,11 @@ _ListViewModel::MoveItem(_ListItemPos originPosition, _ListItemPos destinationPo
                        pTemporaryItem = *destinationIter;
                        pTemporaryItem->GetItemIndex(temporaryGroupIndex, temporaryItemIndex);
 
-                       if (temporaryItemIndex >= destinationPosition.itemIndex)
+                       if (temporaryItemIndex >= destinationItemIndex)
                        {
                                pTemporaryItem->SetItemIndex(temporaryGroupIndex, temporaryItemIndex + 1);
 
-                               if (temporaryItemIndex == destinationPosition.itemIndex)
+                               if (temporaryItemIndex == destinationItemIndex)
                                {
                                        pDestinationGroupNode->__items.insert(destinationIter, pItem);
                                        isFound = true;
@@ -1547,10 +1533,10 @@ _ListViewModel::MoveItem(_ListItemPos originPosition, _ListItemPos destinationPo
                }
 
                // remove checked(radio/check) & disabled item index
-               MoveCheckedAndDisabledItemIndex(pOriginGroupNode, originPosition.itemIndex, -1, pItem->IsChecked(), pItem->IsItemEnabled());
+               MoveCheckedAndDisabledItemIndex(pOriginGroupNode, originItemIndex, -1, pItem->IsChecked(), pItem->IsItemEnabled());
 
                // insert checked(radio/check) & disabled item index
-               MoveCheckedAndDisabledItemIndex(pDestinationGroupNode, -1, destinationPosition.itemIndex, pItem->IsChecked(), pItem->IsItemEnabled());
+               MoveCheckedAndDisabledItemIndex(pDestinationGroupNode, -1, destinationItemIndex, pItem->IsChecked(), pItem->IsItemEnabled());
 
                pOriginGroupNode->__itemCountInGroup--;
                pDestinationGroupNode->__itemCountInGroup++;
@@ -1565,25 +1551,25 @@ _ListViewModel::MoveItem(_ListItemPos originPosition, _ListItemPos destinationPo
                        pTemporaryItem = *theIter;
                        pTemporaryItem->GetItemIndex(temporaryGroupIndex, temporaryItemIndex);
 
-                       if (temporaryItemIndex < originPosition.itemIndex && temporaryItemIndex >= destinationPosition.itemIndex)
+                       if (temporaryItemIndex < originItemIndex && temporaryItemIndex >= destinationItemIndex)
                        {
                                pTemporaryItem->SetItemIndex(temporaryGroupIndex, temporaryItemIndex + 1);
                        }
-                       else if (temporaryItemIndex > originPosition.itemIndex && temporaryItemIndex <= destinationPosition.itemIndex)
+                       else if (temporaryItemIndex > originItemIndex && temporaryItemIndex <= destinationItemIndex)
                        {
                                pTemporaryItem->SetItemIndex(temporaryGroupIndex, temporaryItemIndex - 1);
 
-                               if (temporaryItemIndex == destinationPosition.itemIndex)
+                               if (temporaryItemIndex == destinationItemIndex)
                                {
                                        indexCount++;
                                }
                        }
-                       else if (temporaryItemIndex > originPosition.itemIndex && temporaryItemIndex > destinationPosition.itemIndex)
+                       else if (temporaryItemIndex > originItemIndex && temporaryItemIndex > destinationItemIndex)
                        {
                                break;
                        }
 
-                       if (temporaryItemIndex < destinationPosition.itemIndex)
+                       if (temporaryItemIndex < destinationItemIndex)
                        {
                                indexCount++;
                        }
@@ -1596,16 +1582,22 @@ _ListViewModel::MoveItem(_ListItemPos originPosition, _ListItemPos destinationPo
                        indexCount = 0;
                }
 
-               pItem->SetItemIndex(destinationPosition.groupIndex, destinationPosition.itemIndex);
+               pItem->SetItemIndex(destinationGroupIndex, destinationItemIndex);
                pOriginGroupNode->__items.insert(pOriginGroupNode->__items.begin() + indexCount, pItem);
 
                // move checked(radio/check) & disabled item index
-               MoveCheckedAndDisabledItemIndex(pOriginGroupNode, originPosition.itemIndex, destinationPosition.itemIndex, pItem->IsChecked(), pItem->IsItemEnabled());
+               MoveCheckedAndDisabledItemIndex(pOriginGroupNode, originItemIndex, destinationItemIndex, pItem->IsChecked(), pItem->IsItemEnabled());
        }
 
        return E_SUCCESS;
 }
 
+result
+_ListViewModel::MoveItem(_ListItemPos originPosition, _ListItemPos destinationPosition)
+{
+       return MoveItem(originPosition.groupIndex, originPosition.itemIndex, destinationPosition.groupIndex, destinationPosition.itemIndex);
+}
+
 // insert mode : originItemIndex == -1
 // remove mode : destinationItemIndex == -1
 void
@@ -1619,7 +1611,7 @@ _ListViewModel::MoveCheckedAndDisabledItemIndex(_ListViewGroupNode* pListGroupNo
        }
 
        // move checked(radio/check) item index
-       if (pListGroupNode->__usingRadioStyle == true)
+       if (pListGroupNode->__usingRadioStyle)
        {
                //radio style
                if (checked == true || (pListGroupNode->__radioCheckedItemIndex == originItemIndex && originItemIndex != -1))   // for insert mode
@@ -1671,6 +1663,7 @@ _ListViewModel::MoveCheckedAndDisabledItemIndex(_ListViewGroupNode* pListGroupNo
                                else if (checkedItemIndex == originItemIndex)
                                {
                                        pListGroupNode->__checkedItems.erase(theIter);
+                                       continue;
                                }
                                else if (checkedItemIndex > originItemIndex && checkedItemIndex > temporaryDestinationIndex)
                                {
@@ -1726,6 +1719,7 @@ _ListViewModel::MoveCheckedAndDisabledItemIndex(_ListViewGroupNode* pListGroupNo
                        else if (disabledItemIndex == originItemIndex)
                        {
                                pListGroupNode->__disabledItems.erase(theIter);
+                               continue;
                        }
                        else if (disabledItemIndex > originItemIndex && disabledItemIndex > temporaryDestinationIndex)
                        {
@@ -1751,7 +1745,7 @@ _ListViewModel::MoveCheckedAndDisabledItemIndex(_ListViewGroupNode* pListGroupNo
 _ListViewGroupNode*
 _ListViewModel::GetGroupNode(int groupIndex) const
 {
-       if (__groupNodes.empty() == true)
+       if (__groupNodes.empty())
        {
                SysLogException(NID_UI_CTRL, E_SYSTEM, "[E_SYSTEM] GroupNode is Empty.");
                return null;
index e2184a9..d1166a1 100644 (file)
@@ -126,6 +126,12 @@ public:
                _ReverseIterator(_ListNode* _p = null)
                        : __pPos(_p) {}
 
+               _Iterator base() const
+               {
+                       _Iterator _retval(__pPos);
+                       return _retval;
+               }
+
                _ReverseIterator& operator ++(void)
                {
                        __pPos = __pPos->pPrev;
@@ -147,7 +153,7 @@ public:
 
                _ReverseIterator operator --(int)
                {
-                       _Iterator _retval = *this;
+                       _ReverseIterator _retval = *this;
                        --*this;
                        return _retval;
                } //post
@@ -209,8 +215,10 @@ public:
        _ReverseIterator rend(void) const { return _ReverseIterator(__pHead);}
 
 private:
-       void insert_node(_Iterator, _ListNode *, _ListNode *, const T &);
-       void delete_node(_Iterator, _ListNode *, _ListNode*);
+       void insert_node(_ListNode *, _ListNode *, const T &);
+       void insert_node(_Iterator&, const T &);
+       void delete_node(_ListNode *, _ListNode*);
+       void delete_node(_Iterator&);
        void swap_node(_ListNode*, _ListNode*);
        void sort_node(bool (*)(T, T), _ListNode *, _ListNode*);
        int count_node(_ListNode*, _ListNode*);
@@ -247,14 +255,14 @@ template<class T>
 void
 _LinkedList <T>::insert(_Iterator& _where, const T& _val)
 {
-       insert_node(_where, null, null, _val);
+       insert_node(_where, _val);
 }
 
 template<class T>
 void
 _LinkedList <T>::erase(_Iterator& _where)
 {
-       delete_node(_where, null, null);
+       delete_node(_where);
 }
 
 template<class T>
@@ -305,28 +313,28 @@ template<class T>
 void
 _LinkedList <T>::push_front(const T& _val)
 {
-       insert_node(null, __pHead->pNext, null, _val);
+       insert_node(__pHead->pNext, null, _val);
 }
 
 template<class T>
 void
 _LinkedList <T>::push_back(const T& _val)
 {
-       insert_node(null, null, __pTail->pPrev, _val);
+       insert_node(null, __pTail->pPrev, _val);
 }
 
 template<class T>
 void
 _LinkedList <T>::pop_front(void)
 {
-       delete_node(null, __pHead->pNext, null);
+       delete_node(__pHead->pNext, null);
 }
 
 template<class T>
 void
 _LinkedList <T>::pop_back(void)
 {
-       delete_node(null, null, __pTail->pPrev);
+       delete_node(null, __pTail->pPrev);
 }
 
 template<class T>
@@ -383,58 +391,62 @@ _LinkedList <T>::advance(_Iterator& _where, int _index)
 
 template<class T>
 void
-_LinkedList <T>::insert_node(_Iterator _where, _ListNode* _first, _ListNode* _last, const T& _val)
+_LinkedList <T>::insert_node(_ListNode* _first, _ListNode* _last, const T& _val)
 {
        _ListNode* _pNewNode = new (std::nothrow) _ListNode;
        _pNewNode->val = _val;
 
-       if (_where == null)
+       if (!_first && !_last)
        {
-               if (!_first && !_last)
-               {
-                       __pHead->pNext = _pNewNode;
-                       __pTail->pPrev = _pNewNode;
-               }
-               else if (_first)
-               {
-                       _pNewNode->pPrev = __pHead;
-                       _pNewNode->pNext = __pHead->pNext;
-                       __pHead->pNext->pPrev = _pNewNode;
-                       __pHead->pNext = _pNewNode;
-               }
-               else
-               {
-                       _pNewNode->pPrev = __pTail->pPrev;
-                       _pNewNode->pNext = __pTail;
-                       __pTail->pPrev->pNext = _pNewNode;
-                       __pTail->pPrev = _pNewNode;
-               }
+               __pHead->pNext = _pNewNode;
+               __pTail->pPrev = _pNewNode;
+       }
+       else if (_first)
+       {
+               _pNewNode->pPrev = __pHead;
+               _pNewNode->pNext = __pHead->pNext;
+               __pHead->pNext->pPrev = _pNewNode;
+               __pHead->pNext = _pNewNode;
        }
        else
        {
-               if (_where.__pPos == __pHead->pNext)
-               {
-                       _pNewNode->pPrev = __pHead;
-                       _pNewNode->pNext = __pHead->pNext;
-                       __pHead->pNext->pPrev = _pNewNode;
-                       __pHead->pNext = _pNewNode;
-               }
-               else if (_where.__pPos == __pTail)
-               {
-                       _pNewNode->pPrev = __pTail->pPrev;
-                       _pNewNode->pNext = __pTail;
-                       __pTail->pPrev->pNext = _pNewNode;
-                       __pTail->pPrev = _pNewNode;
-               }
-               else
-               {
-                       _pNewNode->pPrev = _where.__pPos->pPrev;
-                       _where.__pPos->pPrev->pNext = _pNewNode;
-                       _pNewNode->pNext = _where.__pPos;
-                       _where.__pPos->pPrev = _pNewNode;
-               }
+               _pNewNode->pPrev = __pTail->pPrev;
+               _pNewNode->pNext = __pTail;
+               __pTail->pPrev->pNext = _pNewNode;
+               __pTail->pPrev = _pNewNode;
+       }
 
-               _where++;
+       __length++;
+}
+
+
+template<class T>
+void
+_LinkedList <T>::insert_node(_Iterator& _where, const T& _val)
+{
+       _ListNode* _pNewNode = new (std::nothrow) _ListNode;
+       _pNewNode->val = _val;
+
+       if (_where.__pPos == __pHead->pNext)
+       {
+               _pNewNode->pPrev = __pHead;
+               _pNewNode->pNext = __pHead->pNext;
+               __pHead->pNext->pPrev = _pNewNode;
+               __pHead->pNext = _pNewNode;
+       }
+       else if (_where.__pPos == __pTail)
+       {
+               _pNewNode->pPrev = __pTail->pPrev;
+               _pNewNode->pNext = __pTail;
+               __pTail->pPrev->pNext = _pNewNode;
+               __pTail->pPrev = _pNewNode;
+       }
+       else
+       {
+               _pNewNode->pPrev = _where.__pPos->pPrev;
+               _where.__pPos->pPrev->pNext = _pNewNode;
+               _pNewNode->pNext = _where.__pPos;
+               _where.__pPos->pPrev = _pNewNode;
        }
 
        __length++;
@@ -442,67 +454,84 @@ _LinkedList <T>::insert_node(_Iterator _where, _ListNode* _first, _ListNode* _la
 
 template<class T>
 void
-_LinkedList <T>::delete_node(_Iterator _where, _ListNode* _first, _ListNode* _last)
+_LinkedList <T>::delete_node(_ListNode* _first, _ListNode* _last)
 {
        if (__length <= 0)
        {
                return;
        }
 
-       if (_where == null)
+       if ((_first == __pHead->pNext) && (_first == __pTail->pPrev)) // only one node
        {
-               if ((_first == __pHead->pNext) && (_first == __pTail->pPrev)) // only one node
-               {
-                       delete __pHead->pNext;
-                       __pHead->pNext = __pTail;
-                       __pTail->pPrev = __pHead;
-               }
-               else if (_first)    // pop_front
+               delete __pHead->pNext;
+               __pHead->pNext = __pTail;
+               __pTail->pPrev = __pHead;
+       }
+       else if (_first)    // pop_front
+       {
+               __pHead->pNext = __pHead->pNext->pNext;
+               delete __pHead->pNext->pPrev;
+               __pHead->pNext->pPrev = __pHead;
+       }
+       else if (_last) // pop_back
+       {
+               __pTail->pPrev = __pTail->pPrev->pPrev;
+               delete __pTail->pPrev->pNext;
+               __pTail->pPrev->pNext = __pTail;
+       }
+       else
+       {
+               return;
+       }
+
+       __length--;
+}
+
+template<class T>
+void
+_LinkedList <T>::delete_node(_Iterator& _where)
+{
+       if (__length <= 0)
+       {
+               return;
+       }
+
+       if ((_where.__pPos == __pHead->pNext) && (_where.__pPos == __pTail->pPrev))
+       {
+               delete __pHead->pNext;
+               __pHead->pNext = __pTail;
+               __pTail->pPrev = __pHead;
+
+               _where.__pPos = __pTail;
+       }
+       else
+       {
+               if (_where.__pPos == __pHead->pNext)
                {
                        __pHead->pNext = __pHead->pNext->pNext;
                        delete __pHead->pNext->pPrev;
                        __pHead->pNext->pPrev = __pHead;
+
+                       _where.__pPos = __pHead->pNext;
                }
-               else if (_last) // pop_back
+               else if (_where.__pPos == __pTail->pPrev)
                {
                        __pTail->pPrev = __pTail->pPrev->pPrev;
                        delete __pTail->pPrev->pNext;
                        __pTail->pPrev->pNext = __pTail;
+
+                       _where.__pPos = __pTail;
                }
                else
                {
-                       return;
-               }
-       }
-       else
-       {
-               if ((_where.__pPos == __pHead->pNext) && (_where.__pPos == __pTail->pPrev))
-               {
-                       delete __pHead->pNext;
-                       __pHead->pNext = __pTail;
-                       __pTail->pPrev = __pHead;
-               }
-               else
-               {
-                       if (_where.__pPos == __pHead->pNext)
-                       {
-                               __pHead->pNext = __pHead->pNext->pNext;
-                               delete __pHead->pNext->pPrev;
-                               __pHead->pNext->pPrev = __pHead;
-                       }
-                       else if (_where.__pPos == __pTail->pPrev)
-                       {
-                               __pTail->pPrev = __pTail->pPrev->pPrev;
-                               delete __pTail->pPrev->pNext;
-                               __pTail->pPrev->pNext = __pTail;
-                       }
-                       else
-                       {
-                               _where.__pPos->pPrev->pNext = _where.__pPos->pNext;
-                               _where.__pPos->pNext->pPrev = _where.__pPos->pPrev;
-                               delete _where.__pPos;
-                               _where.__pPos = null;
-                       }
+                       _ListNode* pDeleteNode = _where.__pPos;
+
+                       pDeleteNode->pPrev->pNext = pDeleteNode->pNext;
+                       pDeleteNode->pNext->pPrev = pDeleteNode->pPrev;
+                       _where.__pPos = pDeleteNode->pNext;
+//                     ++_where;
+
+                       delete pDeleteNode;
                }
        }
 
index 5ab1af6..02db212 100644 (file)
@@ -93,6 +93,8 @@ public:
 
        result MoveItem(_ListItemPos originPosition, _ListItemPos destinationPosition);
 
+       result MoveItem(int originGroupIndex, int originItemIndex, int destinationGroupIndex, int destinationItemIndex);
+
        result RemoveItemAt(int groupIndex, int itemIndex, bool internalDestroy = false);
 
        result RemoveAllItem(bool internalDestroy = false, bool backupItemStatus = false);