Odil
A C++11 library for the DICOM standard
DataSet.h
Go to the documentation of this file.
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  std::shared_ptr<DataSet> const &
184  as_data_set(Tag const & tag, unsigned int position) const;
185 
187  bool is_binary(Tag const & tag) const;
188 
190  Value::Binary const & as_binary(Tag const & tag) const;
191 
193  Value::Binary & as_binary(Tag const & tag);
194 
196  Value::Binary::value_type const &
197  as_binary(Tag const & tag, unsigned int position) const;
198 
200  typedef std::map<Tag, Element>::const_iterator const_iterator;
201 
203  const_iterator begin() const;
204 
206  const_iterator end() const;
207 
209  bool operator==(DataSet const & other) const;
210 
212  bool operator!=(DataSet const & other) const;
213 
218  void clear();
219 
221  void clear(Tag const & tag);
222 
224  std::string const & get_transfer_syntax() const;
225 
227  void set_transfer_syntax(std::string const & transfer_syntax);
228 
229 private:
230  typedef std::map<Tag, Element> ElementMap;
231 
232  ElementMap _elements;
233 
235  std::string _transfer_syntax;
236 };
237 
238 }
239 
240 #endif // _8424446e_1153_4acc_9f57_e86faa7246e3
odil::is_int
bool is_int(VR vr)
Test whether a VR contains integers.
odil::operator==
bool operator==(Value::DataSets const &left, Value::DataSets const &right)
Equality test.
odil::Value::Strings
std::vector< String > Strings
String container.
Definition: Value.h:63
ODIL_DATASET_ADD
#define ODIL_DATASET_ADD(type)
Definition: DataSet.h:66
odil::is_binary
bool is_binary(VR vr)
Test whether a VR contains binary data.
odil
Definition: Association.h:24
ODIL_API
#define ODIL_API
Definition: odil.h:28
odil::Value::Binary
std::vector< std::vector< uint8_t > > Binary
Binary data container.
Definition: Value.h:69
odil::VR::UNKNOWN
@ UNKNOWN
odil::Value::String
std::string String
String type.
Definition: Value.h:54
Element.h
odil::Value::Real
double Real
Real type.
Definition: Value.h:51
odil::Tag
A DICOM element tag.
Definition: Tag.h:30
odil.h
odil::operator!=
bool operator!=(Value::DataSets const &left, Value::DataSets const &right)
Difference test.
odil::as_string
std::string as_string(VR vr)
Convert a VR to its string representation.
odil::is_string
bool is_string(VR vr)
Test whether a VR contains text.
odil::VR
VR
Value representations of DICOM.
Definition: VR.h:28
odil::Value::DataSets
std::vector< std::shared_ptr< DataSet > > DataSets
Data sets container.
Definition: Value.h:66
odil::Value::Integer
int64_t Integer
Integer type.
Definition: Value.h:48
odil::is_real
bool is_real(VR vr)
Test whether a VR contains rel numbers.
odil::Value::Reals
std::vector< Real > Reals
Real container.
Definition: Value.h:60
odil::Value::Integers
std::vector< Integer > Integers
Integer container.
Definition: Value.h:57
Value.h
odil::DataSet
DICOM Data set.
Definition: DataSet.h:35