annotate OrthancFramework/Sources/Cache/SharedArchive.h @ 4744:c125632f9468

cppcheck
author Sebastien Jodogne <s.jodogne@gmail.com>
date Tue, 06 Jul 2021 13:29:57 +0200
parents d9473bd5ed43
children 7053502fbf97
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1367
fe6e5a9f1ea2 SharedArchive
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1 /**
fe6e5a9f1ea2 SharedArchive
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2 * Orthanc - A Lightweight, RESTful DICOM Store
1900
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1368
diff changeset
3 * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics
1367
fe6e5a9f1ea2 SharedArchive
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
4 * Department, University Hospital of Liege, Belgium
4437
d9473bd5ed43 upgrade to year 2021
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4300
diff changeset
5 * Copyright (C) 2017-2021 Osimis S.A., Belgium
1367
fe6e5a9f1ea2 SharedArchive
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
6 *
fe6e5a9f1ea2 SharedArchive
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
7 * This program is free software: you can redistribute it and/or
4119
bf7b9edf6b81 re-licensing the OrthancFramework to LGPL, in order to license Stone of Orthanc under LGPL
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4063
diff changeset
8 * modify it under the terms of the GNU Lesser General Public License
bf7b9edf6b81 re-licensing the OrthancFramework to LGPL, in order to license Stone of Orthanc under LGPL
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4063
diff changeset
9 * as published by the Free Software Foundation, either version 3 of
bf7b9edf6b81 re-licensing the OrthancFramework to LGPL, in order to license Stone of Orthanc under LGPL
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4063
diff changeset
10 * the License, or (at your option) any later version.
1367
fe6e5a9f1ea2 SharedArchive
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
11 *
fe6e5a9f1ea2 SharedArchive
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
12 * This program is distributed in the hope that it will be useful, but
fe6e5a9f1ea2 SharedArchive
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
fe6e5a9f1ea2 SharedArchive
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
4119
bf7b9edf6b81 re-licensing the OrthancFramework to LGPL, in order to license Stone of Orthanc under LGPL
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4063
diff changeset
15 * Lesser General Public License for more details.
1367
fe6e5a9f1ea2 SharedArchive
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
16 *
4119
bf7b9edf6b81 re-licensing the OrthancFramework to LGPL, in order to license Stone of Orthanc under LGPL
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4063
diff changeset
17 * You should have received a copy of the GNU Lesser General Public
bf7b9edf6b81 re-licensing the OrthancFramework to LGPL, in order to license Stone of Orthanc under LGPL
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4063
diff changeset
18 * License along with this program. If not, see
bf7b9edf6b81 re-licensing the OrthancFramework to LGPL, in order to license Stone of Orthanc under LGPL
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4063
diff changeset
19 * <http://www.gnu.org/licenses/>.
1367
fe6e5a9f1ea2 SharedArchive
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
20 **/
fe6e5a9f1ea2 SharedArchive
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
21
fe6e5a9f1ea2 SharedArchive
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
22
fe6e5a9f1ea2 SharedArchive
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
23 #pragma once
fe6e5a9f1ea2 SharedArchive
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
24
2407
5edec967055e fix sandboxed builds
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2244
diff changeset
25 #if !defined(ORTHANC_SANDBOXED)
5edec967055e fix sandboxed builds
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2244
diff changeset
26 # error The macro ORTHANC_SANDBOXED must be defined
5edec967055e fix sandboxed builds
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2244
diff changeset
27 #endif
5edec967055e fix sandboxed builds
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2244
diff changeset
28
5edec967055e fix sandboxed builds
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2244
diff changeset
29 #if ORTHANC_SANDBOXED == 1
5edec967055e fix sandboxed builds
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2244
diff changeset
30 # error The class SharedArchive cannot be used in sandboxed environments
5edec967055e fix sandboxed builds
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2244
diff changeset
31 #endif
5edec967055e fix sandboxed builds
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2244
diff changeset
32
1367
fe6e5a9f1ea2 SharedArchive
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
33 #include "LeastRecentlyUsedIndex.h"
fe6e5a9f1ea2 SharedArchive
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
34 #include "../IDynamicObject.h"
fe6e5a9f1ea2 SharedArchive
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
35
fe6e5a9f1ea2 SharedArchive
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
36 #include <map>
fe6e5a9f1ea2 SharedArchive
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
37 #include <boost/thread.hpp>
fe6e5a9f1ea2 SharedArchive
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
38
fe6e5a9f1ea2 SharedArchive
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
39 namespace Orthanc
fe6e5a9f1ea2 SharedArchive
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
40 {
4063
e00f3d089991 shared library of orthanc framework
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4044
diff changeset
41 class ORTHANC_PUBLIC SharedArchive : public boost::noncopyable
1367
fe6e5a9f1ea2 SharedArchive
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
42 {
fe6e5a9f1ea2 SharedArchive
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
43 private:
fe6e5a9f1ea2 SharedArchive
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
44 typedef std::map<std::string, IDynamicObject*> Archive;
fe6e5a9f1ea2 SharedArchive
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
45
fe6e5a9f1ea2 SharedArchive
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
46 size_t maxSize_;
fe6e5a9f1ea2 SharedArchive
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
47 boost::mutex mutex_;
fe6e5a9f1ea2 SharedArchive
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
48 Archive archive_;
3557
4d809b2e1141 better cache toolbox: MemoryObjectCache
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3060
diff changeset
49 LeastRecentlyUsedIndex<std::string> lru_;
1367
fe6e5a9f1ea2 SharedArchive
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
50
fe6e5a9f1ea2 SharedArchive
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
51 void RemoveInternal(const std::string& id);
fe6e5a9f1ea2 SharedArchive
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
52
fe6e5a9f1ea2 SharedArchive
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
53 public:
4063
e00f3d089991 shared library of orthanc framework
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4044
diff changeset
54 class ORTHANC_PUBLIC Accessor : public boost::noncopyable
1367
fe6e5a9f1ea2 SharedArchive
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
55 {
fe6e5a9f1ea2 SharedArchive
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
56 private:
fe6e5a9f1ea2 SharedArchive
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
57 boost::mutex::scoped_lock lock_;
fe6e5a9f1ea2 SharedArchive
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
58 IDynamicObject* item_;
fe6e5a9f1ea2 SharedArchive
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
59
fe6e5a9f1ea2 SharedArchive
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
60 public:
fe6e5a9f1ea2 SharedArchive
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
61 Accessor(SharedArchive& that,
fe6e5a9f1ea2 SharedArchive
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
62 const std::string& id);
fe6e5a9f1ea2 SharedArchive
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
63
4300
b30a8de92ad9 abi continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4199
diff changeset
64 bool IsValid() const;
2976
cb5d75143da0 Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
65
cb5d75143da0 Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
66 IDynamicObject& GetItem() const;
1367
fe6e5a9f1ea2 SharedArchive
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
67 };
fe6e5a9f1ea2 SharedArchive
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
68
fe6e5a9f1ea2 SharedArchive
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
69
4199
fbc49a65340a cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4119
diff changeset
70 explicit SharedArchive(size_t maxSize);
1367
fe6e5a9f1ea2 SharedArchive
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
71
fe6e5a9f1ea2 SharedArchive
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
72 ~SharedArchive();
fe6e5a9f1ea2 SharedArchive
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
73
fe6e5a9f1ea2 SharedArchive
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
74 std::string Add(IDynamicObject* obj); // Takes the ownership
fe6e5a9f1ea2 SharedArchive
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
75
fe6e5a9f1ea2 SharedArchive
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
76 void Remove(const std::string& id);
fe6e5a9f1ea2 SharedArchive
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
77
fe6e5a9f1ea2 SharedArchive
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
78 void List(std::list<std::string>& items);
fe6e5a9f1ea2 SharedArchive
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
79 };
fe6e5a9f1ea2 SharedArchive
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
80 }
fe6e5a9f1ea2 SharedArchive
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
81
fe6e5a9f1ea2 SharedArchive
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
82