mulwidgets/muldatamodel/inc/mulcachemanager.h
branchRCL_3
changeset 26 0e9bb658ef58
parent 0 e83bab7cf002
equal deleted inserted replaced
25:4ea6f81c838a 26:0e9bb658ef58
       
     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:  Cache Manager class
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #ifndef MULCACHEMANAGER_H
       
    20 #define MULCACHEMANAGER_H
       
    21 
       
    22 #include <mul/mulvisualitem.h>
       
    23 
       
    24 #include <memory>
       
    25 #include <vector>
       
    26 #include <map>
       
    27 
       
    28 #include <mul/imulwidgetdef.h>
       
    29 #include <mul/muldatapath.h>
       
    30 
       
    31 #include "multree.h"
       
    32 #include "mulvectoradaptor.h"
       
    33 
       
    34 namespace osncore
       
    35     {
       
    36     class UString;  
       
    37     }
       
    38 using namespace osncore;
       
    39 
       
    40 namespace Alf
       
    41 	{
       
    42 
       
    43 //Forward Declaration
       
    44 class MulVisualItem;
       
    45 class IAlfMap;
       
    46 class IAlfContainer;
       
    47 
       
    48 /**
       
    49  *  Implementation class for Cache Manager.
       
    50  *  @lib 
       
    51  */
       
    52 
       
    53 class MulCacheManager
       
    54     {
       
    55 public: //structure
       
    56 
       
    57 	/**
       
    58 	 * Comparation structure
       
    59 	 * Required by stl map to compare MulDataPath
       
    60 	 */
       
    61 	struct TCompPath
       
    62 	{
       
    63 	  bool operator()( MulDataPath& path1, MulDataPath& path2 ) const
       
    64 	  {
       
    65 	  return ( path1 < path2 ) ;
       
    66 	  }
       
    67 	};
       
    68 	
       
    69 	typedef std::map< int,MulVisualItem* > MulVisualItemMap;
       
    70 	typedef std::map< int, int > MulSelectionMap;
       
    71 
       
    72 public: //Constructor and destructor
       
    73     
       
    74     /**
       
    75      * C++ constructor.
       
    76      */
       
    77      MulCacheManager();
       
    78      
       
    79      /**
       
    80  	 * Destructor.
       
    81  	 */
       
    82 	~MulCacheManager();
       
    83 	
       
    84 public: //New method	
       
    85 	
       
    86 	/**
       
    87 	 * Create Node for visual items in tree. 
       
    88 	 * this function must be called before adding VisualItem
       
    89 	 * 
       
    90 	 * @param aStartIndex Index of first item.
       
    91 	 * @param aCount Number of items to be added.
       
    92 	 * @param aPath
       
    93 	 */
       
    94 	void CreateNodes(int aStartIndex, int aCount, const MulDataPath& aPath );
       
    95 	
       
    96 	/**
       
    97      * Adds Visual Item in CacheManager.
       
    98      * 
       
    99      * @param aVisualItem Visual items to be added.
       
   100      * @param aItemIndex Index where item need to be added
       
   101      * 
       
   102      * @return index where item is added
       
   103      */ 
       
   104 	//void AddVisualItem( std::auto_ptr<MulVisualItem> aVisualItem, int aItemIndex );
       
   105 	
       
   106 	/**
       
   107 	 * Add Visual Item to cache manager
       
   108 	 * 
       
   109 	 * @param aVisualItem  Visual item to be added
       
   110 	 * @param aPath Path of visual item in  tree
       
   111 	 * @param aIndex Index of visual item in path
       
   112 	 */
       
   113 	void AddVisualItem( std::auto_ptr<MulVisualItem> aVisualItem, const MulDataPath& aPath , int aIndex );
       
   114 	
       
   115 	/**
       
   116      * Removes Visual Item in CacheManager.
       
   117      * 
       
   118      * @param aIndex index of item to be removed.
       
   119      * 
       
   120      * @throws invalid_argument exception
       
   121      */ 
       
   122 	
       
   123 	void RemoveVisualItem( int aIndex  );
       
   124 	
       
   125 	/**
       
   126 	 * Remove Visual Item from cache manager
       
   127 	 * 
       
   128 	 * @param aPath Path of visual item in  tree
       
   129 	 * @param aIndex Index of visual item in path
       
   130 	 */
       
   131 	void RemoveVisualItem( const MulDataPath& aPath , int aIndex );
       
   132 	
       
   133 	
       
   134 	/**
       
   135 	 * Remove Visual item form cache manager
       
   136 	 *
       
   137 	 * @param aIndex Start index of item to delete
       
   138 	 * @param aCount No of items to be removed
       
   139 	 * @param aPath Path from items to be removed
       
   140 	 */
       
   141 	void RemoveVisualItem(int aIndex, int aCount, const MulDataPath& aPath);
       
   142 	
       
   143 	/**
       
   144      * Updates Visual Item in CacheManager.
       
   145      * 
       
   146      * @param aVisualItem Visual items to be updated.
       
   147      * @param aItemIndex Index where item need to be added
       
   148      * @throws invalid_argument exception
       
   149      */ 
       
   150 	
       
   151 	void UpdateVisualItem( MulVisualItem& aVisualItem, int aItemIndex );
       
   152 	
       
   153 	
       
   154 	/**
       
   155      * Updates Visual Item in CacheManager.
       
   156      * 
       
   157      * @param aVisualItem Visual items to be updated.
       
   158      * @param aPath Path of visual item in tree
       
   159      * @param aIndex Index of visual item in path
       
   160      * @throws invalid_argument exception
       
   161      */ 
       
   162 	void UpdateVisualItem( MulVisualItem& aVisualItem, const MulDataPath& aPath, int aIndex );
       
   163 		
       
   164 	/**
       
   165      * Returns Visual Items to Model from CacheManager.
       
   166      * 
       
   167      * @param aIndex  Index of item to be retrieved.
       
   168      */
       
   169 	
       
   170 	MulVisualItem* Data( int aIndex ) const;
       
   171 	
       
   172 	/**
       
   173      * Returns Visual Items to Model from CacheManager.
       
   174      * 
       
   175      * @param aPath Path of visual item in tree
       
   176      * @param aIndex Index of visual item in path
       
   177      */
       
   178 	MulVisualItem* Data( const MulDataPath& aPath, int aIndex ) const;
       
   179 	
       
   180 	/**
       
   181      * Gets Number Of items stored in the Cache Manager .
       
   182      * 
       
   183      * @return number of items in the Cache Manager
       
   184      */
       
   185 	int Count() const;
       
   186 	
       
   187 	/**
       
   188      * Get Number of items in mentiond path
       
   189      * 
       
   190      * @param aPath Path of node
       
   191      * @return number of items 
       
   192      */
       
   193 	//int Count( const MulDataPath& aPath ) const;
       
   194 	
       
   195 	/**
       
   196      * Get Number of childs for the given node
       
   197      * 
       
   198      * @param aPath Path of node
       
   199      * @return number of items 
       
   200      */
       
   201 	//int ChildCount( const MulDataPath& aPath ) const;	
       
   202 	
       
   203 	/**
       
   204 	 * Retrun number of items,
       
   205 	 * Checks that node is expanded or not , 
       
   206 	 * if expanded then add it couts child count else ignore child count.
       
   207 	 * 
       
   208 	 * @return Node count
       
   209 	 */
       
   210 	int ExpandedNodeCount( ) const;
       
   211 	
       
   212 	/**
       
   213 	 * Return path of node of specified absoulte index
       
   214 	 * 
       
   215 	 * @param aAbsoluteIndex Absoulte index of node in tree
       
   216 	 * @return Path to node.
       
   217 	 */
       
   218 	//MulDataPath Path( int aAbsoluteIndex ) const;
       
   219 	
       
   220 	/**
       
   221 	 * Expand Node with given absolute index
       
   222 	 * This Api will be called by widget to expand node.
       
   223 	 * 
       
   224 	 * @param aAbsoluteIndex Absolute index of node to be expanded
       
   225 	 * @return Number of items affected
       
   226 	 */
       
   227 	//int ExpandNode( int aAbsoluteIndex );
       
   228 	
       
   229 	
       
   230 	/**
       
   231 	 * Returns absolute index
       
   232 	 * 
       
   233 	 * @param aPath Path to node
       
   234 	 * @param aIndex index of node in path
       
   235 	 * @return Absolute index
       
   236 	 */
       
   237 	//int PathToAbsoluteIndex( const MulDataPath& aPath, int aIndex ) const;
       
   238 	
       
   239 	/**
       
   240 	 * Mark or Unmark item
       
   241 	 * 
       
   242 	 * @param aType Marking type
       
   243 	 * @param aItemsIndex vector of index of items
       
   244 	 * @param aPath Path/depth at wich items are to be marked/unmark
       
   245 	 */
       
   246 	void SetMarkedIndices( MulWidgetDef::TMulWidgetMarkingType aType ,
       
   247 						   const std::vector<int>& aItemsIndex,
       
   248 						   const MulDataPath& aPath );
       
   249 
       
   250 	/**
       
   251 	 * Mark or Unmark or unmark all type
       
   252 	 * 
       
   253 	 * @param aType Marking type
       
   254 	 */
       
   255 	void SetMarkedIndices( MulWidgetDef::TMulWidgetMarkingType aType = MulWidgetDef::EMulMarkAll );
       
   256 
       
   257 	/**
       
   258 	 * Return mared index for mentioned path
       
   259 	 * 
       
   260 	 * @param aPath Path
       
   261 	 * @return vector of index
       
   262 	 */
       
   263 	const std::vector<int>& MarkedIndices( const MulDataPath& aPath ) ;
       
   264 
       
   265 	/**
       
   266 	* Check weather item at specified index is marked or not.
       
   267 	* 
       
   268 	* @param aIndex Absolute index of item
       
   269 	* @return true if seleccted else otherwise
       
   270 	*/	
       
   271 	bool IsItemMarked( int aIndex ) const;
       
   272 	
       
   273     /**
       
   274 	 * Function for setting the item Marked or Unmarked. For mark and
       
   275 	 * unmark operations, index of item should be provided.
       
   276 	 * 
       
   277 	 * @param aType Type of marking operation to be performed. 
       
   278 	 * @param aItemsIndex Indices of the items to be changed
       
   279 	 * @throw Invalid Argument, if type is specified as mark-all and unmark-all. 
       
   280 	 */ 
       
   281     void SetMarkedIndex( MulWidgetDef::TMulWidgetMarkingType aType, int aIndex );
       
   282 	
       
   283 private: //New Method
       
   284 
       
   285 	/**
       
   286 	 * Remove visual Item data from map and update other keys for map
       
   287 	 * 
       
   288 	 * @param aPath Path of visual item in  tree
       
   289 	 * @param aIndex Index of visual item in path
       
   290 	 * @param aCount No of items to be removed
       
   291 	 */
       
   292 	void RemoveItemFromMap(const MulDataPath& aPath , int aIndex );
       
   293 
       
   294 	/**
       
   295 	 * Remove child visual Item from map
       
   296 	 * 
       
   297 	 * @param aPath Path of visual item in  tree
       
   298 	 * @param aIndex Index of visual item in path
       
   299 	 */	
       
   300 	//void RemoveChildItemsFromMap(MulDataPath aPath , int aIndex );
       
   301 
       
   302 	
       
   303 	/**
       
   304 	 * Update index in Map.
       
   305 	 * 
       
   306 	 * Once we remove any item from tree.
       
   307 	 * Index of other items will be changed so the path that points
       
   308 	 * to Data of Item. We now need to update path that to item.
       
   309 	 * 
       
   310 	 * @param aMap Map wich need to be updated
       
   311 	 * @param aIndex Index from item removed
       
   312 	 */
       
   313 	template <typename T> void UpdataPathInMapAfterRemove( std::map<int,T >& aMap, int aIndex, int aCount );
       
   314 
       
   315 	/**
       
   316 	 * Update Path in Map.
       
   317 	 * 
       
   318 	 * Update the path (modify thh depth) for the child items after remove.
       
   319 	 * 
       
   320 	 * @param aMap Map wich need to be updated
       
   321 	 * @param aParentNode, parent node
       
   322 	 * @param aOldPath Old path
       
   323 	 * @param aNewPath New path	 
       
   324 	 * @param aIndex, index of the node in that parent node
       
   325 	 */							 						 
       
   326 //	template <typename T> void UpdataChildDepthInMap( 
       
   327 //											std::map<MulDataPath,T,TCompPath>& aMap,
       
   328 //											MulTreeNode* aParentNode,MulDataPath& aOldPath,
       
   329 //								 			MulDataPath& aNewPath,int aIndex);	
       
   330 	/**
       
   331 	 * Update index in Map.
       
   332 	 * 
       
   333 	 * Once we insert any item from tree.
       
   334 	 * Index of other items will be changed so the path that points
       
   335 	 * to Data of Item. We now need to update path that to item.
       
   336 	 * 
       
   337 	 * @param aMap Map wich need to be updated
       
   338 	 * @param aIndex Index at which new item inserted
       
   339 	 */
       
   340 	template <typename T> void UpdataPathInMapAfterInsert( std::map<int,T >& aMap, int aIndex, int aCount );
       
   341 																								
       
   342 	
       
   343 private: //data
       
   344 		
       
   345     int                         mTotalCount; // total no of items in cache
       
   346 	MulVisualItemMap 		    mVisualItemMap; //store visual item in map using path as key	
       
   347 	MulVectorAdaptor<int>       mSelectionVector;//store maked indices to ,used to return marking information to client
       
   348 	MulSelectionMap 			mSelectionMap; //store marking information using path as key
       
   349   };
       
   350   
       
   351 } // namespace Alf
       
   352 
       
   353 #endif //MULCACHEMANAGER_H
       
   354     
       
   355 //End of file