comparison OrthancServer/DicomInstanceToStore.h @ 1004:a226e0959d8b lua-scripting

DicomInstanceToStore
author Sebastien Jodogne <s.jodogne@gmail.com>
date Tue, 08 Jul 2014 14:06:05 +0200
parents 1d35281d967c
children 84b6d7bca6db
comparison
equal deleted inserted replaced
1003:1d35281d967c 1004:a226e0959d8b
32 32
33 #pragma once 33 #pragma once
34 34
35 #include "ParsedDicomFile.h" 35 #include "ParsedDicomFile.h"
36 #include "ServerIndex.h" 36 #include "ServerIndex.h"
37 #include "../Core/OrthancException.h"
37 38
38 namespace Orthanc 39 namespace Orthanc
39 { 40 {
40 class DicomInstanceToStore 41 class DicomInstanceToStore
41 { 42 {
42 private: 43 private:
43 bool hasBuffer_; 44 template <typename T>
44 const char* buffer_; 45 class SmartContainer
45 size_t bufferSize_; 46 {
46 47 private:
47 ParsedDicomFile* parsed_; 48 T* content_;
48 const DicomMap* summary_; 49 bool toDelete_;
49 const Json::Value* json_; 50 bool isReadOnly_;
51
52 void Deallocate()
53 {
54 if (content_ && toDelete_)
55 {
56 delete content_;
57 toDelete_ = false;
58 content_ = NULL;
59 }
60 }
61
62 public:
63 SmartContainer() : content_(NULL), toDelete_(false)
64 {
65 }
66
67 ~SmartContainer()
68 {
69 Deallocate();
70 }
71
72 void Allocate()
73 {
74 Deallocate();
75 content_ = new T;
76 toDelete_ = true;
77 isReadOnly_ = false;
78 }
79
80 void TakeOwnership(T* content)
81 {
82 if (content == NULL)
83 {
84 throw OrthancException(ErrorCode_ParameterOutOfRange);
85 }
86
87 Deallocate();
88 content_ = content;
89 toDelete_ = true;
90 isReadOnly_ = true;
91 }
92
93 void SetReference(const T& content) // Read-only assign, without transfering ownership
94 {
95 Deallocate();
96 content_ = &const_cast<T&>(content);
97 toDelete_ = false;
98 isReadOnly_ = true;
99 }
100
101 bool HasContent() const
102 {
103 return content_ != NULL;
104 }
105
106 T& GetContent()
107 {
108 if (content_ == NULL)
109 {
110 throw OrthancException(ErrorCode_BadSequenceOfCalls);
111 }
112
113 if (isReadOnly_)
114 {
115 throw OrthancException(ErrorCode_ReadOnly);
116 }
117
118 return *content_;
119 }
120
121 const T& GetConstContent() const
122 {
123 if (content_ == NULL)
124 {
125 throw OrthancException(ErrorCode_BadSequenceOfCalls);
126 }
127
128 return *content_;
129 }
130 };
131
132
133 /*class MemoryBuffer
134 {
135 private:
136 const char* buffer_;
137 size_t size_;
138
139 public:
140 MemoryBuffer() : buffer_(NULL), size_(0)
141 {
142 }
143
144 const char* GetBuffer() const
145 {
146 return buffer_;
147 }
148
149 size_t GetSize() const
150 {
151 return size_;
152 }
153
154 void Assign(const char* buffer, size_t size)
155 {
156 buffer_ = buffer;
157 size_ = size;
158 }
159
160 void Assign(const std::string& buffer)
161 {
162 size_ = buffer.size();
163
164 if (size_ == 0)
165 {
166 buffer_ = NULL;
167 }
168 else
169 {
170 buffer_ = &buffer[0];
171 }
172 }
173 };*/
174
175
176 SmartContainer<std::string> buffer_;
177 SmartContainer<ParsedDicomFile> parsed_;
178 SmartContainer<DicomMap> summary_;
179 SmartContainer<Json::Value> json_;
50 180
51 std::string remoteAet_; 181 std::string remoteAet_;
52 ServerIndex::MetadataMap metadata_; 182 ServerIndex::MetadataMap metadata_;
53 183
54 void ComputeMissingInformation(); 184 void ComputeMissingInformation();
55 185
56 public: 186 public:
57 DicomInstanceToStore(); 187 void SetBuffer(const std::string& dicom)
58 188 {
59 void SetBuffer(const std::string& dicom); 189 buffer_.SetReference(dicom);
60 190 }
61 void SetBuffer(const char* buffer,
62 size_t size);
63 191
64 void SetParsedDicomFile(ParsedDicomFile& parsed) 192 void SetParsedDicomFile(ParsedDicomFile& parsed)
65 { 193 {
66 parsed_ = &parsed; 194 parsed_.SetReference(parsed);
67 } 195 }
68 196
69 void SetSummary(const DicomMap& summary) 197 void SetSummary(const DicomMap& summary)
70 { 198 {
71 summary_ = &summary; 199 summary_.SetReference(summary);
72 } 200 }
73 201
74 void SetJson(const Json::Value& json) 202 void SetJson(const Json::Value& json)
75 { 203 {
76 json_ = &json; 204 json_.SetReference(json);
77 } 205 }
78 206
79 const std::string GetRemoteAet() const 207 const std::string GetRemoteAet() const
80 { 208 {
81 return remoteAet_; 209 return remoteAet_;
84 void SetRemoteAet(const std::string& aet) 212 void SetRemoteAet(const std::string& aet)
85 { 213 {
86 remoteAet_ = aet; 214 remoteAet_ = aet;
87 } 215 }
88 216
89 void SetMetadata(ResourceType level, 217 void AddMetadata(ResourceType level,
90 MetadataType metadata, 218 MetadataType metadata,
91 const std::string& value); 219 const std::string& value);
92 220
93 const ServerIndex::MetadataMap& GetMetadata() const 221 const ServerIndex::MetadataMap& GetMetadata() const
94 { 222 {
95 return metadata_; 223 return metadata_;
96 } 224 }
97 225
98 const char* GetBuffer(); 226 ServerIndex::MetadataMap& GetMetadata()
227 {
228 return metadata_;
229 }
230
231 const char* GetBufferData();
99 232
100 size_t GetBufferSize(); 233 size_t GetBufferSize();
234
235 const DicomMap& GetSummary();
236
237 const Json::Value& GetJson();
101 }; 238 };
102 } 239 }