epoc32/include/test/testshareddata.inl
branchSymbian2
changeset 2 2fe1408b6811
child 4 837f303aceeb
equal deleted inserted replaced
1:666f914201fb 2:2fe1408b6811
       
     1 /*
       
     2 * Copyright (c) 2005-2009 Nokia Corporation and/or its subsidiary(-ies). 
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of the License "Symbian Foundation License v1.0" to Symbian Foundation members and "Symbian Foundation End User License Agreement v1.0" to non-members
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.symbianfoundation.org/legal/licencesv10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description: 
       
    15 * Implementation of Test structured data class for sharing between process
       
    16 * Initialises the member variable with zero
       
    17 *
       
    18 */
       
    19 
       
    20 
       
    21 /**
       
    22  @file TestSharedData.cpp
       
    23 */
       
    24 void CTestSharedData::Construct()
       
    25 	{
       
    26 	// Initialise the data member
       
    27 	for (TInt index = 0; index < KMaxSharedDataLength; index++)
       
    28 		{
       
    29 		iText[index] = 0;
       
    30 		}
       
    31 	}
       
    32 
       
    33 /**
       
    34  * Copies the data input to the shared TText member for sharing
       
    35  * @param aVal - Descriptor containing the string to be set to the member data
       
    36  */
       
    37 void CTestSharedData::SetText(TDesC& aVal)
       
    38 	{
       
    39 	TInt length = aVal.Length();
       
    40 	if (length < KMaxSharedDataLength)
       
    41 		{
       
    42 		for (TInt index = 0; index < length; index++)
       
    43 			{
       
    44 			iText[index] = *(aVal.Mid(index,1).Ptr());
       
    45 			}
       
    46 		for (TInt nullIndex = length; nullIndex < KMaxSharedDataLength; nullIndex++)
       
    47 			{
       
    48 			iText[nullIndex] = 0;
       
    49 			}
       
    50 		}
       
    51 	else
       
    52 		{
       
    53 		User::Panic(_L("OutOfMemory"), KErrNoMemory);
       
    54 		}
       
    55 	}
       
    56 
       
    57 /**
       
    58  * Appends the data input to the shared TText for sharing
       
    59  * @param aVal - Descriptor containing the string to be appended to the member data
       
    60  */
       
    61 void CTestSharedData::AppendText(TDesC& aVal)
       
    62 	{
       
    63 	TInt appendLength = aVal.Length();
       
    64 	TInt originalLength = User::StringLength(iText);;
       
    65 	TInt length = originalLength + appendLength;
       
    66 	if (length < KMaxSharedDataLength)
       
    67 		{
       
    68 		TInt midLocation = 0;
       
    69 		for (TInt index = originalLength; index < length; index++)
       
    70 			{
       
    71 			iText[index] = *(aVal.Mid(midLocation,1).Ptr());
       
    72 			midLocation++;
       
    73 			}
       
    74 		for (TInt nullIndex = length; nullIndex < KMaxSharedDataLength; nullIndex++)
       
    75 			{
       
    76 			iText[nullIndex] = 0;
       
    77 			}
       
    78 		}
       
    79 	else
       
    80 		{
       
    81 		User::Panic(_L("OutOfMemory"), KErrNoMemory);
       
    82 		}
       
    83 	}
       
    84 
       
    85 /**
       
    86  * Copies the value within member data to the descriptor reference passed in
       
    87  * @param aVal - Reference Descriptor which gets set with member data value
       
    88  */
       
    89 void CTestSharedData::GetText(TDes& aVal)
       
    90 	{
       
    91 	TInt length = User::StringLength(iText);
       
    92 	TInt bufferLength = aVal.MaxLength();
       
    93 	if (bufferLength < length)
       
    94 		{
       
    95 		User::Panic(_L("OutOfMemory"), KErrNoMemory);
       
    96 		}
       
    97 
       
    98 	aVal.Zero();
       
    99 	for (TInt index = 0; index < length; index++)
       
   100 		{
       
   101 		aVal.Append(iText[index]);
       
   102 		}
       
   103 	}