persistentstorage/sql/SRC/Common/SqlBufIterator.inl
changeset 0 08ec8eefde2f
child 23 26645d81f48d
equal deleted inserted replaced
-1:000000000000 0:08ec8eefde2f
       
     1 // Copyright (c) 2006-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 // /////////////////////          TSqlBufRIterator class          /////////////////////////////////////////
       
    15 // 
       
    16 //
       
    17 
       
    18 /**
       
    19  
       
    20  Initializes the iterator.
       
    21  After the initialization the iterator points to the first flat buffer field - 1.
       
    22  
       
    23  @param aBuf A reference to the buffer which will be iterated.
       
    24 */
       
    25 inline void TSqlBufRIterator::Set(const RSqlBufFlat& aBuf)
       
    26 	{
       
    27 	iBegin = aBuf.Header();
       
    28 	iCurrent = iBegin - 1;
       
    29 	iEnd = iBegin + aBuf.Count();
       
    30 	}
       
    31 
       
    32 /**
       
    33 Moves to the next flat buffer field
       
    34 
       
    35 @return False if there are no more fields to be iterated.
       
    36 */
       
    37 inline TBool TSqlBufRIterator::Next()
       
    38 	{
       
    39 	return ++iCurrent < iEnd;
       
    40 	}
       
    41 
       
    42 /**
       
    43 Moves to the specified field in the flat buffer.
       
    44 
       
    45 @param aIndex Field index
       
    46 */
       
    47 inline void TSqlBufRIterator::MoveTo(TInt aIndex)
       
    48 	{
       
    49 	__SQLASSERT((iBegin + (TUint)aIndex) < iEnd, ESqlPanicBadArgument);
       
    50 	iCurrent = iBegin + aIndex;
       
    51 	}
       
    52 
       
    53 /**
       
    54 @return True if the current flat buffer field is "Present"
       
    55 */
       
    56 inline TBool TSqlBufRIterator::IsPresent() const
       
    57 	{
       
    58 	__SQLASSERT(iCurrent >= iBegin && iCurrent < iEnd, ESqlPanicInternalError);
       
    59 	return iCurrent->iPos > 0;
       
    60 	}
       
    61 	
       
    62 /**
       
    63 @return Current flat buffer field type. One of TSqlColumnType enum item values or ESqlText8.
       
    64 */
       
    65 inline TInt TSqlBufRIterator::Type() const
       
    66 	{
       
    67 	__SQLASSERT(iCurrent >= iBegin && iCurrent < iEnd, ESqlPanicInternalError);
       
    68 	return iCurrent->Type();
       
    69 	}
       
    70 	
       
    71 /**
       
    72 @return Current flat buffer field size
       
    73 */
       
    74 inline TInt TSqlBufRIterator::Size() const
       
    75 	{
       
    76 	__SQLASSERT(iCurrent >= iBegin && iCurrent < iEnd, ESqlPanicInternalError);
       
    77 	return Type() == ESqlText ? iCurrent->Size() / sizeof(TUint16) : iCurrent->Size();
       
    78 	}
       
    79 
       
    80 
       
    81 ///////////////////////////////////////////////////////////////////////////////////////////////////////////
       
    82 ////////////////////////                 TSqlBufWIterator class          //////////////////////////////////
       
    83 ///////////////////////////////////////////////////////////////////////////////////////////////////////////
       
    84 
       
    85 /**
       
    86 Initializes the iterator.
       
    87 After the initialization the iterator points to the first flat buffer field - 1.
       
    88 
       
    89 @param aBuf A reference to the buffer which will be iterated.
       
    90 */
       
    91 inline void TSqlBufWIterator::Set(RSqlBufFlat& aBuf)
       
    92 	{
       
    93 	iBuf = &aBuf;
       
    94 	iIndex = -1;
       
    95 	}
       
    96 	
       
    97 /**
       
    98 Moves to the next flat buffer field
       
    99 
       
   100 @return False if there are no more fields to be iterated.
       
   101 */
       
   102 inline TBool TSqlBufWIterator::Next()
       
   103 	{
       
   104 	__SQLASSERT(iBuf != NULL, ESqlPanicInternalError);
       
   105 	return ++iIndex < iBuf->Count();	
       
   106 	}
       
   107 	
       
   108 /**
       
   109 Moves to the specified field in the flat buffer.
       
   110 
       
   111 @param aIndex Field index
       
   112 */
       
   113 inline void TSqlBufWIterator::MoveTo(TInt aIndex)
       
   114 	{
       
   115 	__SQLASSERT(iBuf != NULL, ESqlPanicInternalError);
       
   116 	__SQLASSERT((TUint)aIndex < iBuf->Count(), ESqlPanicInternalError);
       
   117 	iIndex = aIndex;
       
   118 	}
       
   119 
       
   120 /**
       
   121 Sets the current flat buffer field to NULL.
       
   122 */
       
   123 inline void TSqlBufWIterator::SetNull()
       
   124 	{
       
   125 	__SQLASSERT(iBuf != NULL, ESqlPanicInternalError);
       
   126 	__SQLASSERT((TUint)iIndex < iBuf->Count(), ESqlPanicInternalError);
       
   127 	(void)iBuf->SetField(iIndex, ESqlNull, NULL, 0);
       
   128 	}
       
   129 	
       
   130 /**
       
   131 Sets the current flat buffer field as "Not present".
       
   132 
       
   133 @param aType Field type. One of TSqlColumnType enum item values or ESqlText8.
       
   134 @param aLength Field length in bytes
       
   135 */
       
   136 inline void TSqlBufWIterator::SetAsNotPresent(TInt aType, TInt aLength)
       
   137 	{
       
   138 	__SQLASSERT(::IsSequenceSqlType(aType), ESqlPanicBadArgument);
       
   139 	__SQLASSERT(aLength >= 0, ESqlPanicBadArgument);
       
   140 	__SQLASSERT(iBuf != NULL, ESqlPanicInternalError);
       
   141 	__SQLASSERT((TUint)iIndex < iBuf->Count(), ESqlPanicInternalError);
       
   142 	iBuf->SetField(iIndex, aType, NULL, aType == ESqlText ? aLength * sizeof(TUint16) : aLength);
       
   143 	}
       
   144 	
       
   145 /**
       
   146 Initializes current flat buffer field with an integer value.
       
   147 
       
   148 @param aValue An integer value to be set as a field content
       
   149 
       
   150 @return KErrNone, The operation has completed successfully;
       
   151 		KErrNoMemory, Out of memory condition has occured.
       
   152 */
       
   153 inline TInt TSqlBufWIterator::SetInt(TInt aValue)
       
   154 	{
       
   155 	__SQLASSERT(iBuf != NULL, ESqlPanicInternalError);
       
   156 	__SQLASSERT((TUint)iIndex < iBuf->Count(), ESqlPanicInternalError);
       
   157 	return iBuf->SetField(iIndex, ESqlInt, &aValue, sizeof(TInt));
       
   158 	}
       
   159 	
       
   160 /**
       
   161 Initializes current flat buffer field with an 64 bit integer value.
       
   162 
       
   163 @param aValue A 64 bit integer value to be set as a field content
       
   164 
       
   165 @return KErrNone, The operation has completed successfully;
       
   166 		KErrNoMemory, Out of memory condition has occured.
       
   167 */
       
   168 inline TInt TSqlBufWIterator::SetInt64(TInt64 aValue)
       
   169 	{
       
   170 	__SQLASSERT(iBuf != NULL, ESqlPanicInternalError);
       
   171 	__SQLASSERT((TUint)iIndex < iBuf->Count(), ESqlPanicInternalError);
       
   172 	return iBuf->SetField(iIndex, ESqlInt64, &aValue, sizeof(TInt64));
       
   173 	}
       
   174 	
       
   175 /**
       
   176 Initializes current flat buffer field with a real value.
       
   177 
       
   178 @param aValue A real value to be set as a field content
       
   179 
       
   180 @return KErrNone, The operation has completed successfully;
       
   181 		KErrNoMemory, Out of memory condition has occured.
       
   182 */
       
   183 inline TInt TSqlBufWIterator::SetReal(TReal aValue)
       
   184 	{
       
   185 	__SQLASSERT(iBuf != NULL, ESqlPanicInternalError);
       
   186 	__SQLASSERT((TUint)iIndex < iBuf->Count(), ESqlPanicInternalError);
       
   187 	return iBuf->SetField(iIndex, ESqlReal, &aValue, sizeof(TReal));
       
   188 	}
       
   189 	
       
   190 /**
       
   191 Initializes current flat buffer field with a block of binary data.
       
   192 
       
   193 @param aValue An 8 bit descriptor pointing to the block of data to be set as a field content.
       
   194 
       
   195 @return KErrNone, The operation has completed successfully;
       
   196 		KErrNoMemory, Out of memory condition has occured.
       
   197 */
       
   198 inline TInt TSqlBufWIterator::SetBinary(const TDesC8& aValue)
       
   199 	{
       
   200 	__SQLASSERT(iBuf != NULL, ESqlPanicInternalError);
       
   201 	__SQLASSERT((TUint)iIndex < iBuf->Count(), ESqlPanicInternalError);
       
   202 	return iBuf->SetField(iIndex, ESqlBinary, aValue.Ptr(), aValue.Length());
       
   203 	}
       
   204 	
       
   205 /**
       
   206 Initializes current flat buffer field with a block of 16 bit text.
       
   207 
       
   208 @param aValue A 16 bit descriptor pointing to the block of text to be set as a field content.
       
   209 
       
   210 @return KErrNone, The operation has completed successfully;
       
   211 		KErrNoMemory, Out of memory condition has occured.
       
   212 */
       
   213 inline TInt TSqlBufWIterator::SetText(const TDesC16& aValue)
       
   214 	{
       
   215 	__SQLASSERT(iBuf != NULL, ESqlPanicInternalError);
       
   216 	__SQLASSERT((TUint)iIndex < iBuf->Count(), ESqlPanicInternalError);
       
   217 	return iBuf->SetField(iIndex, ESqlText, aValue.Ptr(), aValue.Length() * sizeof(TUint16));
       
   218 	}
       
   219 
       
   220 	
       
   221 /**
       
   222 Initializes current flat buffer field with a zeroblob of the specified size.
       
   223 
       
   224 @param aSize The size, in bytes, of the zeroblob to be set as the field content.
       
   225 
       
   226 @return KErrNone, The operation has completed successfully;
       
   227 		KErrNoMemory, Out of memory condition has occured.
       
   228 */
       
   229 inline TInt TSqlBufWIterator::SetZeroBlob(TInt aSize)
       
   230 	{
       
   231 	__SQLASSERT(iBuf != NULL, ESqlPanicInternalError);
       
   232 	__SQLASSERT((TUint)iIndex < iBuf->Count(), ESqlPanicInternalError);
       
   233 	return iBuf->SetField(iIndex, ESqlZeroBlob, &aSize, sizeof(TInt));
       
   234 	}