annotate OrthancFramework/Sources/DicomParsing/ParsedDicomCache.h @ 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 #pragma once
3e4f7b7840f0 new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
24
3e4f7b7840f0 new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
25 #include "../Cache/MemoryObjectCache.h"
3e4f7b7840f0 new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
26 #include "ParsedDicomFile.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 : public boost::noncopyable
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 class Item;
3e4f7b7840f0 new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
34
3e4f7b7840f0 new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
35 boost::mutex mutex_;
3e4f7b7840f0 new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
36 size_t cacheSize_;
3e4f7b7840f0 new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
37 std::unique_ptr<MemoryObjectCache> cache_;
3e4f7b7840f0 new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
38 std::unique_ptr<ParsedDicomFile> largeDicom_;
3e4f7b7840f0 new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
39 std::string largeId_;
3e4f7b7840f0 new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
40 size_t largeSize_;
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 public:
3e4f7b7840f0 new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
43 explicit ParsedDicomCache(size_t size);
3e4f7b7840f0 new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
44
3e4f7b7840f0 new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
45 size_t GetCurrentSize(); // For unit tests only
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 void Invalidate(const std::string& id);
3e4f7b7840f0 new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
48
3e4f7b7840f0 new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
49 void Acquire(const std::string& id,
3e4f7b7840f0 new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
50 ParsedDicomFile* dicom, // Takes ownership
3e4f7b7840f0 new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
51 size_t fileSize);
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 class Accessor : public boost::noncopyable
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 private:
3e4f7b7840f0 new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
56 boost::mutex::scoped_lock lock_;
3e4f7b7840f0 new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
57 std::string id_;
3e4f7b7840f0 new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
58 ParsedDicomFile* file_;
3e4f7b7840f0 new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
59 size_t fileSize_;
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 std::unique_ptr<MemoryObjectCache::Accessor> accessor_;
3e4f7b7840f0 new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
62
3e4f7b7840f0 new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
63 public:
3e4f7b7840f0 new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
64 Accessor(ParsedDicomCache& that,
3e4f7b7840f0 new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
65 const std::string& id);
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 bool IsValid() const
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 return file_ != NULL;
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 ParsedDicomFile& GetDicom() const;
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 size_t GetFileSize() const;
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 };
3e4f7b7840f0 new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
77 }