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/odil.h"
21 #include "odil/Value.h"
22 
23 namespace odil
24 {
25 
29 class ODIL_API DataSet
30 {
31 public:
33  explicit DataSet(std::string const & transfer_syntax="");
34 
38  ~DataSet() =default;
39  DataSet(DataSet const &) =default;
40  DataSet(DataSet &&) =default;
41  DataSet & operator=(DataSet const &) =default;
42  DataSet & operator=(DataSet &&) =default;
44 
46  void add(Tag const & tag, Element const & element);
47 
49  void add(Tag const & tag, Element && element);
50 
52  void add(Tag const & tag, VR vr=VR::UNKNOWN);
53 
54 #define ODIL_DATASET_ADD(type) \
55  void add(\
56  Tag const & tag, Value::type const & value, VR vr=VR::UNKNOWN);\
57  void add(\
58  Tag const & tag, Value::type && value, VR vr=VR::UNKNOWN); \
59  void add(\
60  Tag const & tag, \
61  std::initializer_list<Value::type::value_type> const & value, \
62  VR vr=VR::UNKNOWN);
63  /*
64  * No need for for a rvalue reference version of std::initializer_list:
65  * copying a std::initializer_list does not copy the underlying objects.
66  */
67 
68  ODIL_DATASET_ADD(Integers);
69  ODIL_DATASET_ADD(Reals);
70  ODIL_DATASET_ADD(Strings);
71  ODIL_DATASET_ADD(DataSets);
72  ODIL_DATASET_ADD(Binary);
73 #undef ODIL_DATASET_ADD
74 
76  void add(
77  Tag const & tag, std::initializer_list<int> const & value,
78  VR vr=VR::UNKNOWN);
79 
81  void add(
82  Tag const & tag,
83  std::initializer_list<std::initializer_list<uint8_t>> const & value,
84  VR vr=VR::UNKNOWN);
85 
91  void remove(Tag const & tag);
92 
94  bool empty() const;
95 
97  std::size_t size() const;
98 
100  bool has(Tag const & tag) const;
101 
107  VR get_vr(Tag const & tag) const;
108 
114  bool empty(Tag const & tag) const;
115 
121  std::size_t size(Tag const & tag) const;
122 
128  Element const & operator[](Tag const & tag) const;
129 
135  Element & operator[](Tag const & tag);
136 
138  bool is_int(Tag const & tag) const;
139 
141  Value::Integers const & as_int(Tag const & tag) const;
142 
144  Value::Integers & as_int(Tag const & tag);
145 
147  Value::Integer const & as_int(Tag const & tag, unsigned int position) const;
148 
150  bool is_real(Tag const & tag) const;
151 
153  Value::Reals const & as_real(Tag const & tag) const;
154 
156  Value::Reals & as_real(Tag const & tag);
157 
159  Value::Real const & as_real(Tag const & tag, unsigned int position) const;
160 
162  bool is_string(Tag const & tag) const;
163 
165  Value::Strings const & as_string(Tag const & tag) const;
166 
168  Value::Strings & as_string(Tag const & tag);
169 
171  Value::String const & as_string(Tag const & tag, unsigned int position) const;
172 
174  bool is_data_set(Tag const & tag) const;
175 
177  Value::DataSets const & as_data_set(Tag const & tag) const;
178 
180  Value::DataSets & as_data_set(Tag const & tag);
181 
183  DataSet const & as_data_set(Tag const & tag, unsigned int position) const;
184 
186  bool is_binary(Tag const & tag) const;
187 
189  Value::Binary const & as_binary(Tag const & tag) const;
190 
192  Value::Binary & as_binary(Tag const & tag);
193 
195  Value::Binary::value_type const &
196  as_binary(Tag const & tag, unsigned int position) const;
197 
199  typedef std::map<Tag, Element>::const_iterator const_iterator;
200 
202  const_iterator begin() const;
203 
205  const_iterator end() const;
206 
208  bool operator==(DataSet const & other) const;
209 
211  bool operator!=(DataSet const & other) const;
212 
214  void clear(Tag const & tag);
215 
217  std::string const & get_transfer_syntax() const;
218 
220  void set_transfer_syntax(std::string const & transfer_syntax);
221 
222 private:
223  typedef std::map<Tag, Element> ElementMap;
224 
225  ElementMap _elements;
226 
228  std::string _transfer_syntax;
229 };
230 
231 }
232 
233 #endif // _8424446e_1153_4acc_9f57_e86faa7246e3
std::vector< String > Strings
String container.
Definition: Value.h:57
std::vector< Real > Reals
Real container.
Definition: Value.h:54
double Real
Real type.
Definition: Value.h:45
Definition: Association.cpp:39
A DICOM element tag.
Definition: Tag.h:24
std::string String
String type.
Definition: Value.h:48
std::vector< Integer > Integers
Integer container.
Definition: Value.h:51
std::vector< DataSet > DataSets
Data sets container.
Definition: Value.h:60
std::vector< std::vector< uint8_t > > Binary
Binary data container.
Definition: Value.h:63
DICOM Data set.
Definition: DataSet.h:29
std::map< Tag, Element >::const_iterator const_iterator
Iterator to the elements.
Definition: DataSet.h:199
Element of a DICOM data set.
Definition: Element.h:26
int64_t Integer
Integer type.
Definition: Value.h:42