tzpcside/tzcompiler/Include/PersistedEntityWrapper.h
changeset 0 2e3d3ce01487
equal deleted inserted replaced
-1:000000000000 0:2e3d3ce01487
       
     1 // Copyright (c) 2004-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 // DST TZ Database Compiler 
       
    15 // 
       
    16 //
       
    17 
       
    18 #ifndef __PERSISTED_ENTITY_WRAPPER_H
       
    19 #define __PERSISTED_ENTITY_WRAPPER_H
       
    20 
       
    21 #include <windows.h>
       
    22 #include <iostream>
       
    23 #include <fstream>
       
    24 #include "..\..\tz\Server\Include\tzpersisted.h"
       
    25 
       
    26 //============================================================================
       
    27 // Forward Declarations
       
    28 //============================================================================
       
    29 class CTZDocument;
       
    30 //============================================================================
       
    31 // CPersistedEntityWrapper class definition
       
    32 // Abstract base wrapper class for all the entities.  
       
    33 // Each specialised wrapper class will be responsible for the behaviour of a 
       
    34 // persisted entity.
       
    35 //============================================================================
       
    36 class CPersistedEntityWrapper
       
    37 	{
       
    38 public:
       
    39 	CPersistedEntityWrapper(CTZDocument& aDocument);
       
    40 	virtual ~CPersistedEntityWrapper();
       
    41 
       
    42 	virtual void ExternaliseL(std::ofstream& aFilestream)=0;
       
    43 
       
    44 	// When a derived class is destroyed, call this on each referenced entity.
       
    45 	virtual void DecrRefCount() { --iReferenceCount; }
       
    46 	virtual void IncrRefCount() { ++iReferenceCount; }
       
    47 	virtual bool IsUnreferenced() { return iReferenceCount==0; } 
       
    48 	virtual TUint16 ReferenceCount() { return iReferenceCount; }
       
    49 
       
    50 	int iOffset;				//Reference to the entity in the database
       
    51 
       
    52 protected:
       
    53 	CTZDocument& iDocument;
       
    54 	
       
    55 private:
       
    56 	TUint16 iReferenceCount;		//Number of objects referencing this entity
       
    57 								//If this remains 0 after assembly then 
       
    58 								//this entity will not be persisted.
       
    59 	};
       
    60 
       
    61 //============================================================================
       
    62 // SEntityCheck
       
    63 // Used to remove unreferenced entities from the entity tables
       
    64 //============================================================================
       
    65 struct SEntityCheck
       
    66 	{
       
    67 	TBool operator()(CPersistedEntityWrapper* aEntity)
       
    68 		{
       
    69 		bool remove = aEntity->IsUnreferenced();
       
    70 		if (remove)
       
    71 			{
       
    72 			delete aEntity;
       
    73 			}
       
    74 		return remove;
       
    75 		}
       
    76 	};
       
    77 
       
    78 #endif //__PERSISTED_ENTITY_WRAPPER_H
       
    79 //============================================================================
       
    80 // End of file
       
    81 //============================================================================