comparison OrthancServer/ServerContext.cpp @ 3001:7695a9c81099

refactoring /tools/find using LookupResource::IVisitor
author Sebastien Jodogne <s.jodogne@gmail.com>
date Tue, 11 Dec 2018 18:36:38 +0100
parents 9c0b0a6d8b54
children 5ae3ff2398e9
comparison
equal deleted inserted replaced
2998:0a52af0c66e7 3001:7695a9c81099
771 return false; 771 return false;
772 #endif 772 #endif
773 } 773 }
774 774
775 775
776 void ServerContext::Apply(bool& isComplete, 776 void ServerContext::Apply(LookupResource::IVisitor& visitor,
777 std::list<std::string>& result,
778 const ::Orthanc::LookupResource& lookup, 777 const ::Orthanc::LookupResource& lookup,
779 size_t since, 778 size_t since,
780 size_t limit) 779 size_t limit)
781 { 780 {
782 result.clear();
783 isComplete = true;
784
785 std::vector<std::string> resources, instances; 781 std::vector<std::string> resources, instances;
786 GetIndex().FindCandidates(resources, instances, lookup); 782 GetIndex().FindCandidates(resources, instances, lookup);
787 783
788 assert(resources.size() == instances.size()); 784 assert(resources.size() == instances.size());
789 785
786 size_t countResults = 0;
790 size_t skipped = 0; 787 size_t skipped = 0;
788
791 for (size_t i = 0; i < instances.size(); i++) 789 for (size_t i = 0; i < instances.size(); i++)
792 { 790 {
793 // TODO - Don't read the full JSON from the disk if only "main 791 // TODO - Don't read the full JSON from the disk if only "main
794 // DICOM tags" are to be returned 792 // DICOM tags" are to be returned
795 Json::Value dicom; 793 Json::Value dicom;
800 if (skipped < since) 798 if (skipped < since)
801 { 799 {
802 skipped++; 800 skipped++;
803 } 801 }
804 else if (limit != 0 && 802 else if (limit != 0 &&
805 result.size() >= limit) 803 countResults >= limit)
806 { 804 {
807 isComplete = false; 805 return; // too many results, don't mark as complete
808 return; // too many results
809 } 806 }
810 else 807 else
811 { 808 {
812 result.push_back(resources[i]); 809 visitor.Visit(resources[i], dicom);
810 countResults ++;
813 } 811 }
814 } 812 }
815 } 813 }
814
815 visitor.MarkAsComplete();
816 } 816 }
817 817
818 818
819 void ServerContext::AddChildInstances(SetOfInstancesJob& job, 819 void ServerContext::AddChildInstances(SetOfInstancesJob& job,
820 const std::string& publicId) 820 const std::string& publicId)