os/ossrv/genericopenlibs/openenvcore/backend/inc/base.h
author sl
Tue, 10 Jun 2014 14:32:02 +0200
changeset 1 260cb5ec6c19
permissions -rw-r--r--
Update contrib.
     1 /*
     2 * Copyright (c) 2005-2009 Nokia Corporation and/or its subsidiary(-ies).
     3 * All rights reserved.
     4 * This component and the accompanying materials are made available
     5 * under the terms of "Eclipse Public License v1.0"
     6 * which accompanies this distribution, and is available
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
     8 *
     9 * Initial Contributors:
    10 * Nokia Corporation - initial contribution.
    11 *
    12 * Contributors:
    13 *
    14 * Description:  Base class for all objects created by backend
    15 *
    16 */
    17 
    18 
    19 #ifndef BASE_H
    20 #define BASE_H
    21 
    22 #include "sysif.h"
    23 
    24 class BBase : public CBase
    25 	{
    26 public:
    27 	/*
    28 	Default constructor
    29 	*/
    30 	inline BBase()	{}
    31 	virtual ~BBase() { }
    32 	
    33 	/* *****************************************************************
    34 	Overloading new and delete operators so that they will
    35 	allocate and deallocare memory from/to the private heap of backend
    36 	********************************************************************/
    37 	inline TAny* operator new(TUint aSize, TAny* aBase) __NO_THROW
    38 		{
    39 		Mem::FillZ(aBase, aSize); return aBase;
    40 		}
    41 		
    42 	inline TAny* operator new(TUint aSize) __NO_THROW
    43 		{
    44 		return Backend()->Alloc(aSize);
    45 		}
    46 		
    47 	inline TAny* operator new(TUint aSize, TLeave)
    48 		{
    49 		TAny* ptr = Backend()->Alloc(aSize);
    50 		if (ptr == NULL)
    51 			{
    52 			User::Leave(KErrNoMemory);
    53 			}
    54 		return ptr;
    55 		}
    56 		
    57 	inline TAny* operator new(TUint aSize, TUint aExtraSize) __NO_THROW
    58 		{
    59 		return Backend()->Alloc(aSize + aExtraSize);
    60 		}
    61 		
    62 	inline TAny* operator new(TUint aSize, TLeave, TUint aExtraSize)
    63 		{
    64 		TAny* ptr = Backend()->Alloc(aSize + aExtraSize);
    65 		if (ptr == NULL)
    66 			{
    67 			User::Leave(KErrNoMemory);
    68 			}
    69 		return ptr;
    70 		}
    71 		
    72 /*corresponding overloaded delete operators	*/
    73 
    74 	inline void operator delete(TAny *aPtr, TAny*) __NO_THROW
    75 		{
    76 		Backend()->Free( aPtr );
    77 		}
    78 		
    79 	inline void operator delete(TAny *aPtr) __NO_THROW
    80 		{
    81 		Backend()->Free( aPtr );
    82 		}
    83 		
    84 	inline void operator delete(TAny *aPtr, TLeave) 
    85 		{
    86 		Backend()->Free( aPtr );
    87 		}
    88 		
    89 	inline void operator delete(TAny *aPtr, TUint) __NO_THROW
    90 		{
    91 		Backend()->Free( aPtr );
    92 		}
    93 		
    94 	inline void operator delete(TAny *aPtr, TLeave, TUint) 
    95 		{
    96 		Backend()->Free( aPtr );
    97 		}
    98 		
    99 	static void Delete(BBase* aPtr)
   100 		{
   101 		delete aPtr;
   102 		}
   103 		
   104 /*
   105 protected:
   106 	virtual TInt Extension_(TUint aExtensionId, TAny*& a0, TAny* a1)
   107 		{
   108 		a0 = NULL;
   109 		return KErrExtensionNotSupported;
   110 		}*/
   111 		
   112 private:
   113 	BBase(const BBase&);
   114 	BBase& operator=(const CBase&);
   115 	};
   116 
   117 
   118 #endif //BASE_H