mulwidgets/muldatamodel/inc/mulvectoradaptor.h
branchRCL_3
changeset 19 4ea6f81c838a
parent 17 514d98f21c43
child 20 0e9bb658ef58
equal deleted inserted replaced
17:514d98f21c43 19:4ea6f81c838a
     1 /*
       
     2 * Copyright (c) 2007-2008 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:  Adaptor class for AlfPtrVector and Stt vector
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #ifndef MULVECTORADAPTOR_H_
       
    20 #define MULVECTORADAPTOR_H_
       
    21 
       
    22 #include <vector>
       
    23 #include <algorithm> //for find algorithm
       
    24 
       
    25 using namespace std;
       
    26 
       
    27 namespace Alf
       
    28 	{
       
    29 	
       
    30 //Forward Declaration
       
    31 
       
    32 /**
       
    33  * Adaptor class for stl vector with interface similar to AlfPtrVector
       
    34  */
       
    35 template <class T> class MulVectorAdaptor 
       
    36     {         
       
    37 public: //new method
       
    38 
       
    39 	/**
       
    40 	 * Return number of element in  vector
       
    41 	 * 
       
    42 	 * @return no of element in vector
       
    43 	 */
       
    44 	int count()
       
    45 		{
       
    46 		return mVector.size();
       
    47 		}
       
    48 	
       
    49 	/**
       
    50 	 * Insert item in vector
       
    51 	 * 
       
    52 	 * @param aPosition Position of item 
       
    53 	 * @param aItem item to be inserted
       
    54 	 */
       
    55 	void insert( uint aPosition, T aItem )
       
    56 		{		
       
    57 		mVector.insert( mVector.begin() + aPosition, aItem );
       
    58 		}
       
    59 	
       
    60 	/**
       
    61 	 * Insert item in vector at last
       
    62 	 * 
       
    63 	 * @param aItem item to be inserted
       
    64 	 */
       
    65 	void insert( T aItem )
       
    66 		{
       
    67 		mVector.push_back( aItem );
       
    68 		}
       
    69 	
       
    70 	/**
       
    71 	 * Return item at specified index
       
    72 	 * 
       
    73 	 * @param aPosition position of item 
       
    74 	 * @return itmem at specified index
       
    75 	 */
       
    76 	T operator[] ( uint aPosition ) const
       
    77 		{
       
    78 		return mVector[aPosition];
       
    79 		}
       
    80 	
       
    81 	/**
       
    82 	 * Remove item from specified position
       
    83 	 * 
       
    84 	 * @param aPosition Position of item to be removed
       
    85 	 */
       
    86 	void remove( uint aPosition  )
       
    87 		{
       
    88 		mVector.erase( mVector.begin() + aPosition );
       
    89 		}
       
    90 	
       
    91 	/**
       
    92 	 * Remove specified item
       
    93 	 * 
       
    94 	 * @param aItem Item to be removed
       
    95 	 */
       
    96 	void remove( T aItem )
       
    97 		{
       
    98 //		vector<T>::iterator iter = std::find( mVector.begin(), mVector.end(), aItem) ;
       
    99 //		if( iter !=  mVector.end())
       
   100 //			{
       
   101 //			mVector.erase( iter );
       
   102 //			}
       
   103 		
       
   104 		if(  std::find( mVector.begin(), mVector.end(), aItem) !=  mVector.end())
       
   105 			{
       
   106 			mVector.erase(  std::find( mVector.begin(), mVector.end(), aItem) );
       
   107 			}
       
   108 		}
       
   109 	
       
   110 	/**
       
   111 	 * Return actual std vector of this adaptor class
       
   112 	 * 
       
   113 	 * @return Return std vector.
       
   114 	 */
       
   115 	const vector<T>& actualVector()
       
   116 		{
       
   117 		return mVector;
       
   118 		}
       
   119 	
       
   120 	/**
       
   121 	 * Find specifed item in vecotr
       
   122 	 * 
       
   123 	 * @return return true if item found false otherwise
       
   124 	 */
       
   125 	bool find( T aItem )
       
   126 		{
       
   127 //		vector<T>::iterator iter = std::find(mVector.begin(), mVector.end(), aItem) ;
       
   128 //		return (iter != mVector.end());
       
   129 		
       
   130 		return (std::find(mVector.begin(), mVector.end(), aItem) != mVector.end());		
       
   131 		}
       
   132 	
       
   133 	/**
       
   134 	 * Clear the content of vector
       
   135 	 */
       
   136 	void clear()
       
   137 		{
       
   138 		mVector.clear();
       
   139 		}
       
   140 	
       
   141 private: //data
       
   142 
       
   143 	vector<T> mVector;	
       
   144     };
       
   145 	    
       
   146     } //namespace Alf
       
   147 
       
   148 #endif /*MULVECTORADAPTOR_H_*/
       
   149 
       
   150 //End of file
       
   151 
       
   152