All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
UniqueKeyFifo.h
1 // Copyright eeGeo Ltd (2012-2014), All Rights Reserved
2 
3 #pragma once
4 
5 #include "Types.h"
6 #include "MortonKey.h"
7 #include "tr1.h"
8 
9 #include <deque>
10 
11 namespace Eegeo
12 {
13  namespace Routes
14  {
15  namespace Fitting
16  {
18  {
19  public:
20  void PushBack(const Streaming::MortonKey& key);
21  void PopFront();
22 
23  inline const Streaming::MortonKey& Front() const
24  {
25  return m_keys.front();
26  }
27 
28  inline bool Empty() const
29  {
30  return m_keys.empty();
31  }
32 
33  inline const std::deque<Streaming::MortonKey>& Fifo() const
34  {
35  return m_keys;
36  }
37 
38  template <class OutputIterator, class UnaryPredicate>
39  inline OutputIterator RemoveIf(OutputIterator removed, UnaryPredicate predicate)
40  {
41  std::deque<Streaming::MortonKey>::iterator remainingIter = m_keys.begin();
42  for (std::deque<Streaming::MortonKey>::const_iterator iter = m_keys.begin(); iter != m_keys.end(); ++iter)
43  {
44  const Streaming::MortonKey& key = *iter;
45  if (predicate(key))
46  {
47  m_uniqueSet.erase(key.RawValue());
48  *removed = key;
49  ++removed;
50  }
51  else
52  {
53  *remainingIter = key;
54  ++remainingIter;
55  }
56  }
57 
58  m_keys.erase(remainingIter, m_keys.end());
59 
60  Eegeo_ASSERT(m_keys.size() == m_uniqueSet.size());
61 
62  return removed;
63  }
64 
65  private:
66  Eegeo::unordered_set<s64>::type m_uniqueSet;
67  std::deque<Streaming::MortonKey> m_keys;
68  };
69 
70  }
71  }
72 }