comparison 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
comparison
equal deleted inserted replaced
4455:a8f554ca5ac6 4456:3e4f7b7840f0
1 /**
2 * Orthanc - A Lightweight, RESTful DICOM Store
3 * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics
4 * Department, University Hospital of Liege, Belgium
5 * Copyright (C) 2017-2021 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 Lesser 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 * Lesser General Public License for more details.
16 *
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this program. If not, see
19 * <http://www.gnu.org/licenses/>.
20 **/
21
22
23 #pragma once
24
25 #include "../Cache/MemoryObjectCache.h"
26 #include "ParsedDicomFile.h"
27
28 namespace Orthanc
29 {
30 class ParsedDicomCache : public boost::noncopyable
31 {
32 private:
33 class Item;
34
35 boost::mutex mutex_;
36 size_t cacheSize_;
37 std::unique_ptr<MemoryObjectCache> cache_;
38 std::unique_ptr<ParsedDicomFile> largeDicom_;
39 std::string largeId_;
40 size_t largeSize_;
41
42 public:
43 explicit ParsedDicomCache(size_t size);
44
45 size_t GetCurrentSize(); // For unit tests only
46
47 void Invalidate(const std::string& id);
48
49 void Acquire(const std::string& id,
50 ParsedDicomFile* dicom, // Takes ownership
51 size_t fileSize);
52
53 class Accessor : public boost::noncopyable
54 {
55 private:
56 boost::mutex::scoped_lock lock_;
57 std::string id_;
58 ParsedDicomFile* file_;
59 size_t fileSize_;
60
61 std::unique_ptr<MemoryObjectCache::Accessor> accessor_;
62
63 public:
64 Accessor(ParsedDicomCache& that,
65 const std::string& id);
66
67 bool IsValid() const
68 {
69 return file_ != NULL;
70 }
71
72 ParsedDicomFile& GetDicom() const;
73
74 size_t GetFileSize() const;
75 };
76 };
77 }