6 #include "SceneElement.h"
7 #include "ISceneElementRemover.h"
8 #include "ISceneElementSource.h"
9 #include "ISceneElementFilterCriteria.h"
10 #include "ISceneElementObservable.h"
11 #include "PackedRenderable.h"
12 #include "ISceneElementObserver.h"
26 class SceneElementRepository :
public ISceneElementSource<T>, ISceneElementRemover<T>, ISceneElementObservable<T>,
protected Eegeo::NonCopyable
28 typedef SceneElement<T> TSceneElement;
29 typedef TSceneElement* TSceneElementPtr;
30 typedef std::vector<TSceneElementPtr> TSceneElementPtrVector;
33 TSceneElementPtrVector m_sceneElements;
34 typedef ISceneElementObserver<T> TObserver;
35 typedef TObserver* TObserverPtr;
36 typedef std::vector<TObserverPtr> TObserverPtrVec;
37 TObserverPtrVec m_observers;
39 void NotifyObserversOfAdd(TSceneElement& sceneElementAdded)
const
41 for(
typename TObserverPtrVec::const_iterator it = m_observers.begin(); it != m_observers.end(); ++it)
43 (*it)->OnSceneElementAdded(sceneElementAdded);
47 void NotifyObserversOfRemove(TSceneElement& sceneElementRemoved)
const
49 for(
typename TObserverPtrVec::const_iterator it = m_observers.begin(); it != m_observers.end(); ++it)
51 (*it)->OnSceneElementRemoved(sceneElementRemoved);
56 SceneElementRepository()
60 ~SceneElementRepository()
65 void AddObserver(ISceneElementObserver<T>& observerToAdd)
67 m_observers.push_back(&observerToAdd);
70 void RemoveObserver(ISceneElementObserver<T>& observerToRemove)
72 m_observers.erase(std::remove(m_observers.begin(), m_observers.end(), &observerToRemove));
75 int GetNumOfSceneElements()
const
77 return m_sceneElements.size();
80 int GetCapacity()
const
82 return m_sceneElements.capacity();
85 void GetSceneElements(std::vector<SceneElement<T>*>& out_sceneElements)
const
87 out_sceneElements.insert(out_sceneElements.end(), m_sceneElements.begin(), m_sceneElements.end());
90 void Add(SceneElement<T>& sceneElement)
92 sceneElement.SetRemover(
this);
93 m_sceneElements.push_back(&sceneElement);
94 NotifyObserversOfAdd(sceneElement);
97 void Remove(SceneElement<T>* pSceneElement)
99 Eegeo_ASSERT(std::find(m_sceneElements.begin(), m_sceneElements.end(), pSceneElement) != m_sceneElements.end());
100 size_t size = m_sceneElements.size();
101 m_sceneElements.erase(std::remove(m_sceneElements.begin(), m_sceneElements.end(), pSceneElement));
102 Eegeo_ASSERT(m_sceneElements.size() == size - 1);
103 NotifyObserversOfRemove(*pSceneElement);