pimappservices/calendar/server/src/agsindexiterator.cpp
changeset 0 f979ecb2b13e
equal deleted inserted replaced
-1:000000000000 0:f979ecb2b13e
       
     1 // Copyright (c) 1997-2009 Nokia Corporation and/or its subsidiary(-ies).
       
     2 // All rights reserved.
       
     3 // This component and the accompanying materials are made available
       
     4 // under the terms of "Eclipse Public License v1.0"
       
     5 // which accompanies this distribution, and is available
       
     6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     7 //
       
     8 // Initial Contributors:
       
     9 // Nokia Corporation - initial contribution.
       
    10 //
       
    11 // Contributors:
       
    12 //
       
    13 // Description:
       
    14 //
       
    15 
       
    16 #include "agsindexiterator.h"
       
    17 
       
    18 #include "agmdate.h"
       
    19 #include "agmpanic.h"
       
    20 #include "agsindex.h"
       
    21 
       
    22 // ----------------------------TAgnEntryDateIterator----------------------------
       
    23 // Entry Iterator 
       
    24 TAgnEntryDateIterator::TAgnEntryDateIterator(CAgnSimpleEntryTable& aEntryInfoTable, const TTime& aUndatedTodoTime, const TAgnFilter& aFilter):
       
    25 		iNonRptFixedIter(aEntryInfoTable.EntryNonRptIndex(MAgnCalendarTimeMode::EFixedUtc), aFilter),
       
    26 		iNonRptFloatingIter(aEntryInfoTable.EntryNonRptIndex(MAgnCalendarTimeMode::EFloating), aFilter),
       
    27 		iRptFixedIter(aEntryInfoTable.EntryRptIndex(MAgnCalendarTimeMode::EFixedUtc), aFilter),
       
    28 		iRptFloatingIter(aEntryInfoTable.EntryRptIndex(MAgnCalendarTimeMode::EFloating), aFilter),
       
    29 		iTodoNonRptFixedIter(aEntryInfoTable.TodoNonRptIndex(MAgnCalendarTimeMode::EFixedUtc), aFilter),
       
    30 		iTodoNonRptFloatingIter(aEntryInfoTable.TodoNonRptIndex(MAgnCalendarTimeMode::EFloating), aFilter),
       
    31 		iTodoRptFixedIter(aEntryInfoTable.TodoRptIndex(MAgnCalendarTimeMode::EFixedUtc), aFilter),
       
    32 		iTodoRptFloatingIter(aEntryInfoTable.TodoRptIndex(MAgnCalendarTimeMode::EFloating), aFilter)
       
    33 	//
       
    34 	// Populate the array of iterators with only those that are
       
    35 	// required w.r.t to the filters
       
    36 	//
       
    37 	{
       
    38 	TInt i = 0;
       
    39 	if (aFilter.AreNonTodosIncluded())
       
    40 		{
       
    41 		iIteratorsInUse[i++] = &iNonRptFixedIter;
       
    42 		iIteratorsInUse[i++] = &iNonRptFloatingIter;
       
    43 		iIteratorsInUse[i++] = &iRptFixedIter;
       
    44 		iIteratorsInUse[i++] = &iRptFloatingIter;
       
    45 		}
       
    46 	if (aFilter.AreCompletedTodosIncluded() || aFilter.AreIncompletedTodosIncluded())
       
    47 		{
       
    48 		iIteratorsInUse[i++] = &iTodoNonRptFixedIter;
       
    49 		iIteratorsInUse[i++] = &iTodoNonRptFloatingIter;
       
    50 		iIteratorsInUse[i++] = &iTodoRptFixedIter;
       
    51 		iIteratorsInUse[i++] = &iTodoRptFloatingIter;
       
    52 		}
       
    53 	
       
    54 	iCount = i;
       
    55 		
       
    56 	for (TInt ii =0; ii < iCount; ii++)
       
    57 		{
       
    58 		iIteratorsInUse[ii]->SetUndatedTodoTime(aUndatedTodoTime);
       
    59 		}
       
    60 	}
       
    61 
       
    62 const CAgnSimpleEntry& TAgnEntryDateIterator::CurrentElement() const
       
    63 /**
       
    64 Return the current element in the iterator
       
    65 
       
    66 @internalAll
       
    67 */
       
    68 	{
       
    69 	__ASSERT_ALWAYS(iCurrent >= 0 && iCurrent < iCount,Panic(EAgmErrCompoundIteratorOutOfRange));
       
    70 	return iIteratorsInUse[iCurrent]->CurrentElement();
       
    71 	}
       
    72 	
       
    73 const TTime& TAgnEntryDateIterator::CurrentKey() const
       
    74 /**
       
    75 return current key
       
    76 
       
    77 @internalAll
       
    78 */
       
    79 	{
       
    80 
       
    81 	__ASSERT_ALWAYS(iCurrent>=0 && iCurrent<iCount,Panic(EAgmErrCompoundIteratorOutOfRange));
       
    82 	return iIteratorsInUse[iCurrent]->CurrentKey();
       
    83 	}
       
    84 	
       
    85 
       
    86 void TAgnEntryDateIterator::StartL()
       
    87 /**
       
    88 Position all iterator to their start
       
    89 
       
    90 @internalAll
       
    91 */
       
    92 	{
       
    93 
       
    94 	for(TInt ii = 0; ii < iCount; ii++)
       
    95 		{
       
    96 		iIteratorsInUse[ii]->StartL();
       
    97 		}
       
    98 	SetCurrent();
       
    99 	}
       
   100 
       
   101 void TAgnEntryDateIterator::NextL()
       
   102 /**
       
   103 move position to the next element
       
   104 
       
   105 @internalAll
       
   106 */
       
   107 	{
       
   108 	__ASSERT_ALWAYS(iCurrent>=0 && iCurrent<iCount,Panic(EAgmErrCompoundIteratorOutOfRange));
       
   109 
       
   110 	TTime currentKey = iIteratorsInUse[iCurrent]->CurrentKey();
       
   111 	iIteratorsInUse[iCurrent]->NextL();
       
   112 	if (iIteratorsInUse[iCurrent]->AtEnd() || currentKey < iIteratorsInUse[iCurrent]->CurrentKey())
       
   113 		SetCurrent();
       
   114 	}
       
   115 	
       
   116 	
       
   117 void TAgnEntryDateIterator::PreviousL()
       
   118 /**
       
   119 move position to previous element
       
   120 
       
   121 @internalAll
       
   122 */
       
   123 	{
       
   124 
       
   125 	__ASSERT_ALWAYS(iCurrent>=0 && iCurrent<iCount,Panic(EAgmErrCompoundIteratorOutOfRange));
       
   126 
       
   127 	TTime currentKey = iIteratorsInUse[iCurrent]->CurrentKey();
       
   128 	iIteratorsInUse[iCurrent]->PreviousL();
       
   129 	if (iIteratorsInUse[iCurrent]->AtStart() || currentKey > iIteratorsInUse[iCurrent]->CurrentKey())
       
   130 		SetCurrentLessOrEqual();
       
   131 	}
       
   132 
       
   133 TBool TAgnEntryDateIterator::AtEnd()
       
   134 /**
       
   135 Are all iterators positioned to beyond the end
       
   136 
       
   137 @internalAll
       
   138 */
       
   139 	{
       
   140 
       
   141 	TInt ii;
       
   142 	for(ii = 0; ii < iCount && iIteratorsInUse[ii]->AtEnd();ii++)
       
   143 		;
       
   144 	return (ii == iCount);
       
   145 	}
       
   146 
       
   147 TBool TAgnEntryDateIterator::AtStart()
       
   148 /**
       
   149 Are all iterators positioned to before the start
       
   150 
       
   151 @internalAll
       
   152 */
       
   153 	{
       
   154 
       
   155 	TInt ii;
       
   156 	for(ii = 0; ii < iCount && iIteratorsInUse[ii]->AtStart();ii++)
       
   157 		;
       
   158 	return (ii == iCount);
       
   159 	}
       
   160 
       
   161 TBool TAgnEntryDateIterator::GotoL(TTime& aKeyValue)
       
   162 /**
       
   163 Position to the first element whose keyvalue is >= aKeyValue
       
   164 
       
   165 @internalAll
       
   166 */
       
   167 	{
       
   168 
       
   169 	for(TInt ii = 0; ii < iCount;ii++)
       
   170 		{
       
   171 		TTime wkKeyValue(aKeyValue);
       
   172 		iIteratorsInUse[ii]->GotoL(wkKeyValue);
       
   173 		}
       
   174 	return SetCurrent();
       
   175 	}
       
   176 
       
   177 TBool TAgnEntryDateIterator::GotoLessOrEqualL(TTime& aKeyValue)
       
   178 /**
       
   179 Position to the first element whose keyvalue is >= aKeyValue
       
   180 
       
   181 @internalAll
       
   182 */
       
   183 	{
       
   184 
       
   185 	for(TInt ii = 0; ii < iCount;ii++)
       
   186 		{
       
   187 		TTime wkKeyValue(aKeyValue);
       
   188 		iIteratorsInUse[ii]->GotoLessOrEqualL(wkKeyValue);
       
   189 		}
       
   190 	return SetCurrentLessOrEqual();
       
   191 	}
       
   192 
       
   193 TBool TAgnEntryDateIterator::SetCurrent()
       
   194 //
       
   195 // Set the current iterator
       
   196 //
       
   197 	{
       
   198 
       
   199 	TTime best(AgnDateTime::MinDate());
       
   200 	iCurrent = -1;
       
   201 	for(TInt ii = 0; ii < iCount; ii++)
       
   202 		{
       
   203 		if (!iIteratorsInUse[ii]->AtEnd() && (iCurrent == -1 || best > iIteratorsInUse[ii]->CurrentKey()))
       
   204 			{
       
   205 			best = iIteratorsInUse[ii]->CurrentKey();
       
   206 			iCurrent = ii;
       
   207 			}
       
   208 		}
       
   209 	if(iCurrent == -1)
       
   210 		return (EFalse);
       
   211 	return (ETrue);
       
   212 	}
       
   213 
       
   214 TBool TAgnEntryDateIterator::SetCurrentLessOrEqual()
       
   215 
       
   216 //
       
   217 // Set the current iterator
       
   218 //
       
   219 	{
       
   220 
       
   221 	TTime best(AgnDateTime::MinDate());
       
   222 	iCurrent = -1;
       
   223 	for(TInt ii = 0; ii < iCount; ii++)
       
   224 		{
       
   225 		if (!iIteratorsInUse[ii]->AtStart() && (iCurrent == -1 || best < iIteratorsInUse[ii]->CurrentKey()))
       
   226 			{
       
   227 			best = iIteratorsInUse[ii]->CurrentKey();
       
   228 			iCurrent = ii;
       
   229 			}
       
   230 		}
       
   231 	if(iCurrent == -1)
       
   232 		return (EFalse);
       
   233 	return (ETrue);
       
   234 	}
       
   235 
       
   236 TAgnEntryDateIterator::~TAgnEntryDateIterator()
       
   237 	{
       
   238 	}
       
   239 
       
   240 // --------------------------TAgnTodoNonRptIterator-----------------------------
       
   241 TAgnTodoNonRptIterator::TAgnTodoNonRptIterator(CAgnIndex* aIndex,const TAgnFilter& aFilter):
       
   242                         TAgnIterator(aIndex, aFilter)
       
   243                         {
       
   244                         }
       
   245 
       
   246 TAgnTodoNonRptIterator::TAgnTodoNonRptIterator()
       
   247                         {
       
   248                         }
       
   249 
       
   250 TBool TAgnTodoNonRptIterator::GotoL(TTime& aKeyValue)
       
   251 	{
       
   252 	const_cast<CAgnIndex*>(Array())->SetUndatedTodoTime(iUndatedTodoTime);
       
   253 	return TAgnIterator::GotoL(aKeyValue);
       
   254 	}
       
   255 
       
   256 TBool TAgnTodoNonRptIterator::GotoLessOrEqualL(TTime& aKeyValue)
       
   257 	{
       
   258 	const_cast<CAgnIndex*>(Array())->SetUndatedTodoTime(iUndatedTodoTime);
       
   259 	return TAgnIterator::GotoLessOrEqualL(aKeyValue);
       
   260 	}
       
   261 
       
   262 
       
   263 // -------------------------------- EOF ----------------------------------------