First public contribution.
1 // Copyright (c) 2008-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 the License "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".
8 // Initial Contributors:
9 // Nokia Corporation - initial contribution.
14 // f32\sfat32\inc\sl_leafdir_cache.h
23 #ifndef SL_LEAFDIR_CACHE_H
24 #define SL_LEAFDIR_CACHE_H
26 //---------------------------------------------------------------------------------------------------------------------------------
31 A data structure to define the location of a direcotry
37 TLeafDirData(TUint aClusterNum);
38 TLeafDirData(TUint aClusterNum, const TEntryPos& aMRUPos);
39 inline TBool operator==(const TLeafDirData &aDirPos) const;
40 inline TBool operator!=(const TLeafDirData &aDirPos) const;
47 Class definition for the nodes of the leaf dir cache
48 All cached direcotries are stored as nodes in a tree structure
51 class CLeafDirTreeNode : public CBase
55 enum TLeafDirTreeNodeType
57 ERoot, // Represents the root node, i.e. the root path
58 ELeaf, // Represents a pure 'leaf' nodes, no child
59 ELeafIntermediary, // Represents a 'leaf' node, but has at least one child
60 EPureIntermediary, // Represents a pure 'intermediary' node, which only exists to share the common path of other nodes
63 static CLeafDirTreeNode* NewL(CLeafDirTree* aOwnerTree, const TDesC& aPathName, const TLeafDirData& aDirPos, TLeafDirTreeNodeType aType);
65 inline CLeafDirTreeNode* Parent();
66 inline void SetParent(CLeafDirTreeNode* aNode);
67 inline RPointerArray<CLeafDirTreeNode>& Children();
68 void MakeItChildL(CLeafDirTreeNode* aNode);
69 TInt RemoveChild(CLeafDirTreeNode* aNode);
70 inline const TLeafDirData& LeafDirData() const;
71 inline TUint32 StartClusterNum() const;
72 inline void SetLeafDirData(const TLeafDirData& aLeafDirData);
73 inline const TDesC& Path() const;
74 void SetPathL(const TDesC& aPathData);
75 void SetType(const CLeafDirTreeNode::TLeafDirTreeNodeType aType);
76 inline TBool IsRoot() const;
77 inline TBool IsLeaf();
78 inline TBool IsLeafIntermediary();
79 inline TBool IsPureIntermediary();
82 void ConstructL(CLeafDirTree* aOwnerTree, const TDesC& aPathName);
83 CLeafDirTreeNode(const TLeafDirData& aDirPos , TLeafDirTreeNodeType aType);
84 CLeafDirTreeNode(const CLeafDirTreeNode& aLeafDirTreeNode);
85 CLeafDirTreeNode* operator=(CLeafDirTreeNode& aLeafDirTreeNode);
88 CLeafDirTree* iOwnerTree; // A pointer to the owner of this node.
89 CLeafDirTreeNode* iParent; // The parent of this node
90 RPointerArray<CLeafDirTreeNode> iChildren; // The children of this node
91 RBuf iPath; // The path of the direcotry this node represents
92 TLeafDirData iLeafDirData; // The position of the direcotry this node represents
93 TLeafDirTreeNodeType iNodeType; // The type of the node
97 Class definition for the tree structure of the leaf dir cache
98 All cached direcotries are stored as nodes in a tree structure
101 class CLeafDirTree : public CBase
104 static CLeafDirTree* NewL(TUint32 aSize);
108 TInt Search(const TDesC& aPath, CLeafDirTreeNode*& aNodeFound, TLeafDirData& aDirPos);
109 TInt DoSearch(const TDesC& aPath, CLeafDirTreeNode* aNodeToStart, CLeafDirTreeNode*& aNodeFound, TLeafDirData& aDirPos);
110 void InsertL(const TDesC& aPath, const TLeafDirData& aDirPos, CLeafDirTreeNode*& aNodeInserted);
111 void DoInsertL(CLeafDirTreeNode* aNodeToStart, const TDesC& aPath, const TLeafDirData& aDirPos, CLeafDirTreeNode*& aNodeInserted);
112 void RemoveDirL(const TLeafDirData& aDirPos);
113 void UpdateMRUPos(const TLeafDirData& aLeafDirData);
114 void RemoveFromCacheL(CLeafDirTreeNode* aNodeToDelete);
115 CLeafDirTreeNode* FindLeftestLeafNode(CLeafDirTreeNode* aNodeToStart) const;
116 void DeleteSubTreeL(CLeafDirTreeNode* aNodeToStart);
118 CLeafDirTreeNode* LruNode();
119 void AddOntoLruL(CLeafDirTreeNode* aNodeToAdd);
120 TInt RemoveFromLru(CLeafDirTreeNode* aNodeToRemove);
121 TInt MakeMostRecentlyUsed(CLeafDirTreeNode* aNodeUsed);
122 inline TInt LruCount() const;
125 // For debugging & testing only
127 TInt ObjectCount() const {return iContainer.Count();};
128 void AddToObjectContainerL(CLeafDirTreeNode* aNode);
129 void RemoveFromObjectContainerL(CLeafDirTreeNode* aNode);
130 void DumpTreeContentL() const;
135 CLeafDirTree(TUint32 aSize);
138 CLeafDirTreeNode* iRoot; // The root node
139 RPointerArray<CLeafDirTreeNode> iLruList; // The list containing all the LRU cached nodes
140 TUint32 iSize; // The maximum number of items allowed to cache
142 // For debugging & testing only
144 RPointerArray<CLeafDirTreeNode> iContainer; // The container containing all nodes
149 Class definition for leaf directory cache.
150 Acting as an interface class for CFatMountCB to use.
153 class CLeafDirCache : public CBase
156 static CLeafDirCache* NewL(TUint32 aLimit);
159 TInt FindInCache(const TDesC& aLeafDirName, TLeafDirData& aDirPos) const;
160 void AddToCacheL(const TDesC& aLeafDirName, const TLeafDirData& aDirPos);
161 void RemoveDirL(const TLeafDirData& aDirPos);
162 void UpdateMRUPos(const TLeafDirData& aLeafDirData);
163 TInt CacheCount() const;
165 // For debugging & testing only
167 void DumpCacheContentL() const;
168 TInt NodeCount() const;
172 CLeafDirCache(TUint32 aLimit);
176 TUint32 iSize; // The cache size
177 CLeafDirTree* iTree; // The cache content, represented as a tree structure
180 //---------------------------------------------------------------------------------------------------------------------------------
182 #include"sl_leafdir_cache.inl"
184 #endif //SL_LEAFDIR_CACHE_H