All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
ShapeModelRepositoryObserver.h
1 #pragma once
2 
3 #include "EegeoShapes.h"
4 #include "Types.h"
5 #include "ModelRepository.h"
6 
7 namespace Eegeo
8 {
9  namespace Shapes
10  {
11  template <
12  typename ShapeModelRepositoryType,
13  typename ShapeModelAddedEventType,
14  typename ShapeModelRemovedEventType
15  >
16  class TShapeModelRepositoryObserver : public ShapeModelRepositoryType::ObserverType, private Eegeo::NonCopyable
17  {
18  public:
19  TShapeModelRepositoryObserver(ShapeModelRepositoryType& shapeModelRepository,
20  ShapeModelAddedEventType& shapeModelAddedEvent,
21  ShapeModelRemovedEventType& shapeModelRemovedEvent)
22  : m_shapeModelRepository(shapeModelRepository)
23  , m_shapeModelAddedEvent(shapeModelAddedEvent)
24  , m_shapeModelRemovedEvent(shapeModelRemovedEvent)
25  {
26  m_shapeModelRepository.AddObserver(*this);
27  }
28 
30  {
31  m_shapeModelRepository.RemoveObserver(*this);
32  }
33 
34  virtual void OnItemAdded(const typename ShapeModelRepositoryType::ItemType& item)
35  {
36  m_shapeModelAddedEvent.Raise(*item);
37  }
38 
39  virtual void OnItemRemoved(const typename ShapeModelRepositoryType::ItemType& item)
40  {
41  m_shapeModelRemovedEvent.Raise(*item);
42  }
43 
44  private:
45  ShapeModelRepositoryType& m_shapeModelRepository;
46  ShapeModelAddedEventType& m_shapeModelAddedEvent;
47  ShapeModelRemovedEventType& m_shapeModelRemovedEvent;
48  };
49  }
50 }