Object Detection  5.0
Image Processing Using Qt and Opencv
observer.cpp
1 #include "observer.h"
2 #include "subject.h"
3 using namespace Devices;
4 
5 class Observer::_ObserverImpl{
6  Observer *const _ptr;
7 public:
8  _ObserverImpl(Observer *const ptr);
9  void observe(Subject *sub);
10  void stopObserving(Subject *sub);
11 };
12 
13 
14 
15 Observer::~Observer()
16 {
17 
18 }
19 
20 Observer::Observer(QObject *parent) : QObject(parent)
21  ,_pimpl{std::make_unique<Observer::_ObserverImpl>(this)}
22 {
23 
24 }
25 
26 void Observer::observe(Subject *sub)
27 {
28  _pimpl->observe(sub);
29 }
30 
31 void Observer::stopObserving(Subject *sub)
32 {
33  _pimpl->stopObserving(sub);
34 }
35 
36 
37 
38 Observer::_ObserverImpl::_ObserverImpl(Observer * const ptr):_ptr{ptr}
39 {
40 
41 }
42 
43 void Observer::_ObserverImpl::observe(Subject *sub)
44 {
45  if(sub == nullptr)
46  return;
47  sub->addObserver(_ptr);
48 }
49 
50 void Observer::_ObserverImpl::stopObserving(Subject *sub)
51 {
52  if(sub == nullptr)
53  return;
54  sub->removeObserver(_ptr);
55 }