servicediscoveryandcontrol/pnp/test/upnp/chunkmgr/inc/rmemchunk.h
changeset 0 f5a58ecadc66
equal deleted inserted replaced
-1:000000000000 0:f5a58ecadc66
       
     1 // Copyright (c) 2008-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 // @file
       
    15 // @internalComponent
       
    16 // 
       
    17 //
       
    18 
       
    19 #ifndef __RMEMCHUNK_
       
    20 #define __RMEMCHUNK_
       
    21 
       
    22 #include <e32base.h>
       
    23 #include <cchunkmanager.h>
       
    24 
       
    25 //forward Declaration
       
    26 class RMemoryAllocator;
       
    27 
       
    28 class RMemChunk
       
    29 	{
       
    30 public:
       
    31 	inline RMemChunk ()
       
    32 		{
       
    33 		iNextCell = NULL;
       
    34 		}
       
    35 		
       
    36 	IMPORT_C TInt Alloc ( TInt aSize, RMemoryAllocator& aAllocator );
       
    37 	IMPORT_C TInt Create ( const TDesC8& aDes, RMemoryAllocator& aAllocator );
       
    38 	IMPORT_C void CreateL ( const TDesC8& aDes,RMemoryAllocator& aAllocator );
       
    39 	IMPORT_C void Free ();
       
    40 	IMPORT_C RMemCell* Remove();
       
    41 	IMPORT_C TInt NumBufs() const;
       
    42 	IMPORT_C TInt Length() const;
       
    43 	IMPORT_C void TrimStart(TInt anOffset);
       
    44 	IMPORT_C void CopyIn(const TDesC8& aDes, TInt aOffset=0);
       
    45 	IMPORT_C void CopyOut(TDes8 &aDes, TInt aOffset=0) const;
       
    46 	IMPORT_C TBool Goto(TInt anOffset, RMemCell* &resBuf, TInt& resOffset, TInt& resLength, RMemCell* &resPrevBuf) const;
       
    47 	IMPORT_C void Assign(RMemChunk& aChain);
       
    48 	IMPORT_C void Append(RMemChunk& aChain);
       
    49 	IMPORT_C RMemCell* Last() const;
       
    50 	inline RMemCell* First ();
       
    51 	inline TBool IsEmpty() const;
       
    52 	inline void Init();
       
    53 	
       
    54 private:
       
    55 	RMemCell*	iNextCell;
       
    56 	};
       
    57 	
       
    58 inline TBool RMemChunk::IsEmpty() const
       
    59 	{ 
       
    60 	return iNextCell==NULL; 
       
    61 	}
       
    62 
       
    63 inline void RMemChunk::Init()
       
    64 	{ 
       
    65 	iNextCell = NULL;	
       
    66 	}
       
    67 
       
    68 class RMemoryAllocator
       
    69 	{
       
    70 public:
       
    71 	RMemoryAllocator ( CChunkManager* aManager )
       
    72 		: iManager ( aManager )
       
    73 		{	}
       
    74 	
       
    75 	CChunkManager* ChunkManager ()
       
    76 		{
       
    77 		return iManager;
       
    78 		}
       
    79 	
       
    80 	RMemoryAllocator (  )
       
    81 		: iManager ( NULL )
       
    82 			{	}
       
    83 	
       
    84 	void SetChunkManager (CChunkManager* aChunkMgr)
       
    85 		{
       
    86 		iManager = aChunkMgr;
       
    87 		}
       
    88 private:
       
    89 	CChunkManager* iManager;	
       
    90 	};	
       
    91 
       
    92 inline RMemCell* RMemChunk::First ()
       
    93 	{
       
    94 	return iNextCell;
       
    95 	}
       
    96 	
       
    97 
       
    98 class TMemCellIterator
       
    99 	{
       
   100 	public:
       
   101 		TMemCellIterator();
       
   102 		inline TMemCellIterator(RMemCell* aChain);
       
   103 		inline TMemCellIterator(RMemChunk& aMemChunk);
       
   104 		IMPORT_C RMemCell* operator++(TInt);
       
   105 	private:
       
   106 		RMemCell* iMemCell;
       
   107 		
       
   108 	};
       
   109 
       
   110 inline TMemCellIterator::TMemCellIterator(RMemChunk& aMemChunk)
       
   111 	: iMemCell(aMemChunk.First()) 
       
   112 	{ }
       
   113 
       
   114 inline TMemCellIterator::TMemCellIterator(RMemCell* aChain)
       
   115 	: iMemCell(aChain)
       
   116 	{ }
       
   117 
       
   118 #endif /*__RMEMCHUNK_*/