comparison OrthancServer/ServerIndex.cpp @ 304:4eea080e6e7a

refactoring
author Sebastien Jodogne <s.jodogne@gmail.com>
date Wed, 19 Dec 2012 14:57:18 +0100
parents 771f12042be9
children 326d5a4a5af3
comparison
equal deleted inserted replaced
303:c76a35a85c69 304:4eea080e6e7a
960 LOG(INFO) << "Patient " << publicId << " has been protected"; 960 LOG(INFO) << "Patient " << publicId << " has been protected";
961 else 961 else
962 LOG(INFO) << "Patient " << publicId << " has been unprotected"; 962 LOG(INFO) << "Patient " << publicId << " has been unprotected";
963 } 963 }
964 964
965
966 void ServerIndex::GetChildInstances(std::list<std::string>& result,
967 const std::string& publicId)
968 {
969 result.clear();
970
971 boost::mutex::scoped_lock lock(mutex_);
972
973 ResourceType type;
974 int64_t top;
975 if (!db_->LookupResource(publicId, top, type))
976 {
977 throw OrthancException(ErrorCode_UnknownResource);
978 }
979
980 if (type == ResourceType_Instance)
981 {
982 // The resource is already an instance: Do not go down the hierarchy
983 result.push_back(publicId);
984 return;
985 }
986
987 std::stack<int64_t> toExplore;
988 toExplore.push(top);
989
990 std::list<int64_t> tmp;
991
992 while (!toExplore.empty())
993 {
994 // Get the internal ID of the current resource
995 int64_t resource = toExplore.top();
996 toExplore.pop();
997
998 if (db_->GetResourceType(resource) == ResourceType_Instance)
999 {
1000 result.push_back(db_->GetPublicId(resource));
1001 }
1002 else
1003 {
1004 // Tag all the children of this resource as to be explored
1005 db_->GetChildrenInternalId(tmp, resource);
1006 for (std::list<int64_t>::const_iterator
1007 it = tmp.begin(); it != tmp.end(); it++)
1008 {
1009 toExplore.push(*it);
1010 }
1011 }
1012 }
1013 }
1014
965 } 1015 }