secureswitools/swisistools/source/sisxlibrary/counterbase.h
changeset 0 ba25891c3a9e
equal deleted inserted replaced
-1:000000000000 0:ba25891c3a9e
       
     1 /*
       
     2 * Copyright (c) 2007-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 the License "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: 
       
    15 * Note: This file may contain code to generate corrupt files for test purposes.
       
    16 * Such code is excluded from production builds by use of compiler defines;
       
    17 * it is recommended that such code should be removed if this code is ever published publicly.
       
    18 * part of smart pointers. See CElement.
       
    19 *
       
    20 */
       
    21 
       
    22 
       
    23 /**
       
    24  @file 
       
    25  @internalComponent
       
    26  @released
       
    27 */
       
    28 
       
    29 #ifndef __COUNTERBASE_H__
       
    30 #define __COUNTERBASE_H__
       
    31 
       
    32 #include "utility_interface.h"
       
    33 #include <assert.h>
       
    34 #include "basetype.h"
       
    35 
       
    36 
       
    37 
       
    38 class CCounterBase
       
    39 	{
       
    40 public:
       
    41     CCounterBase ();
       
    42     virtual ~CCounterBase ();
       
    43     virtual void Dispose () = 0; 
       
    44     virtual void Destruct ();
       
    45     void AddRef ();
       
    46     void Release (); 
       
    47     long UseCount () const;
       
    48 private:
       
    49     CCounterBase (CCounterBase const&);
       
    50     CCounterBase& operator = (CCounterBase const&);
       
    51 private:
       
    52     long iUseCount;
       
    53 	};
       
    54 
       
    55 
       
    56 
       
    57 inline CCounterBase::CCounterBase () : 
       
    58 		iUseCount (1)
       
    59 	{
       
    60 	}
       
    61 
       
    62 inline CCounterBase::~CCounterBase ()
       
    63 	{ 
       
    64 	}
       
    65 
       
    66 inline void CCounterBase::Destruct ()
       
    67 	{ 
       
    68 	delete this; 
       
    69 	}
       
    70 
       
    71 inline void CCounterBase::AddRef ()
       
    72 	{
       
    73     assert (iUseCount != 0);
       
    74 	++iUseCount;
       
    75 	}
       
    76 
       
    77 inline void CCounterBase::Release () 
       
    78 	{
       
    79 	if (--iUseCount) 
       
    80 		{
       
    81 		return;
       
    82 		}
       
    83     Dispose ();
       
    84     Destruct ();
       
    85 	}
       
    86 
       
    87 inline long CCounterBase::UseCount () const
       
    88 	{ 
       
    89 	return iUseCount; 
       
    90 	}
       
    91 
       
    92 #endif // __COUNTERBASE_H__