odil
C++11libraryfortheDICOMstandard
DataSet.h
1 /*************************************************************************
2  * odil - Copyright (C) Universite de Strasbourg
3  * Distributed under the terms of the CeCILL-B license, as published by
4  * the CEA-CNRS-INRIA. Refer to the LICENSE file or to
5  * http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html
6  * for details.
7  ************************************************************************/
8 
9 #ifndef _8424446e_1153_4acc_9f57_e86faa7246e3
10 #define _8424446e_1153_4acc_9f57_e86faa7246e3
11 
12 #include <cstddef>
13 #include <cstdint>
14 #include <initializer_list>
15 #include <map>
16 #include <string>
17 #include <vector>
18 
19 #include "odil/Element.h"
20 #include "odil/Value.h"
21 
22 namespace odil
23 {
24 
28 class DataSet
29 {
30 public:
32  explicit DataSet(std::string const & transfer_syntax="");
33 
35  void add(Tag const & tag, Element const & element);
36 
38  void add(Tag const & tag, VR vr=VR::UNKNOWN);
39 
41  void add(
42  Tag const & tag, Value::Integers const & value, VR vr=VR::UNKNOWN);
43 
45  void add(
46  Tag const & tag, Value::Reals const & value, VR vr=VR::UNKNOWN);
47 
49  void add(
50  Tag const & tag, Value::Strings const & value, VR vr=VR::UNKNOWN);
51 
53  void add(
54  Tag const & tag, Value::DataSets const & value, VR vr=VR::UNKNOWN);
55 
57  void add(
58  Tag const & tag, Value::Binary const & value, VR vr=VR::UNKNOWN);
59 
61  void add(
62  Tag const & tag, std::initializer_list<int> const & value,
63  VR vr=VR::UNKNOWN);
64 
66  void add(
67  Tag const & tag, std::initializer_list<Value::Integer> const & value,
68  VR vr=VR::UNKNOWN);
69 
71  void add(
72  Tag const & tag, std::initializer_list<Value::Real> const & value,
73  VR vr=VR::UNKNOWN);
74 
76  void add(
77  Tag const & tag, std::initializer_list<Value::String> const & value,
78  VR vr=VR::UNKNOWN);
79 
81  void add(
82  Tag const & tag, std::initializer_list<DataSet> const & value,
83  VR vr=VR::UNKNOWN);
84 
90  void remove(Tag const & tag);
91 
93  bool empty() const;
94 
96  std::size_t size() const;
97 
99  bool has(Tag const & tag) const;
100 
106  VR get_vr(Tag const & tag) const;
107 
113  bool empty(Tag const & tag) const;
114 
120  std::size_t size(Tag const & tag) const;
121 
127  Element const & operator[](Tag const & tag) const;
128 
134  Element & operator[](Tag const & tag);
135 
137  bool is_int(Tag const & tag) const;
138 
140  Value::Integers const & as_int(Tag const & tag) const;
141 
143  Value::Integers & as_int(Tag const & tag);
144 
146  Value::Integer const & as_int(Tag const & tag, unsigned int position) const;
147 
149  bool is_real(Tag const & tag) const;
150 
152  Value::Reals const & as_real(Tag const & tag) const;
153 
155  Value::Reals & as_real(Tag const & tag);
156 
158  Value::Real const & as_real(Tag const & tag, unsigned int position) const;
159 
161  bool is_string(Tag const & tag) const;
162 
164  Value::Strings const & as_string(Tag const & tag) const;
165 
167  Value::Strings & as_string(Tag const & tag);
168 
170  Value::String const & as_string(Tag const & tag, unsigned int position) const;
171 
173  bool is_data_set(Tag const & tag) const;
174 
176  Value::DataSets const & as_data_set(Tag const & tag) const;
177 
179  Value::DataSets & as_data_set(Tag const & tag);
180 
182  DataSet const & as_data_set(Tag const & tag, unsigned int position) const;
183 
185  bool is_binary(Tag const & tag) const;
186 
188  Value::Binary const & as_binary(Tag const & tag) const;
189 
191  Value::Binary & as_binary(Tag const & tag);
192 
194  Value::Binary::value_type const &
195  as_binary(Tag const & tag, unsigned int position) const;
196 
198  typedef std::map<Tag, Element>::const_iterator const_iterator;
199 
201  const_iterator begin() const { return this->_elements.begin(); }
202 
204  const_iterator end() const { return this->_elements.end(); }
205 
207  bool operator==(DataSet const & other) const;
208 
210  bool operator!=(DataSet const & other) const;
211 
213  std::string const & get_transfer_syntax() const;
214 
216  void set_transfer_syntax(std::string const & transfer_syntax);
217 
218 private:
219  typedef std::map<Tag, Element> ElementMap;
220 
221  ElementMap _elements;
222 
224  std::string _transfer_syntax;
225 };
226 
227 }
228 
229 #endif // _8424446e_1153_4acc_9f57_e86faa7246e3
bool is_binary(Tag const &tag) const
Test whether an existing element has binary type.
Definition: DataSet.cpp:369
VR get_vr(Tag const &tag) const
Return the VR of an element in the data set.
Definition: DataSet.cpp:404
bool is_int(Tag const &tag) const
Test whether an existing element has integer type.
Definition: DataSet.cpp:257
std::vector< String > Strings
String container.
Definition: Value.h:55
Element const & operator[](Tag const &tag) const
Access the given element.
Definition: DataSet.cpp:220
std::vector< Real > Reals
Real container.
Definition: Value.h:52
const_iterator end() const
Return an iterator to the end of the elements.
Definition: DataSet.h:204
double Real
Real type.
Definition: Value.h:43
Value::Integers const & as_int(Tag const &tag) const
Return the integers contained in an existing element (read-only).
Definition: DataSet.cpp:264
bool has(Tag const &tag) const
Test whether an element is in the data set.
Definition: DataSet.cpp:397
Value::Strings const & as_string(Tag const &tag) const
Return the strings contained in an existing element (read-only).
Definition: DataSet.cpp:320
Definition: Association.cpp:39
A DICOM element tag.
Definition: Tag.h:22
bool is_data_set(Tag const &tag) const
Test whether an existing element has data set type.
Definition: DataSet.cpp:341
bool operator!=(DataSet const &other) const
Difference test.
Definition: DataSet.cpp:450
bool is_real(Tag const &tag) const
Test whether an existing element has real type.
Definition: DataSet.cpp:285
bool operator==(DataSet const &other) const
Equality test.
Definition: DataSet.cpp:443
Value::DataSets const & as_data_set(Tag const &tag) const
Return the data sets contained in an existing element (read-only).
Definition: DataSet.cpp:348
std::string String
String type.
Definition: Value.h:46
std::vector< Integer > Integers
Integer container.
Definition: Value.h:49
void set_transfer_syntax(std::string const &transfer_syntax)
Set the current transfer syntax.
Definition: DataSet.cpp:464
std::vector< DataSet > DataSets
Data sets container.
Definition: Value.h:58
const_iterator begin() const
Return an iterator to the start of the elements.
Definition: DataSet.h:201
Value::Binary const & as_binary(Tag const &tag) const
Return the binary items contained in an existing element (read-only).
Definition: DataSet.cpp:376
bool is_string(Tag const &tag) const
Test whether an existing element has string type.
Definition: DataSet.cpp:313
std::vector< std::vector< uint8_t > > Binary
Binary data container.
Definition: Value.h:61
DataSet(std::string const &transfer_syntax="")
Create an empty data set.
Definition: DataSet.cpp:25
DICOM Data set.
Definition: DataSet.h:28
std::map< Tag, Element >::const_iterator const_iterator
Iterator to the elements.
Definition: DataSet.h:198
Value::Reals const & as_real(Tag const &tag) const
Return the reals contained in an existing element (read-only).
Definition: DataSet.cpp:292
std::size_t size() const
Return the number of elements in the data set.
Definition: DataSet.cpp:213
std::string const & get_transfer_syntax() const
Return the current transfer syntax.
Definition: DataSet.cpp:457
Element of a DICOM data set.
Definition: Element.h:25
void add(Tag const &tag, Element const &element)
Add an element to the dataset.
Definition: DataSet.cpp:33
int64_t Integer
Integer type.
Definition: Value.h:40
bool empty() const
Test whether the data set is empty.
Definition: DataSet.cpp:206