logsui/EngineInc/CLogsEventArray.h
changeset 0 e686773b3f54
equal deleted inserted replaced
-1:000000000000 0:e686773b3f54
       
     1 /*
       
     2 * Copyright (c) 2002 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: 
       
    15 *     Implementation of MLogsEventArray
       
    16 *
       
    17 */
       
    18 
       
    19 
       
    20 #ifndef __CLogsEventArray_H_
       
    21 #define __CLogsEventArray_H_
       
    22 
       
    23 //  INCLUDES
       
    24 #include <e32base.h>
       
    25 #include "MLogsEventArray.h"
       
    26 #include "MLogsModel.h"
       
    27 
       
    28 // MACROS
       
    29 
       
    30 // DATA TYPES
       
    31 
       
    32 // FUNCTION PROTOTYPES
       
    33 
       
    34 // FORWARD DECLARATIONS
       
    35 class MLogsEvent;
       
    36 // CLASS DECLARATION
       
    37 
       
    38  /**
       
    39   * Concrete MlogsEventArray of TEventType.
       
    40   *
       
    41   * @param TEventType    concrete event type. Must be derived from MLogsEvent.
       
    42   */
       
    43 template<class TEventType>
       
    44 class CLogsEventArray : public CBase, public MLogsEventArray
       
    45     {
       
    46     public:  // Constructors and destructor
       
    47         
       
    48 		/**
       
    49          * EPOC constructor. 
       
    50          *
       
    51          * @param aGranularity Initial granularity of the event array
       
    52          * @return model object
       
    53          */
       
    54 		static CLogsEventArray<TEventType>* NewL( TInt aGranularity );
       
    55         
       
    56         /**
       
    57          *  Destructor
       
    58          */
       
    59 		~CLogsEventArray();
       
    60 
       
    61     private:
       
    62         /**
       
    63          * C++ constructor. 
       
    64          *
       
    65          * @param aGranularity Initial granularity of the event array
       
    66          */
       
    67         CLogsEventArray( TInt aGranularity );
       
    68 
       
    69     public:  // New functions
       
    70 		/**
       
    71 		 * Append a new event of TEventType to event array  
       
    72 		 *
       
    73 		 * @param aEvent  event to be added to this array.
       
    74 		 */
       
    75         ///// void AppendL(const TEventType& aEvent);   //FIXME: remove this 
       
    76 
       
    77     public:  // from MLogsEventArray
       
    78         TInt Count() const ;
       
    79 
       
    80         const MLogsEvent& At(TInt aIndex) const;
       
    81 
       
    82         MLogsEvent& At(TInt aIndex);
       
    83 
       
    84         /**
       
    85          * @param aEvent    event to add to this array. The concrete event type 
       
    86          *                  must always be same as TEventType.
       
    87          */
       
    88         void AppendL( const MLogsEvent& aEvent );
       
    89 
       
    90         void Delete( TInt aIndex );
       
    91 
       
    92         void Reset();
       
    93 
       
    94         void Compress();
       
    95       
       
    96     private:  // Data
       
    97 
       
    98         /// Own: Event array
       
    99 		//CArrayFixSeg<TEventType> iArray;  
       
   100         CArrayPtrSeg<const MLogsEvent> iArray;  //Fix for EKKJ-6EGAKC. Changed to CArrayPtrSeg  
       
   101     };
       
   102 
       
   103 template<class TEventType>
       
   104 CLogsEventArray<TEventType>::CLogsEventArray( TInt aGranularity ) :
       
   105 	iArray( aGranularity )
       
   106     {
       
   107     }
       
   108 
       
   109 template<class TEventType>
       
   110 CLogsEventArray<TEventType>* CLogsEventArray<TEventType>::NewL( TInt aGranularity )
       
   111     {
       
   112     CLogsEventArray<TEventType>* self = 
       
   113 		new (ELeave) CLogsEventArray( aGranularity  );
       
   114     return self;
       
   115     }
       
   116 
       
   117 template<class TEventType>
       
   118 CLogsEventArray<TEventType>::~CLogsEventArray()
       
   119     {
       
   120 	Reset();
       
   121     }
       
   122 
       
   123 ///// FIXME: remove this 
       
   124 ///// template<class TEventType>
       
   125 ///// void CLogsEventArray<TEventType>::AppendL(const TEventType& aEvent)
       
   126 ///// 	{
       
   127 ///// 	iArray.AppendL( aEvent );
       
   128 /////   }
       
   129 
       
   130 template<class TEventType>
       
   131 void CLogsEventArray<TEventType>::AppendL( const MLogsEvent& aEvent )
       
   132 	{
       
   133     iArray.AppendL( &aEvent ); 
       
   134 	}
       
   135 
       
   136 template<class TEventType>
       
   137 TInt CLogsEventArray<TEventType>::Count() const 
       
   138 	{ 
       
   139 	return iArray.Count(); 
       
   140 	}
       
   141 
       
   142 template<class TEventType>
       
   143 const MLogsEvent& CLogsEventArray<TEventType>::At(TInt aIndex) const
       
   144 	{ 
       
   145     return *(iArray.At( aIndex )); 
       
   146 	}
       
   147 
       
   148 template<class TEventType>
       
   149 MLogsEvent& CLogsEventArray<TEventType>::At(TInt aIndex)
       
   150 	{ 
       
   151     return CONST_CAST(MLogsEvent&, (*(iArray.At( aIndex ))));  
       
   152 	}
       
   153 
       
   154 template<class TEventType>
       
   155 void CLogsEventArray<TEventType>::Delete( TInt aIndex )
       
   156 	{
       
   157     const MLogsEvent* event = iArray[aIndex];	
       
   158     delete event;                //delete the owned object
       
   159 	iArray.Delete( aIndex );     //delete array entry (containing pointer)
       
   160 	}
       
   161 
       
   162 template<class TEventType>
       
   163 void CLogsEventArray<TEventType>::Reset()
       
   164 	{
       
   165 /*****
       
   166 	for( int i=0; i<iArray.Count(); i++ )
       
   167 		{
       
   168 		iArray[i].Reset();
       
   169 		}
       
   170 	iArray.Reset(); //Thsi function deletes all elements from the array and frees the memory allocated to the array buffer.
       
   171 *******/
       
   172     iArray.ResetAndDestroy();  //Destroys all objects whose pointers form the elements of the array, before resetting the array.
       
   173 	}
       
   174 
       
   175 template<class TEventType>
       
   176 void CLogsEventArray<TEventType>::Compress()
       
   177 	{
       
   178 	iArray.Compress();
       
   179 	}
       
   180 
       
   181 #endif
       
   182 
       
   183 // End of File  __CLogsEventArray_H_