smsprotocols/smsstack/gsmu/src/gsmubuf.cpp
changeset 0 3553901f7fa8
equal deleted inserted replaced
-1:000000000000 0:3553901f7fa8
       
     1 // Copyright (c) 2001-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 // This file contains the implementation of the SMS buffer
       
    15 // 
       
    16 //
       
    17 
       
    18 /**
       
    19  @file
       
    20 */
       
    21 
       
    22 #include "gsmubuf.h"
       
    23 #include "Gsmumain.h"
       
    24 
       
    25 #include <txtetext.h>
       
    26 
       
    27 
       
    28 /**
       
    29  *  Internalises the object.
       
    30  *  
       
    31  *  @param aStream Stream to read from
       
    32  *  @capability None
       
    33  */
       
    34 EXPORT_C void CSmsBufferBase::InternalizeL(RReadStream& aStream)
       
    35 	{
       
    36 	Reset();
       
    37 	TInt length=aStream.ReadInt32L();
       
    38 	TBuf<EMaxBufLength> buf;
       
    39 	for (TInt pos=0; pos<length; pos+=EMaxBufLength)
       
    40 		{
       
    41 		TInt buflength=(pos+EMaxBufLength)<=length? EMaxBufLength: length-pos;
       
    42 		aStream.ReadL(buf,buflength);
       
    43 		InsertL(pos,buf);
       
    44 		}
       
    45 	} // CSmsBufferBase::InternalizeL
       
    46 
       
    47 
       
    48 /**
       
    49  *  Externalises the object.
       
    50  *  
       
    51  *  @param aStream Stream to write to
       
    52  *  @capability None
       
    53  */
       
    54 EXPORT_C void CSmsBufferBase::ExternalizeL(RWriteStream& aStream) const
       
    55 	{
       
    56 	TInt length=Length();
       
    57 	aStream.WriteInt32L(length);
       
    58 	for (TInt pos=0; pos<length; pos+=EMaxBufLength)
       
    59 		{
       
    60 		TBuf<EMaxBufLength> buf;
       
    61 		TInt buflength=(pos+EMaxBufLength)<=length? EMaxBufLength: length-pos;
       
    62 		Extract(buf,pos,buflength);
       
    63 		aStream.WriteL(buf,buflength);
       
    64 		}
       
    65 	} // CSmsBufferBase::ExternalizeL
       
    66 
       
    67 
       
    68 /**
       
    69  *  Allocates and constructs the buffer.
       
    70  *  
       
    71  *  @return New CSmsBuffer object
       
    72  *  @capability None
       
    73  */
       
    74 EXPORT_C CSmsBuffer* CSmsBuffer::NewL()
       
    75 	{
       
    76 	CSmsBuffer* smsbuffer=new(ELeave) CSmsBuffer();
       
    77 	CleanupStack::PushL(smsbuffer);
       
    78 	smsbuffer->iBuffer=new(ELeave) CArrayFixSeg<TText>(EMaxBufLength);
       
    79 	CleanupStack::Pop();
       
    80 	return smsbuffer;
       
    81 	} // CSmsBuffer::NewL
       
    82 
       
    83 
       
    84 /**
       
    85  *  Destructor, frees resource.
       
    86  *  @capability None
       
    87  */
       
    88 EXPORT_C CSmsBuffer::~CSmsBuffer()
       
    89 	{
       
    90     delete iBuffer;
       
    91     } // CSmsBuffer::NewL
       
    92 
       
    93 
       
    94 /**
       
    95  *  Gets the amount of space currently used in the buffer.
       
    96  *  
       
    97  *  @return Amount of space currently used in the buffer
       
    98  *  @capability None
       
    99  */
       
   100 EXPORT_C TInt CSmsBuffer::Length() const
       
   101 	{
       
   102 	return iBuffer->Count();
       
   103 	} // CSmsBuffer::Length
       
   104 
       
   105 
       
   106 /**
       
   107  *  Extracts buffer data to a descriptor.
       
   108  *  
       
   109  *  @param aBuf On return, buffer data
       
   110  *  @param aPos Position within buffer to begin reading
       
   111  *  @param aLength The amount of data to read from the buffer
       
   112  *  @capability None
       
   113  */
       
   114 EXPORT_C void CSmsBuffer::Extract(TDes& aBuf,TInt aPos,TInt aLength) const
       
   115 	{
       
   116 	aBuf.SetLength(aLength);
       
   117 	for (TInt i=0; i<aLength; i++)
       
   118 		aBuf[i]=iBuffer->At(aPos+i);
       
   119 	} // CSmsBuffer::Extract
       
   120 
       
   121 
       
   122 /**
       
   123  *  Inserts data into the buffer.
       
   124  *  
       
   125  *  @param aPos Position in the buffer to insert the data
       
   126  *  @param aBuf The data to insert into the buffer
       
   127  *  @capability None
       
   128  */
       
   129 EXPORT_C void CSmsBuffer::InsertL(TInt aPos,const TDesC& aBuf)
       
   130 	{
       
   131 	iBuffer->InsertL(aPos,aBuf.Ptr(),aBuf.Length());
       
   132 	} // CSmsBuffer::InsertL
       
   133 
       
   134 
       
   135 /**
       
   136  *  Deletes data from the buffer.
       
   137  *  
       
   138  *  @param aPos Position in the buffer to delete the data
       
   139  *  @param aLength The amount of data to delete from the buffer
       
   140  *  @capability None
       
   141  */
       
   142 EXPORT_C void CSmsBuffer::DeleteL(TInt aPos,TInt aLength)
       
   143 	{
       
   144 	iBuffer->Delete(aPos,aLength);
       
   145 	} // CSmsBuffer::DeleteL
       
   146 
       
   147 
       
   148 /**
       
   149  *  Resets the buffer.
       
   150  *  @capability None
       
   151  */
       
   152 EXPORT_C void CSmsBuffer::Reset()
       
   153 	{
       
   154 	iBuffer->Reset();
       
   155 	} // CSmsBuffer::Reset
       
   156 
       
   157 
       
   158 CSmsBuffer::CSmsBuffer()
       
   159 	{
       
   160 	// NOP
       
   161 	} // CSmsBuffer::CSmsBuffer
       
   162 
       
   163 
       
   164 /**
       
   165  *  Allocates and constructs the buffer.
       
   166  *  
       
   167  *  @param aText Text object to use as buffer
       
   168  *  @return New CSmsEditorBuffer object
       
   169  *  @capability None
       
   170  */
       
   171 EXPORT_C CSmsEditorBuffer* CSmsEditorBuffer::NewL(CEditableText& aText)
       
   172 	{
       
   173 	CSmsEditorBuffer* smseditorbuffer=new(ELeave) CSmsEditorBuffer(aText);
       
   174 	CleanupStack::PushL(smseditorbuffer);
       
   175 	CleanupStack::Pop();
       
   176 	return smseditorbuffer;
       
   177 	} // CSmsEditorBuffer::NewL
       
   178 
       
   179 
       
   180 /**
       
   181  *  Destructor.
       
   182  *  @capability None
       
   183  */
       
   184 EXPORT_C CSmsEditorBuffer::~CSmsEditorBuffer()
       
   185 	{
       
   186 	// NOP
       
   187     } // CSmsEditorBuffer::NewL
       
   188 
       
   189 
       
   190 /**
       
   191  *  Gets the number of characters in the buffer.
       
   192  *  
       
   193  *  @return The number of characters in the buffer.
       
   194  *  @capability None
       
   195  */
       
   196 EXPORT_C TInt CSmsEditorBuffer::Length() const
       
   197 	{
       
   198 	return iText.DocumentLength();
       
   199 	} // CSmsEditorBuffer::Length
       
   200 
       
   201 
       
   202 /**
       
   203  *  Extracts buffer data to a descriptor.
       
   204  *  
       
   205  *  @param aBuf On return, buffer data
       
   206  *  @param aPos Position within buffer to begin reading
       
   207  *  @param aLength The amount of data to read from the buffer
       
   208  *  @capability None
       
   209  */
       
   210 EXPORT_C void CSmsEditorBuffer::Extract(TDes& aBuf,TInt aPos,TInt aLength) const
       
   211 	{
       
   212 	iText.Extract(aBuf,aPos,aLength);
       
   213 	} // CSmsEditorBuffer::Extract
       
   214 
       
   215 
       
   216 /**
       
   217  *  Inserts data into the buffer.
       
   218  *  
       
   219  *  @param aPos Position in the buffer to insert the data
       
   220  *  @param aBuf The data to insert into the buffer
       
   221  *  @capability None
       
   222  */
       
   223 EXPORT_C void CSmsEditorBuffer::InsertL(TInt aPos,const TDesC& aBuf)
       
   224 	{
       
   225 	iText.InsertL(aPos,aBuf);
       
   226 	} // CSmsEditorBuffer::InsertL
       
   227 
       
   228 
       
   229 /**
       
   230  *  Deletes data from the buffer.
       
   231  *  
       
   232  *  @param aPos Position in the buffer to delete the data
       
   233  *  @param aLength The amount of data to delete from the buffer
       
   234  *  @capability None
       
   235  */
       
   236 EXPORT_C void CSmsEditorBuffer::DeleteL(TInt aPos,TInt aLength)
       
   237 	{
       
   238 	iText.DeleteL(aPos,aLength);
       
   239 	} // CSmsEditorBuffer::DeleteL
       
   240 
       
   241 
       
   242 /**
       
   243  *  Reset the buffer.
       
   244  *  @capability None
       
   245  */
       
   246 EXPORT_C void CSmsEditorBuffer::Reset()
       
   247 	{
       
   248 	iText.Reset();
       
   249 	} // CSmsEditorBuffer::Reset
       
   250 
       
   251 
       
   252 CSmsEditorBuffer::CSmsEditorBuffer(CEditableText& aText):
       
   253     iText(aText)
       
   254     {
       
   255     // NOP
       
   256     } // CSmsEditorBuffer::CSmsEditorBuffer