Mercurial > hg > orthanc-stone
comparison Framework/Layers/LayerSourceBase.cpp @ 90:64e60018943f wasm
fix and observer refactoring
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Mon, 29 May 2017 11:04:18 +0200 |
parents | f244018a4e4b |
children | 81f73efd81a1 |
comparison
equal
deleted
inserted
replaced
89:f244018a4e4b | 90:64e60018943f |
---|---|
23 | 23 |
24 #include "../../Resources/Orthanc/Core/OrthancException.h" | 24 #include "../../Resources/Orthanc/Core/OrthancException.h" |
25 | 25 |
26 namespace OrthancStone | 26 namespace OrthancStone |
27 { | 27 { |
28 namespace | |
29 { | |
30 class LayerReadyFunctor : public boost::noncopyable | |
31 { | |
32 private: | |
33 std::auto_ptr<ILayerRenderer> layer_; | |
34 const Slice& slice_; | |
35 | |
36 public: | |
37 LayerReadyFunctor(ILayerRenderer* layer, | |
38 const Slice& slice) : | |
39 layer_(layer), | |
40 slice_(slice) | |
41 { | |
42 } | |
43 | |
44 void operator() (ILayerSource::IObserver& observer, | |
45 const ILayerSource& source) | |
46 { | |
47 observer.NotifyLayerReady(layer_, source, slice_); | |
48 } | |
49 }; | |
50 } | |
51 | |
52 void LayerSourceBase::NotifyGeometryReady() | |
53 { | |
54 observers_.Apply(*this, &IObserver::NotifyGeometryReady); | |
55 } | |
56 | |
57 void LayerSourceBase::NotifyGeometryError() | |
58 { | |
59 observers_.Apply(*this, &IObserver::NotifyGeometryError); | |
60 } | |
61 | |
28 void LayerSourceBase::NotifyContentChange() | 62 void LayerSourceBase::NotifyContentChange() |
29 { | 63 { |
30 if (observer_ != NULL) | 64 observers_.Apply(*this, &IObserver::NotifyContentChange); |
31 { | |
32 observer_->NotifyContentChange(*this); | |
33 } | |
34 } | 65 } |
35 | 66 |
36 void LayerSourceBase::NotifySliceChange(const Slice& slice) | 67 void LayerSourceBase::NotifySliceChange(const Slice& slice) |
37 { | 68 { |
38 if (observer_ != NULL) | 69 observers_.Apply(*this, &IObserver::NotifySliceChange, slice); |
39 { | |
40 observer_->NotifySliceChange(*this, slice); | |
41 } | |
42 } | 70 } |
43 | 71 |
44 void LayerSourceBase::NotifyLayerReady(ILayerRenderer* layer, | 72 void LayerSourceBase::NotifyLayerReady(ILayerRenderer* layer, |
45 const Slice& slice) | 73 const Slice& slice) |
46 { | 74 { |
47 std::auto_ptr<ILayerRenderer> tmp(layer); | |
48 | |
49 if (layer == NULL) | 75 if (layer == NULL) |
50 { | 76 { |
51 throw Orthanc::OrthancException(Orthanc::ErrorCode_ParameterOutOfRange); | 77 throw Orthanc::OrthancException(Orthanc::ErrorCode_ParameterOutOfRange); |
52 } | 78 } |
53 | 79 |
54 if (observer_ != NULL) | 80 LayerReadyFunctor functor(layer, slice); |
55 { | 81 observers_.Notify(this, functor); |
56 observer_->NotifyLayerReady(tmp.release(), *this, slice); | |
57 } | |
58 } | 82 } |
59 | 83 |
60 void LayerSourceBase::NotifyLayerError(const SliceGeometry& slice) | 84 void LayerSourceBase::NotifyLayerError(const SliceGeometry& slice) |
61 { | 85 { |
62 if (observer_ != NULL) | 86 observers_.Apply(*this, &IObserver::NotifyLayerError, slice); |
63 { | |
64 observer_->NotifyLayerError(*this, slice); | |
65 } | |
66 } | 87 } |
67 | 88 |
68 void LayerSourceBase::SetObserver(IObserver& observer) | 89 void LayerSourceBase::Register(IObserver& observer) |
69 { | 90 { |
70 if (observer_ == NULL) | 91 observers_.Register(observer); |
71 { | |
72 observer_ = &observer; | |
73 } | |
74 else | |
75 { | |
76 // Cannot add more than one observer | |
77 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadSequenceOfCalls); | |
78 } | |
79 } | 92 } |
80 } | 93 } |