comparison OrthancFramework/Sources/FileStorage/FileInfo.cpp @ 4500:3b4940bca158

added safeguards in Orthanc::FileInfo
author Sebastien Jodogne <s.jodogne@gmail.com>
date Tue, 09 Feb 2021 14:49:30 +0100
parents
children a3c6678aa7b1
comparison
equal deleted inserted replaced
4499:6f99949b2878 4500:3b4940bca158
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 #include "../PrecompiledHeaders.h"
24 #include "FileInfo.h"
25
26 #include "../OrthancException.h"
27
28 namespace Orthanc
29 {
30 FileInfo::FileInfo(const std::string& uuid,
31 FileContentType contentType,
32 uint64_t size,
33 const std::string& md5) :
34 valid_(true),
35 uuid_(uuid),
36 contentType_(contentType),
37 uncompressedSize_(size),
38 uncompressedMD5_(md5),
39 compressionType_(CompressionType_None),
40 compressedSize_(size),
41 compressedMD5_(md5)
42 {
43 }
44
45
46 FileInfo::FileInfo(const std::string& uuid,
47 FileContentType contentType,
48 uint64_t uncompressedSize,
49 const std::string& uncompressedMD5,
50 CompressionType compressionType,
51 uint64_t compressedSize,
52 const std::string& compressedMD5) :
53 valid_(true),
54 uuid_(uuid),
55 contentType_(contentType),
56 uncompressedSize_(uncompressedSize),
57 uncompressedMD5_(uncompressedMD5),
58 compressionType_(compressionType),
59 compressedSize_(compressedSize),
60 compressedMD5_(compressedMD5)
61 {
62 }
63
64
65 bool FileInfo::IsValid() const
66 {
67 return valid_;
68 }
69
70
71 const std::string& FileInfo::GetUuid() const
72 {
73 if (valid_)
74 {
75 return uuid_;
76 }
77 else
78 {
79 throw OrthancException(ErrorCode_BadSequenceOfCalls);
80 }
81 }
82
83
84 FileContentType FileInfo::GetContentType() const
85 {
86 if (valid_)
87 {
88 return contentType_;
89 }
90 else
91 {
92 throw OrthancException(ErrorCode_BadSequenceOfCalls);
93 }
94 }
95
96
97 uint64_t FileInfo::GetUncompressedSize() const
98 {
99 if (valid_)
100 {
101 return uncompressedSize_;
102 }
103 else
104 {
105 throw OrthancException(ErrorCode_BadSequenceOfCalls);
106 }
107 }
108
109
110 CompressionType FileInfo::GetCompressionType() const
111 {
112 if (valid_)
113 {
114 return compressionType_;
115 }
116 else
117 {
118 throw OrthancException(ErrorCode_BadSequenceOfCalls);
119 }
120 }
121
122
123 uint64_t FileInfo::GetCompressedSize() const
124 {
125 if (valid_)
126 {
127 return compressedSize_;
128 }
129 else
130 {
131 throw OrthancException(ErrorCode_BadSequenceOfCalls);
132 }
133 }
134
135
136 const std::string& FileInfo::GetCompressedMD5() const
137 {
138 if (valid_)
139 {
140 return compressedMD5_;
141 }
142 else
143 {
144 throw OrthancException(ErrorCode_BadSequenceOfCalls);
145 }
146 }
147
148
149 const std::string& FileInfo::GetUncompressedMD5() const
150 {
151 if (valid_)
152 {
153 return uncompressedMD5_;
154 }
155 else
156 {
157 throw OrthancException(ErrorCode_BadSequenceOfCalls);
158 }
159 }
160 }