annotate OrthancFramework/Sources/DicomParsing/ParsedDicomCache.cpp @ 4456:3e4f7b7840f0

new class: ParsedDicomCache()
author Sebastien Jodogne <s.jodogne@gmail.com>
date Tue, 19 Jan 2021 16:11:23 +0100
parents
children 789676a8c96a
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
4456
3e4f7b7840f0 new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1 /**
3e4f7b7840f0 new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2 * Orthanc - A Lightweight, RESTful DICOM Store
3e4f7b7840f0 new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3 * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics
3e4f7b7840f0 new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
4 * Department, University Hospital of Liege, Belgium
3e4f7b7840f0 new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
5 * Copyright (C) 2017-2021 Osimis S.A., Belgium
3e4f7b7840f0 new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
6 *
3e4f7b7840f0 new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
7 * This program is free software: you can redistribute it and/or
3e4f7b7840f0 new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
8 * modify it under the terms of the GNU Lesser General Public License
3e4f7b7840f0 new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
9 * as published by the Free Software Foundation, either version 3 of
3e4f7b7840f0 new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
10 * the License, or (at your option) any later version.
3e4f7b7840f0 new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
11 *
3e4f7b7840f0 new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
12 * This program is distributed in the hope that it will be useful, but
3e4f7b7840f0 new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
3e4f7b7840f0 new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
3e4f7b7840f0 new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
15 * Lesser General Public License for more details.
3e4f7b7840f0 new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
16 *
3e4f7b7840f0 new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
17 * You should have received a copy of the GNU Lesser General Public
3e4f7b7840f0 new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
18 * License along with this program. If not, see
3e4f7b7840f0 new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
19 * <http://www.gnu.org/licenses/>.
3e4f7b7840f0 new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
20 **/
3e4f7b7840f0 new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
21
3e4f7b7840f0 new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
22
3e4f7b7840f0 new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
23 #include "../PrecompiledHeaders.h"
3e4f7b7840f0 new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
24 #include "ParsedDicomCache.h"
3e4f7b7840f0 new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
25
3e4f7b7840f0 new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
26 #include "../OrthancException.h"
3e4f7b7840f0 new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
27
3e4f7b7840f0 new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
28 namespace Orthanc
3e4f7b7840f0 new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
29 {
3e4f7b7840f0 new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
30 class ParsedDicomCache::Item : public ICacheable
3e4f7b7840f0 new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
31 {
3e4f7b7840f0 new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
32 private:
3e4f7b7840f0 new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
33 std::unique_ptr<ParsedDicomFile> dicom_;
3e4f7b7840f0 new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
34 size_t fileSize_;
3e4f7b7840f0 new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
35
3e4f7b7840f0 new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
36 public:
3e4f7b7840f0 new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
37 Item(ParsedDicomFile* dicom,
3e4f7b7840f0 new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
38 size_t fileSize) :
3e4f7b7840f0 new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
39 dicom_(dicom),
3e4f7b7840f0 new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
40 fileSize_(fileSize)
3e4f7b7840f0 new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
41 {
3e4f7b7840f0 new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
42 if (dicom == NULL)
3e4f7b7840f0 new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
43 {
3e4f7b7840f0 new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
44 throw OrthancException(ErrorCode_NullPointer);
3e4f7b7840f0 new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
45 }
3e4f7b7840f0 new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
46 }
3e4f7b7840f0 new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
47
3e4f7b7840f0 new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
48 virtual size_t GetMemoryUsage() const ORTHANC_OVERRIDE
3e4f7b7840f0 new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
49 {
3e4f7b7840f0 new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
50 return fileSize_;
3e4f7b7840f0 new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
51 }
3e4f7b7840f0 new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
52
3e4f7b7840f0 new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
53 ParsedDicomFile& GetDicom() const
3e4f7b7840f0 new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
54 {
3e4f7b7840f0 new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
55 assert(dicom_.get() != NULL);
3e4f7b7840f0 new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
56 return *dicom_;
3e4f7b7840f0 new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
57 }
3e4f7b7840f0 new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
58 };
3e4f7b7840f0 new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
59
3e4f7b7840f0 new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
60
3e4f7b7840f0 new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
61 ParsedDicomCache::ParsedDicomCache(size_t size) :
3e4f7b7840f0 new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
62 cacheSize_(size),
3e4f7b7840f0 new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
63 largeSize_(0)
3e4f7b7840f0 new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
64 {
3e4f7b7840f0 new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
65 if (size == 0)
3e4f7b7840f0 new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
66 {
3e4f7b7840f0 new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
67 throw OrthancException(ErrorCode_ParameterOutOfRange);
3e4f7b7840f0 new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
68 }
3e4f7b7840f0 new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
69 }
3e4f7b7840f0 new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
70
3e4f7b7840f0 new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
71
3e4f7b7840f0 new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
72 size_t ParsedDicomCache::GetCurrentSize() // For unit tests only
3e4f7b7840f0 new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
73 {
3e4f7b7840f0 new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
74 boost::mutex::scoped_lock lock(mutex_);
3e4f7b7840f0 new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
75
3e4f7b7840f0 new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
76 if (cache_.get() == NULL)
3e4f7b7840f0 new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
77 {
3e4f7b7840f0 new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
78 return largeSize_;
3e4f7b7840f0 new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
79 }
3e4f7b7840f0 new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
80 else
3e4f7b7840f0 new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
81 {
3e4f7b7840f0 new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
82 assert(largeSize_ == 0);
3e4f7b7840f0 new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
83 return cache_->GetCurrentSize();
3e4f7b7840f0 new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
84 }
3e4f7b7840f0 new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
85 }
3e4f7b7840f0 new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
86
3e4f7b7840f0 new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
87
3e4f7b7840f0 new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
88 void ParsedDicomCache::Invalidate(const std::string& id)
3e4f7b7840f0 new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
89 {
3e4f7b7840f0 new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
90 boost::mutex::scoped_lock lock(mutex_);
3e4f7b7840f0 new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
91
3e4f7b7840f0 new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
92 if (cache_.get() != NULL)
3e4f7b7840f0 new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
93 {
3e4f7b7840f0 new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
94 cache_->Invalidate(id);
3e4f7b7840f0 new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
95 }
3e4f7b7840f0 new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
96
3e4f7b7840f0 new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
97 if (largeId_ == id)
3e4f7b7840f0 new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
98 {
3e4f7b7840f0 new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
99 largeDicom_.reset(NULL);
3e4f7b7840f0 new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
100 largeSize_ = 0;
3e4f7b7840f0 new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
101 }
3e4f7b7840f0 new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
102 }
3e4f7b7840f0 new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
103
3e4f7b7840f0 new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
104
3e4f7b7840f0 new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
105 void ParsedDicomCache::Acquire(const std::string& id,
3e4f7b7840f0 new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
106 ParsedDicomFile* dicom, // Takes ownership
3e4f7b7840f0 new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
107 size_t fileSize)
3e4f7b7840f0 new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
108 {
3e4f7b7840f0 new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
109 boost::mutex::scoped_lock lock(mutex_);
3e4f7b7840f0 new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
110
3e4f7b7840f0 new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
111 if (fileSize >= cacheSize_)
3e4f7b7840f0 new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
112 {
3e4f7b7840f0 new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
113 cache_.reset(NULL);
3e4f7b7840f0 new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
114 largeDicom_.reset(dicom);
3e4f7b7840f0 new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
115 largeId_ = id;
3e4f7b7840f0 new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
116 largeSize_ = fileSize;
3e4f7b7840f0 new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
117 }
3e4f7b7840f0 new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
118 else
3e4f7b7840f0 new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
119 {
3e4f7b7840f0 new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
120 largeDicom_.reset(NULL);
3e4f7b7840f0 new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
121 largeSize_ = 0;
3e4f7b7840f0 new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
122
3e4f7b7840f0 new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
123 if (cache_.get() == NULL)
3e4f7b7840f0 new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
124 {
3e4f7b7840f0 new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
125 cache_.reset(new MemoryObjectCache);
3e4f7b7840f0 new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
126 cache_->SetMaximumSize(cacheSize_);
3e4f7b7840f0 new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
127 }
3e4f7b7840f0 new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
128
3e4f7b7840f0 new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
129 cache_->Acquire(id, new Item(dicom, fileSize));
3e4f7b7840f0 new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
130 }
3e4f7b7840f0 new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
131 }
3e4f7b7840f0 new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
132
3e4f7b7840f0 new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
133
3e4f7b7840f0 new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
134 ParsedDicomCache::Accessor::Accessor(ParsedDicomCache& that,
3e4f7b7840f0 new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
135 const std::string& id) :
3e4f7b7840f0 new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
136 lock_(that.mutex_),
3e4f7b7840f0 new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
137 id_(id),
3e4f7b7840f0 new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
138 file_(NULL),
3e4f7b7840f0 new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
139 fileSize_(0)
3e4f7b7840f0 new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
140 {
3e4f7b7840f0 new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
141 if (that.largeDicom_.get() != NULL &&
3e4f7b7840f0 new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
142 that.largeId_ == id)
3e4f7b7840f0 new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
143 {
3e4f7b7840f0 new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
144 file_ = that.largeDicom_.get();
3e4f7b7840f0 new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
145 fileSize_ = that.largeSize_;
3e4f7b7840f0 new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
146 }
3e4f7b7840f0 new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
147 else if (that.cache_.get() != NULL)
3e4f7b7840f0 new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
148 {
3e4f7b7840f0 new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
149 accessor_.reset(new MemoryObjectCache::Accessor(
3e4f7b7840f0 new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
150 *that.cache_, id, true /* unique */));
3e4f7b7840f0 new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
151 if (accessor_->IsValid())
3e4f7b7840f0 new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
152 {
3e4f7b7840f0 new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
153 const Item& item = dynamic_cast<const Item&>(accessor_->GetValue());
3e4f7b7840f0 new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
154 file_ = &item.GetDicom();
3e4f7b7840f0 new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
155 fileSize_ = item.GetMemoryUsage();
3e4f7b7840f0 new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
156 }
3e4f7b7840f0 new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
157 }
3e4f7b7840f0 new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
158 }
3e4f7b7840f0 new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
159
3e4f7b7840f0 new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
160
3e4f7b7840f0 new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
161 ParsedDicomFile& ParsedDicomCache::Accessor::GetDicom() const
3e4f7b7840f0 new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
162 {
3e4f7b7840f0 new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
163 if (IsValid())
3e4f7b7840f0 new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
164 {
3e4f7b7840f0 new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
165 assert(file_ != NULL);
3e4f7b7840f0 new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
166 return *file_;
3e4f7b7840f0 new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
167 }
3e4f7b7840f0 new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
168 else
3e4f7b7840f0 new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
169 {
3e4f7b7840f0 new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
170 throw OrthancException(ErrorCode_BadSequenceOfCalls);
3e4f7b7840f0 new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
171 }
3e4f7b7840f0 new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
172 }
3e4f7b7840f0 new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
173
3e4f7b7840f0 new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
174
3e4f7b7840f0 new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
175 size_t ParsedDicomCache::Accessor::GetFileSize() const
3e4f7b7840f0 new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
176 {
3e4f7b7840f0 new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
177 if (IsValid())
3e4f7b7840f0 new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
178 {
3e4f7b7840f0 new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
179 return fileSize_;
3e4f7b7840f0 new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
180 }
3e4f7b7840f0 new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
181 else
3e4f7b7840f0 new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
182 {
3e4f7b7840f0 new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
183 throw OrthancException(ErrorCode_BadSequenceOfCalls);
3e4f7b7840f0 new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
184 }
3e4f7b7840f0 new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
185 }
3e4f7b7840f0 new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
186 }