# HG changeset patch # User Sebastien Jodogne # Date 1556544593 -7200 # Node ID d9c0a66304cbcf6d0c0a4f96dbb8e5a2edb10319 # Parent 7a7e36c52d62767643a822464f7347bf79808b32 Scene2D::ReleaseLayer() diff -r 7a7e36c52d62 -r d9c0a66304cb Framework/Scene2D/Scene2D.cpp --- a/Framework/Scene2D/Scene2D.cpp Mon Apr 29 15:24:59 2019 +0200 +++ b/Framework/Scene2D/Scene2D.cpp Mon Apr 29 15:29:53 2019 +0200 @@ -46,8 +46,26 @@ ISceneLayer& GetLayer() const { - assert(layer_.get() != NULL); - return *layer_; + if (layer_.get() == NULL) + { + throw Orthanc::OrthancException(Orthanc::ErrorCode_BadSequenceOfCalls); + } + else + { + return *layer_; + } + } + + ISceneLayer* ReleaseLayer() + { + if (layer_.get() == NULL) + { + throw Orthanc::OrthancException(Orthanc::ErrorCode_BadSequenceOfCalls); + } + else + { + return layer_.release(); + } } uint64_t GetIdentifier() const @@ -131,7 +149,7 @@ if (found == content_.end()) { - throw Orthanc::OrthancException(Orthanc::ErrorCode_BadSequenceOfCalls); + throw Orthanc::OrthancException(Orthanc::ErrorCode_ParameterOutOfRange); } else { @@ -141,6 +159,28 @@ } + ISceneLayer* Scene2D::ReleaseLayer(int depth) + { + Content::iterator found = content_.find(depth); + + if (found == content_.end()) + { + throw Orthanc::OrthancException(Orthanc::ErrorCode_ParameterOutOfRange); + } + else + { + assert(found->second != NULL); + + std::auto_ptr layer(found->second->ReleaseLayer()); + assert(layer.get() != NULL); + + content_.erase(found); + + return layer.release(); + } + } + + void Scene2D::Apply(IVisitor& visitor) const { for (Content::const_iterator it = content_.begin(); diff -r 7a7e36c52d62 -r d9c0a66304cb Framework/Scene2D/Scene2D.h --- a/Framework/Scene2D/Scene2D.h Mon Apr 29 15:24:59 2019 +0200 +++ b/Framework/Scene2D/Scene2D.h Mon Apr 29 15:29:53 2019 +0200 @@ -77,6 +77,8 @@ ISceneLayer& GetLayer(int depth) const; + ISceneLayer* ReleaseLayer(int depth); + void Apply(IVisitor& visitor) const; const AffineTransform2D& GetSceneToCanvasTransform() const