All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
NavGraphConnectionCache.h
1 // Copyright eeGeo Ltd (2012-2014), All Rights Reserved
2 
3 #pragma once
4 
5 #include "Types.h"
6 #include "Navigation.h"
7 #include "Routes.h"
8 #include "tr1.h"
9 
10 namespace Eegeo
11 {
12  namespace Routes
13  {
14  namespace Fitting
15  {
16  namespace NavGraphConforming
17  {
18  using namespace Resources::Roads::Navigation;
19 
21  {
22  public:
23 
24  struct Key
25  {
26  private:
27  const NavigationGraphRoad* roadA;
28  const NavigationGraphRoad* roadB;
29  bool directionFromToA;
30  bool directionFromToB;
31 
32 
33  public:
34  Key(const NavigationGraphRoad* roadA,
35  const NavigationGraphRoad* roadB,
36  bool directionFromToA,
37  bool directionFromToB)
38  : roadA(roadA)
39  , roadB(roadB)
40  , directionFromToA(directionFromToA)
41  , directionFromToB(directionFromToB)
42  {
43 
44  }
45 
46  const NavigationGraphRoad* GetRoadA() const { return roadA; }
47  const NavigationGraphRoad* GetRoadB() const { return roadB; }
48  bool GetDirectionFromToA() const { return directionFromToA; }
49  bool GetDirectionFromToB() const { return directionFromToB; }
50 
51  bool operator ==(const Key& other) const
52  {
53  return roadA == other.roadA &&
54  roadB == other.roadB &&
55  directionFromToA == other.directionFromToA &&
56  directionFromToB == other.directionFromToB;
57  }
58  };
59 
60 
61  static Key MakeKey(const SolverNode& nodeA, const SolverNode& nodeB);
62 
63 
64  bool TryGetValue(const Key& key, bool& out_isConnectionValue) const
65  {
66  TCache::const_iterator iter = m_cache.find(key);
67  if (iter != m_cache.end())
68  {
69  out_isConnectionValue = iter->second;
70  return true;
71  }
72 
73  return false;
74  }
75 
76  void Add(const Key& key, bool value)
77  {
78  m_cache.insert(std::make_pair(key, value));
79  }
80 
81  struct Hash
82  {
83  size_t operator()(const Key& key) const;
84  };
85 
86  typedef Eegeo::unordered_map<Key, bool, Hash>::type TCache;
87  TCache m_cache;
88  };
89  }
90 
91  }
92  }
93 }