# HG changeset patch # User Sebastien Jodogne # Date 1788271546 -7200 # Node ID d90ff66a934b11c9f997d275d60cbc92f7e21547 # Parent 76d788aef4b0313fafad15d5952747f9448fd411 added LayersCollection::Iterator diff -r 76d788aef4b0 -r d90ff66a934b ViewerPlugin/Annotations/AnnotationsRestApi.cpp --- a/ViewerPlugin/Annotations/AnnotationsRestApi.cpp Tue Sep 01 15:31:04 2026 +0200 +++ b/ViewerPlugin/Annotations/AnnotationsRestApi.cpp Tue Sep 01 16:05:46 2026 +0200 @@ -182,8 +182,6 @@ { public: virtual std::string GetId() const = 0; - - virtual bool IsSharedWith(const UserId& user) const = 0; // TODO - REMOVE? }; @@ -288,49 +286,49 @@ } } - bool HasLayerSharedWith(const UserId& user) const // TODO - Replace by ListLayers() ? + class Iterator : public boost::noncopyable { - for (Content::const_iterator it = content_.begin(); it != content_.end(); ++it) + private: + Content::const_iterator it_; + Content::const_iterator end_; + + public: + Iterator(const LayersCollection& that) : + it_(that.content_.begin()), + end_(that.content_.end()) { - assert(*it != NULL); - if ((*it)->IsSharedWith(user)) + } + + bool IsDone() const + { + return it_ == end_; + } + + const ILayer& GetLayer() const + { + if (IsDone()) { - return true; + throw Orthanc::OrthancException(Orthanc::ErrorCode_BadSequenceOfCalls); + } + else + { + assert(*it_ != NULL); + return **it_; } } - return false; - } - - void ListLayersSharedWith(Json::Value& target, - const UserId& author, - const UserId& user) const // TODO - Replace by ListLayers() ? - { - target.clear(); - - for (Content::const_iterator it = content_.begin(); it != content_.end(); ++it) + void Next() { - assert(*it != NULL); - if (!author.Equals(user) && // Don't add self - (*it)->IsSharedWith(user)) + if (IsDone()) { - Json::Value item; - (*it)->Serialize(item); - target.append(item); + throw Orthanc::OrthancException(Orthanc::ErrorCode_BadSequenceOfCalls); + } + else + { + it_++; } } - } - - void ListLayers(std::list& target) const - { - target.clear(); - - for (Content::const_iterator it = content_.begin(); it != content_.end(); ++it) - { - assert(*it != NULL); - target.push_back((*it)->GetId()); - } - } + }; }; @@ -491,7 +489,7 @@ return name_; } - virtual bool IsSharedWith(const UserId& user) const ORTHANC_OVERRIDE + bool IsSharedWith(const UserId& user) const { assert(user.GetType() == UserId::Type_Root || user.GetType() == UserId::Type_Standard); @@ -623,11 +621,6 @@ author_.Serialize(serialized[KEY_AUTHOR]); } - - virtual bool IsSharedWith(const UserId& user) const ORTHANC_OVERRIDE - { - return false; - } }; @@ -754,14 +747,45 @@ bool HasLayerSharedWith(const UserId& user) const { - return userLayers_.HasLayerSharedWith(user); + LayersCollection::Iterator iterator(userLayers_); + + while (!iterator.IsDone()) + { + const UserLayer& layer = dynamic_cast(iterator.GetLayer()); + + if (layer.IsSharedWith(user)) + { + return true; + } + + iterator.Next(); + } + + return false; } void ListLayersSharedWith(Json::Value& target, const UserId& author, const UserId& user) const { - return userLayers_.ListLayersSharedWith(target, author, user); + target = Json::arrayValue; + + LayersCollection::Iterator iterator(userLayers_); + + while (!iterator.IsDone()) + { + const UserLayer& layer = dynamic_cast(iterator.GetLayer()); + + if (!author.Equals(user) && // Don't add self - TODO MAKES NO SENSE (constant) + layer.IsSharedWith(user)) + { + Json::Value item; + layer.Serialize(item); + target.append(item); + } + + iterator.Next(); + } } void ImportSharedLayer(const UserId& author, @@ -1078,12 +1102,12 @@ if (IsValid()) { - std::list layerIds; - userSettings_->GetSharedLayers().ListLayers(layerIds); + LayersCollection::Iterator iterator(userSettings_->GetSharedLayers()); - for (std::list::const_iterator it = layerIds.begin(); it != layerIds.end(); ++it) + while (!iterator.IsDone()) { - target.push_back(SharedLayerId(userId_, *it)); + target.push_back(SharedLayerId(userId_, iterator.GetLayer().GetId())); + iterator.Next(); } } } @@ -1825,6 +1849,11 @@ reader.ListSharedLayers(layers); } + for (std::list::const_iterator it = layers.begin(); it != layers.end(); ++it) + { + printf("[%s] [%s]\n", it->GetAuthor().GetName().c_str(), it->GetLayerId().c_str()); + } + Json::Value answer; ViewerToolbox::AnswerJson(output, answer); }