multimediacommsengine/mmcesrv/mmceserver/inc/mcedictionary.h
author Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
Fri, 19 Feb 2010 23:12:20 +0200
branchRCL_3
changeset 3 513a8b745b2f
parent 0 1bce908db942
permissions -rw-r--r--
Revision: 201003 Kit: 201007

/*
* Copyright (c) 2005 Nokia Corporation and/or its subsidiary(-ies).
* All rights reserved.
* This component and the accompanying materials are made available
* under the terms of "Eclipse Public License v1.0"
* which accompanies this distribution, and is available
* at the URL "http://www.eclipse.org/legal/epl-v10.html".
*
* Initial Contributors:
* Nokia Corporation - initial contribution.
*
* Contributors:
*
* Description:    
*
*/




#ifndef CMCEDICTIONARY_H
#define CMCEDICTIONARY_H

//  INCLUDES
#include <e32base.h>
#include "mcesrv.h"

/**
*  Abstract base class for key - value pairs
*
*  @lib 
*  @since
*/
class CMceDictionaryItem : public CBase
    {
public: // New functions

    /**
    * Returns the key
    * @return the key
    */
    TInt Key();
    
protected:
    
    /**
    * Constructor
    * @param aKey the key
    */
    CMceDictionaryItem( TInt aKey );
    
private: // Data
    
    // the key
    TInt iKey;
    };

/**
*  Template class for key-value pairs, where
*  the value is a T-class object.
*
*  @lib 
*  @since
*/
template <class T> 
class CMceKeyTValuePair : public CMceDictionaryItem
    {
public: // Constructors and destructors

	/**
	* Constructor
	* @param aKey the key
	* @param aValue the value
	*/
	CMceKeyTValuePair( TInt aKey, T aValue );

public: // Functions from base classes
    
    // From CMceKeyValuePairBase
    /**
    * Returns the value.
    * @return the value
    */
	T& Value();
        
public: // New functions       
    
    /**
    * Sets the value
    * @param aValue
    */
    void SetValue( T aValue );
    
private: // Data
    
        // the value
        T iValue;
    MCESRV_UT_DEFINITIONS
    };

/**
*  Template class for key-value pairs, where
*  the value is a C-class object.
*
*  @lib 
*  @since
*/
template <class C> 
class CMceKeyCValuePair : public CMceDictionaryItem
    {

public: // Constructors and destructor

    /**
	* Constructor
    * @param aKey the key
	* @param aValue the value, ownership is transfered
	*/
	CMceKeyCValuePair( TInt aKey, C* aValue );
    
    /**
	* Destructor
	*/
	~CMceKeyCValuePair();

public: // Functions from base classes
    
    // From CMceKeyValuePairBase
    /**
    * Returns the value.
    * @return the value, ownership is not transfered
    */
	C* Value();
        
public: // New functions           
    /**
    * Sets the value
    * @param aValue
    */
    void SetValue( C* aValue );
        
private: // data
        
    // the value, owned
    C* iValue;
    
    MCESRV_UT_DEFINITIONS    
    };
    
    
/**
* Cictionary that holds key-value pairs and allows modification of them. 
*/
class CMceDictionary : public CBase
    {
    
public: // Constructors and destructor
    
    /**
	* Destructor
	*/
    ~CMceDictionary();
   
public: // New functions
    
    /**
    * Returns the dictionary item with given key.
    * Returns NULL, if the item is not found.
    * @param aKey
    * @return the item, ownership is not transfered.
    */
    CMceDictionaryItem* Pair( TInt aKey ) const;
    
    /**
    * Adds a key-value pair to the dictionary.
    * aPair the pair, ownership is transfered.
    * The pair 
    */
    void AddL( CMceDictionaryItem* aPair );
    
	/**
	* Deletes a pair that has given key from the dictionary.
	* @param aKey the key
	*/	
	void Delete( TInt aKey );
	
private:
    
    // data
    RPointerArray< CMceDictionaryItem > iPairs;

    MCESRV_UT_DEFINITIONS		
    };

#include "mcedictionary.inl"
#endif // CMCEDICTIONARY_H

// End of File