All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
ResourceNodeCache.h
1 // Copyright eeGeo Ltd (2012-2014), All Rights Reserved
2 
3 #pragma once
4 
5 #include "Streaming.h"
6 #include "MortonKey.h"
7 #include <list>
8 
9 namespace Eegeo
10 {
11  namespace Streaming
12  {
14  {
15  public:
17  const IResourceStream* resourceStream,
18  const MortonKey key,
19  ResourceNode* resourceNode
20  ) :
21  pResourceStream(resourceStream),
22  mortonKey(key),
23  pResourceNode(resourceNode)
24  {
25  }
26 
27  bool MatchesKey(const IResourceStream* resourceStream, const MortonKey otherKey)
28  {
29  return (pResourceStream == resourceStream && mortonKey == otherKey);
30  }
31 
32  const IResourceStream* pResourceStream;
33  const MortonKey mortonKey;
34  ResourceNode* pResourceNode;
35  };
36 
38  {
39  public:
40  ResourceNodeCache(size_t maxResourceNodes);
41 
43 
44  void ClearResourceNodes();
45 
46  ResourceNode* GetResourceNodeOrNull(const IResourceStream* resourceStream, const MortonKey mortonKey);
47 
48  void AddResourceNode(
49  const IResourceStream* resourceStream,
50  const MortonKey mortonKey,
51  ResourceNode* resourceNode);
52 
53  int GetTotalNumOfAllocations() const { return m_totalNumOfAllocations; }
54  int GetTotalNumOfMisses() const { return m_totalNumOfMisses; }
55  int GetTotalNumOfDeletions() const { return m_totalNumOfDeletions; }
56  int GetTotalNumOfAdds() const { return m_totalNumOfAdds; }
57  int GetSize() const { return static_cast<int>(m_cachedNodes.size()); }
58 
59  void ResetCounters();
60 
61  private:
62  size_t m_maxResourceNodes;
63  std::list<CachedResourceNode> m_cachedNodes;
64  int m_totalNumOfAllocations;
65  int m_totalNumOfMisses;
66  int m_totalNumOfDeletions;
67  int m_totalNumOfAdds;
68  };
69  }
70 }