00001 #include "common/epoc_rs_buf8.hpp" 00002 00003 // See Symbian's ossrv/lowlevellibsandfws/genericusabilitylib/ for the 00004 // EUserHL code. 00005 00006 void RRsBuf8::CopyL(const TDesC8 &aDes) 00007 { 00008 ReserveL(aDes.Length()); 00009 RBuf8::Copy(aDes); 00010 } 00011 00012 void RRsBuf8::CopyL(const TUint8 *aZeroTerminatedString) 00013 { 00014 TInt len = User::StringLength(aZeroTerminatedString); 00015 ReserveL(len); 00016 RBuf8::Copy(aZeroTerminatedString, len); 00017 } 00018 00019 void RRsBuf8::CopyL(const TUint8 *aBuf, TInt aLength) 00020 { 00021 ReserveL(aLength); 00022 RBuf8::Copy(aBuf, aLength); 00023 } 00024 00025 void RRsBuf8::AppendL(const TDesC8 &aDes) 00026 { 00027 ReserveFreeCapacityL(aDes.Length()); 00028 RBuf8::Append(aDes); 00029 } 00030 00031 void RRsBuf8::AppendL(const TUint8 *aZeroTerminatedString) 00032 { 00033 TInt len = User::StringLength(aZeroTerminatedString); 00034 ReserveFreeCapacityL(len); 00035 RBuf8::Append(aZeroTerminatedString, len); 00036 } 00037 00038 void RRsBuf8::AppendL(const TUint8 *aBuf, TInt aLength) 00039 { 00040 ReserveFreeCapacityL(aLength); 00041 RBuf8::Append(aBuf, aLength); 00042 } 00043 00044 const TUint8 *RRsBuf8::PtrZL() 00045 { 00046 ReserveFreeCapacityL(1); 00047 return RBuf8::PtrZ(); 00048 } 00049 00050 /** 00051 Aligns the supplied capacity to the nearest growth factor 00052 00053 For performance reasons the growth factor, KDefaultExpandSizeShift, 00054 is expressed as an exponent of 2 so shifting can be used to achieve the 00055 alignment. 00056 00057 a KDefaultExpandSizeShift value of 4 is equivalent to 16; 00058 giving newCapacity = ((newCapacity / 16) + 1) * 16 00059 00060 @param aNewCapacity The size to be aligned 00061 00062 @return The new, aligned capacity 00063 */ 00064 static inline TInt AlignCapacity(TInt aNewCapacity) 00065 { 00066 const TUint KDefaultExpandSizeShift = 4; 00067 00068 return (TInt)((((TUint)aNewCapacity >> KDefaultExpandSizeShift) + 1) 00069 << KDefaultExpandSizeShift); 00070 } 00071 00072 /** 00073 Guarantees that MaxLength() is greater than or equal to the supplied 00074 capacity, reallocating the supplied capacity if necessary. 00075 00076 The actual value of MaxLength() after a call may differ from the exact 00077 value requested, but if it does differ it will always be greater. This 00078 flexibility allows the implementation to manage heap buffers more 00079 efficiently. 00080 00081 The string descriptor's heap buffer may be reallocated in order to 00082 accommodate the new size. As a 00083 result, MaxLength() and Ptr() may return different values afterwards, 00084 and any existing raw pointers to into the descriptor data may be 00085 invalidated. 00086 00087 @param aMinRequiredCapacity The minimum value of MaxLength() required 00088 00089 @leave KErrNoMemory if the underlying buffer needs to be 00090 grown and there are insufficient resources to do so 00091 */ 00092 void RRsBuf8::ReserveL(TInt aMinRequiredCapacity) 00093 { 00094 if (MaxLength() < aMinRequiredCapacity) 00095 { 00096 ReAllocL(AlignCapacity(aMinRequiredCapacity)); 00097 } 00098 } 00099 00100 /** 00101 Ensures that the remaining unused space is more than the supplied value. 00102 00103 May reallocate a larger storage space to meet the requirement. 00104 As a result MaxLength() and Ptr() may return different values afterwards, 00105 and any existing raw pointers to into the descriptor data may be 00106 invalidated. 00107 00108 Typically, you use this method to reserve a known amount of required space 00109 in one go instead of relying on the automatic growth pattern. 00110 00111 @param aExtraSpaceLength The extra space required. 00112 00113 @leave KErrNoMemory if the the buffer needs to be 00114 reallocated and there are insufficient resources to do so. 00115 00116 @panic USER 11 if aLength is negative 00117 */ 00118 void RRsBuf8::ReserveFreeCapacityL(TInt aExtraSpaceLength) 00119 { 00120 ReserveL(Length() + aExtraSpaceLength); 00121 } 00122 00123 // Adapted from estring.h of EUserHL, hence this license applies. 00124 // 00125 // Copyright (c) 2008-2009 Nokia Corporation and/or its subsidiary(-ies). 00126 // All rights reserved. 00127 // This component and the accompanying materials are made available 00128 // under the terms of "Eclipse Public License v1.0" 00129 // which accompanies this distribution, and is available 00130 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
ContextLogger2—ContextLogger2 Logger Daemon Internals—Generated on Mon May 2 13:49:52 2011 by Doxygen 1.6.1