Mercurial > hg > orthanc-stone
comparison Framework/Toolbox/ParsedDicomCache.cpp @ 1149:2da8b4d6f8c1 broker
renamed ParsedDicomFileCache as ParsedDicomCache
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Fri, 15 Nov 2019 12:35:35 +0100 |
parents | Framework/Toolbox/ParsedDicomFileCache.cpp@6333e6f7248e |
children | 48befc2bf66d |
comparison
equal
deleted
inserted
replaced
1148:5e164c629923 | 1149:2da8b4d6f8c1 |
---|---|
1 /** | |
2 * Stone of Orthanc | |
3 * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics | |
4 * Department, University Hospital of Liege, Belgium | |
5 * Copyright (C) 2017-2019 Osimis S.A., Belgium | |
6 * | |
7 * This program is free software: you can redistribute it and/or | |
8 * modify it under the terms of the GNU Affero General Public License | |
9 * as published by the Free Software Foundation, either version 3 of | |
10 * the License, or (at your option) any later version. | |
11 * | |
12 * This program is distributed in the hope that it will be useful, but | |
13 * WITHOUT ANY WARRANTY; without even the implied warranty of | |
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
15 * Affero General Public License for more details. | |
16 * | |
17 * You should have received a copy of the GNU Affero General Public License | |
18 * along with this program. If not, see <http://www.gnu.org/licenses/>. | |
19 **/ | |
20 | |
21 | |
22 #include "ParsedDicomCache.h" | |
23 | |
24 namespace OrthancStone | |
25 { | |
26 class ParsedDicomCache::Item : public Orthanc::ICacheable | |
27 { | |
28 private: | |
29 boost::mutex mutex_; | |
30 std::auto_ptr<Orthanc::ParsedDicomFile> dicom_; | |
31 size_t fileSize_; | |
32 bool hasPixelData_; | |
33 | |
34 public: | |
35 Item(Orthanc::ParsedDicomFile* dicom, | |
36 size_t fileSize, | |
37 bool hasPixelData) : | |
38 dicom_(dicom), | |
39 fileSize_(fileSize), | |
40 hasPixelData_(hasPixelData) | |
41 { | |
42 if (dicom == NULL) | |
43 { | |
44 throw Orthanc::OrthancException(Orthanc::ErrorCode_NullPointer); | |
45 } | |
46 } | |
47 | |
48 boost::mutex& GetMutex() | |
49 { | |
50 return mutex_; | |
51 } | |
52 | |
53 virtual size_t GetMemoryUsage() const | |
54 { | |
55 return fileSize_; | |
56 } | |
57 | |
58 Orthanc::ParsedDicomFile& GetDicom() const | |
59 { | |
60 assert(dicom_.get() != NULL); | |
61 return *dicom_; | |
62 } | |
63 | |
64 bool HasPixelData() const | |
65 { | |
66 return hasPixelData_; | |
67 } | |
68 }; | |
69 | |
70 | |
71 void ParsedDicomCache::Acquire(const std::string& key, | |
72 Orthanc::ParsedDicomFile* dicom, | |
73 size_t fileSize, | |
74 bool hasPixelData) | |
75 { | |
76 cache_.Acquire(key, new Item(dicom, fileSize, hasPixelData)); | |
77 } | |
78 | |
79 | |
80 ParsedDicomCache::Reader::Reader(ParsedDicomCache& cache, | |
81 const std::string& key) : | |
82 /** | |
83 * The "DcmFileFormat" object cannot be accessed from multiple | |
84 * threads, even if using only getters. An unique lock (mutex) is | |
85 * mandatory. | |
86 **/ | |
87 accessor_(cache.cache_, key, true /* unique */) | |
88 { | |
89 if (accessor_.IsValid()) | |
90 { | |
91 item_ = &dynamic_cast<Item&>(accessor_.GetValue()); | |
92 } | |
93 else | |
94 { | |
95 item_ = NULL; | |
96 } | |
97 } | |
98 | |
99 | |
100 bool ParsedDicomCache::Reader::HasPixelData() const | |
101 { | |
102 if (item_ == NULL) | |
103 { | |
104 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadSequenceOfCalls); | |
105 } | |
106 else | |
107 { | |
108 return item_->HasPixelData(); | |
109 } | |
110 } | |
111 | |
112 | |
113 Orthanc::ParsedDicomFile& ParsedDicomCache::Reader::GetDicom() const | |
114 { | |
115 if (item_ == NULL) | |
116 { | |
117 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadSequenceOfCalls); | |
118 } | |
119 else | |
120 { | |
121 return item_->GetDicom(); | |
122 } | |
123 } | |
124 | |
125 | |
126 size_t ParsedDicomCache::Reader::GetFileSize() const | |
127 { | |
128 if (item_ == NULL) | |
129 { | |
130 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadSequenceOfCalls); | |
131 } | |
132 else | |
133 { | |
134 return item_->GetMemoryUsage(); | |
135 } | |
136 } | |
137 } |