sl@0: /*
sl@0: * Copyright (c) 2005-2009 Nokia Corporation and/or its subsidiary(-ies).
sl@0: * All rights reserved.
sl@0: * This component and the accompanying materials are made available
sl@0: * under the terms of "Eclipse Public License v1.0"
sl@0: * which accompanies this distribution, and is available
sl@0: * at the URL "http://www.eclipse.org/legal/epl-v10.html".
sl@0: *
sl@0: * Initial Contributors:
sl@0: * Nokia Corporation - initial contribution.
sl@0: *
sl@0: * Contributors:
sl@0: *
sl@0: * Description:  Base class for all objects created by backend
sl@0: *
sl@0: */
sl@0: 
sl@0: 
sl@0: #ifndef BASE_H
sl@0: #define BASE_H
sl@0: 
sl@0: #include "sysif.h"
sl@0: 
sl@0: class BBase : public CBase
sl@0: 	{
sl@0: public:
sl@0: 	/*
sl@0: 	Default constructor
sl@0: 	*/
sl@0: 	inline BBase()	{}
sl@0: 	virtual ~BBase() { }
sl@0: 	
sl@0: 	/* *****************************************************************
sl@0: 	Overloading new and delete operators so that they will
sl@0: 	allocate and deallocare memory from/to the private heap of backend
sl@0: 	********************************************************************/
sl@0: 	inline TAny* operator new(TUint aSize, TAny* aBase) __NO_THROW
sl@0: 		{
sl@0: 		Mem::FillZ(aBase, aSize); return aBase;
sl@0: 		}
sl@0: 		
sl@0: 	inline TAny* operator new(TUint aSize) __NO_THROW
sl@0: 		{
sl@0: 		return Backend()->Alloc(aSize);
sl@0: 		}
sl@0: 		
sl@0: 	inline TAny* operator new(TUint aSize, TLeave)
sl@0: 		{
sl@0: 		TAny* ptr = Backend()->Alloc(aSize);
sl@0: 		if (ptr == NULL)
sl@0: 			{
sl@0: 			User::Leave(KErrNoMemory);
sl@0: 			}
sl@0: 		return ptr;
sl@0: 		}
sl@0: 		
sl@0: 	inline TAny* operator new(TUint aSize, TUint aExtraSize) __NO_THROW
sl@0: 		{
sl@0: 		return Backend()->Alloc(aSize + aExtraSize);
sl@0: 		}
sl@0: 		
sl@0: 	inline TAny* operator new(TUint aSize, TLeave, TUint aExtraSize)
sl@0: 		{
sl@0: 		TAny* ptr = Backend()->Alloc(aSize + aExtraSize);
sl@0: 		if (ptr == NULL)
sl@0: 			{
sl@0: 			User::Leave(KErrNoMemory);
sl@0: 			}
sl@0: 		return ptr;
sl@0: 		}
sl@0: 		
sl@0: /*corresponding overloaded delete operators	*/
sl@0: 
sl@0: 	inline void operator delete(TAny *aPtr, TAny*) __NO_THROW
sl@0: 		{
sl@0: 		Backend()->Free( aPtr );
sl@0: 		}
sl@0: 		
sl@0: 	inline void operator delete(TAny *aPtr) __NO_THROW
sl@0: 		{
sl@0: 		Backend()->Free( aPtr );
sl@0: 		}
sl@0: 		
sl@0: 	inline void operator delete(TAny *aPtr, TLeave) 
sl@0: 		{
sl@0: 		Backend()->Free( aPtr );
sl@0: 		}
sl@0: 		
sl@0: 	inline void operator delete(TAny *aPtr, TUint) __NO_THROW
sl@0: 		{
sl@0: 		Backend()->Free( aPtr );
sl@0: 		}
sl@0: 		
sl@0: 	inline void operator delete(TAny *aPtr, TLeave, TUint) 
sl@0: 		{
sl@0: 		Backend()->Free( aPtr );
sl@0: 		}
sl@0: 		
sl@0: 	static void Delete(BBase* aPtr)
sl@0: 		{
sl@0: 		delete aPtr;
sl@0: 		}
sl@0: 		
sl@0: /*
sl@0: protected:
sl@0: 	virtual TInt Extension_(TUint aExtensionId, TAny*& a0, TAny* a1)
sl@0: 		{
sl@0: 		a0 = NULL;
sl@0: 		return KErrExtensionNotSupported;
sl@0: 		}*/
sl@0: 		
sl@0: private:
sl@0: 	BBase(const BBase&);
sl@0: 	BBase& operator=(const CBase&);
sl@0: 	};
sl@0: 
sl@0: 
sl@0: #endif //BASE_H