persistentstorage/sql/SRC/Server/SqlSrvObjContainer.h
changeset 0 08ec8eefde2f
child 23 26645d81f48d
equal deleted inserted replaced
-1:000000000000 0:08ec8eefde2f
       
     1 // Copyright (c) 2006-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 //
       
    15 
       
    16 #ifndef __SQLSRVOBJCONTAINER_H__
       
    17 #define __SQLSRVOBJCONTAINER_H__
       
    18 
       
    19 #include <e32std.h>
       
    20 #include "SqlPanic.h"
       
    21 
       
    22 /**
       
    23 Indexed storage for server sdide objects.
       
    24 
       
    25 RDbObjContainer container is used for storing IPC stream handles (HIpcStream) and 
       
    26 statement handles (CSqlSrvStatement).
       
    27 
       
    28 Behaviour when the container is destroyed:
       
    29  - all objects inside the container are destroyed too;
       
    30  
       
    31 Behaviour when the an object is removed from the container:
       
    32  - the container will destroy the object;
       
    33 
       
    34 Behaviour when the an object is added to the container:
       
    35  - the container stores the object <by_ref>, not <by_val>;
       
    36 
       
    37 Behaviour when a look up is performed in the container for an object:
       
    38  - a pointer to the object is returned or NULL if there is no object;
       
    39 
       
    40 @see CSqlSrvStatement
       
    41 @see HIpcStream
       
    42 @see RDbObjContainer::Close()
       
    43 @see RDbObjContainer::AllocL()
       
    44 @see RDbObjContainer::Add()
       
    45 @see RDbObjContainer::Remove()
       
    46 @see RDbObjContainer::Find()
       
    47 @see RDbObjContainer::Count()
       
    48 
       
    49 @internalComponent
       
    50 */
       
    51 template <class T> class RDbObjContainer
       
    52 	{
       
    53 public:
       
    54 	RDbObjContainer();
       
    55 	void Close();
       
    56 	void AllocL();
       
    57 	TInt Add(T* aObj);
       
    58 	void Remove(TInt aHandle);
       
    59 	T* Find(TInt aHandle) const;
       
    60 	TInt Count() const;
       
    61 
       
    62 private:	
       
    63 	TInt MakeHandle(TInt aIndex) const;
       
    64 	TInt MakeIndex(TInt aHandle) const;
       
    65 	
       
    66 private:	
       
    67 	struct TEntry
       
    68 		{
       
    69 		T*		iObj;
       
    70 		TInt	iNext;
       
    71 		};
       
    72 	enum {KGranularity = 16};
       
    73 	//KMaxSize value depends on how many bits are used for handles - see
       
    74 	//KStmtHandleMask and KStreamHandleMask in SqlUtil.h file.
       
    75 	enum {KMaxSize = 0x7FF};
       
    76 	TEntry*	iEntries;
       
    77 	TInt	iSize;
       
    78 	TInt 	iFree;
       
    79 	};
       
    80 
       
    81 #include "SqlSrvObjContainer.inl"
       
    82 
       
    83 #endif//__SQLSRVOBJCONTAINER_H__