secureswitools/swisistools/source/rscparser/commontypes.cpp
branchRCL_3
changeset 25 7333d7932ef7
equal deleted inserted replaced
24:5cc91383ab1e 25:7333d7932ef7
       
     1 // Copyright (c) 2009 - 2010 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 * @file commontypes.cpp
       
    17 *
       
    18 * @internalComponent
       
    19 * @released
       
    20 */
       
    21 #include "commontypes.h"
       
    22 #include "barsc2.h"
       
    23 #include <cassert>
       
    24 
       
    25 /** 
       
    26  Implementation of Class Ptr8
       
    27 */
       
    28 
       
    29 Ptr8::Ptr8(const TUint32& aSize)
       
    30 		:iLength(0), iMaxLength(aSize)		
       
    31 {
       
    32 	iPtr= new TUint8[aSize];
       
    33 }
       
    34 
       
    35 Ptr8::~Ptr8()
       
    36 {
       
    37 	delete iPtr;
       
    38 	iPtr=0;
       
    39 }
       
    40 
       
    41 
       
    42 TUint8 Ptr8::operator[](TInt aIndex) const
       
    43 {
       
    44 	assert(aIndex>=0);
       
    45 	return(iPtr[aIndex]);
       
    46 
       
    47 }
       
    48 
       
    49 TUint8* Ptr8::GetPtr() const 
       
    50 {
       
    51 	return iPtr;
       
    52 }
       
    53 
       
    54 void Ptr8::SetPtr(TUint8* aPtr)
       
    55 {
       
    56 	iPtr=aPtr;
       
    57 }
       
    58 
       
    59 void Ptr8::ForceLength(const TUint32& aLength)
       
    60 {
       
    61 		iLength = aLength;
       
    62 }
       
    63 
       
    64 void Ptr8::SetLength(const TUint32& aLength)
       
    65 {
       
    66 	if ((iLength+aLength) <= iMaxLength)
       
    67 	{
       
    68 		iLength = aLength;
       
    69 		return 0;
       
    70 	}
       
    71 	else
       
    72 	{
       
    73 		return 1;	
       
    74 	}
       
    75 }
       
    76 	
       
    77 TBool Ptr8::UpdateLength(const TUint32& aLength) 
       
    78 {
       
    79 	// Current length should not increase the 
       
    80 	// Max length.
       
    81 	if ((iLength+aLength) <= iMaxLength)
       
    82 	{
       
    83 		iLength+= aLength;
       
    84 		return 0;
       
    85 	}
       
    86 	else
       
    87 	{
       
    88 		return 1;	
       
    89 	}
       
    90 }
       
    91 
       
    92 TUint32 Ptr8::GetLength() const 
       
    93 {
       
    94 	return iLength;
       
    95 }
       
    96 
       
    97 TUint32 Ptr8::GetMaxLength() const 
       
    98 {
       
    99 	return iMaxLength;
       
   100 }
       
   101 
       
   102 void Ptr8::Append(TUint8* aBuffer, TInt aLen)
       
   103 {
       
   104 	if ((iLength+aLen) <= iMaxLength)
       
   105 	{
       
   106 		memcpy(iPtr+iLength,aBuffer, aLen);
       
   107 		iLength+= aLen;
       
   108 	}
       
   109 	else
       
   110 	{
       
   111 		std::string errMsg= "Failed : Cannot Append Beyond Maximum Length";
       
   112 		throw CResourceFileException(errMsg);	
       
   113 	}
       
   114 }
       
   115 
       
   116 /** 
       
   117  Implementation of Class Ptr16
       
   118 */
       
   119 
       
   120 Ptr16::Ptr16(const TUint32& aSize)
       
   121 		:iLength(0), iMaxLength(aSize)		
       
   122 {
       
   123 	iPtr= new TUint16[aSize];
       
   124 }
       
   125 
       
   126 Ptr16::~Ptr16()
       
   127 {
       
   128 	delete iPtr;
       
   129 	iPtr=0;
       
   130 }
       
   131 
       
   132 TUint16* Ptr16::GetPtr() const 
       
   133 {
       
   134 	return iPtr;
       
   135 }
       
   136 
       
   137 void Ptr16::SetPtr(TUint16* aPtr)
       
   138 {
       
   139 	iPtr=aPtr;
       
   140 }
       
   141 
       
   142 TUint16 Ptr16::operator[](TInt aIndex) const
       
   143 {
       
   144 	assert(aIndex>=0);
       
   145 	return(iPtr[aIndex]);
       
   146 }
       
   147 
       
   148 TBool Ptr16::UpdateLength(const TUint32& aLength) 
       
   149 {
       
   150 	// Current length should not increase the 
       
   151 	// Max length.
       
   152 	if ((iLength+aLength) <= iMaxLength)
       
   153 	{
       
   154 		iLength+= aLength;
       
   155 		return 0;
       
   156 	}
       
   157 	else
       
   158 	{
       
   159 		return 1;	
       
   160 	}
       
   161 }
       
   162 
       
   163 TUint32 Ptr16::GetLength() const 
       
   164 {
       
   165 	return iLength;
       
   166 }
       
   167 
       
   168 /**
       
   169 Implementation of Sructure PtrC8
       
   170 */
       
   171 PtrC8::PtrC8():
       
   172 	iMaxLength(0)
       
   173 {	
       
   174 	iPtr = new TUint8;
       
   175 }
       
   176 
       
   177 /**
       
   178 Implementation of Sructure PtrC8
       
   179 */
       
   180 PtrC8::~PtrC8()
       
   181 {	
       
   182 	 delete (TUint8*) iPtr;
       
   183 	 iPtr = NULL;
       
   184 }
       
   185 
       
   186 /**
       
   187 Implementation of Sructure PtrC16
       
   188 */
       
   189 PtrC16::PtrC16():
       
   190 	iMaxLength(0)
       
   191 {	
       
   192 	iPtr = new TUint16;
       
   193 }
       
   194 
       
   195 /**
       
   196 Implementation of Sructure PtrC16
       
   197 */
       
   198 PtrC16::~PtrC16()
       
   199 {	
       
   200 	delete iPtr;
       
   201 	iPtr = NULL;
       
   202 }
       
   203 
       
   204 
       
   205 /**
       
   206  Implementation of Sructure TUid
       
   207 */
       
   208 	
       
   209 sTUid::sTUid():
       
   210 	iUid1(0), iUid2(0), iUid3(0)
       
   211 	{
       
   212 	}