odil
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 
25 #define odilElementTypeMacro(name, Type) \
26 bool is_##name(Tag const & tag) const \
27 { \
28  auto const it = this->_elements.find(tag); \
29  if(it == this->_elements.end()) \
30  { \
31  throw Exception("No such element"); \
32  } \
33  return it->second.is_##name(); \
34 } \
35 Value::Type const & as_##name(Tag const & tag) const \
36 { \
37  auto const it = this->_elements.find(tag); \
38  if(it == this->_elements.end()) \
39  { \
40  throw Exception("No such element"); \
41  } \
42  return it->second.as_##name(); \
43 } \
44 Value::Type::value_type const & as_##name(Tag const & tag, unsigned int position) const \
45 { \
46  auto const & data = this->as_##name(tag); \
47  if(data.size() <= position) \
48  { \
49  throw Exception("No such element"); \
50  } \
51  return data[position]; \
52 } \
53 Value::Type & as_##name(Tag const & tag) \
54 { \
55  auto const it = this->_elements.find(tag); \
56  if(it == this->_elements.end()) \
57  { \
58  throw Exception("No such element"); \
59  } \
60  return it->second.as_##name(); \
61 }
62 
66 class DataSet
67 {
68 public:
70  DataSet();
71 
73  void add(Tag const & tag, Element const & element);
74 
76  void add(Tag const & tag, VR vr=VR::UNKNOWN);
77 
79  void add(
80  Tag const & tag, Value::Integers const & value, VR vr=VR::UNKNOWN);
81 
83  void add(
84  Tag const & tag, Value::Reals const & value, VR vr=VR::UNKNOWN);
85 
87  void add(
88  Tag const & tag, Value::Strings const & value, VR vr=VR::UNKNOWN);
89 
91  void add(
92  Tag const & tag, Value::DataSets const & value, VR vr=VR::UNKNOWN);
93 
95  void add(
96  Tag const & tag, Value::Binary const & value, VR vr=VR::UNKNOWN);
97 
99  void add(
100  Tag const & tag, std::initializer_list<int> const & value,
101  VR vr=VR::UNKNOWN);
102 
104  void add(
105  Tag const & tag, std::initializer_list<Value::Integer> const & value,
106  VR vr=VR::UNKNOWN);
107 
109  void add(
110  Tag const & tag, std::initializer_list<Value::Real> const & value,
111  VR vr=VR::UNKNOWN);
112 
114  void add(
115  Tag const & tag, std::initializer_list<Value::String> const & value,
116  VR vr=VR::UNKNOWN);
117 
119  void add(
120  Tag const & tag, std::initializer_list<DataSet> const & value,
121  VR vr=VR::UNKNOWN);
122 
128  void remove(Tag const & tag);
129 
131  bool empty() const;
132 
134  std::size_t size() const;
135 
137  bool has(Tag const & tag) const;
138 
144  VR get_vr(Tag const & tag) const;
145 
151  bool empty(Tag const & tag) const;
152 
158  std::size_t size(Tag const & tag) const;
159 
165  Element const & operator[](Tag const & tag) const;
166 
172  Element & operator[](Tag const & tag);
173 
174  odilElementTypeMacro(int, Integers);
175  odilElementTypeMacro(real, Reals);
176  odilElementTypeMacro(string, Strings);
177  odilElementTypeMacro(data_set, DataSets);
178  odilElementTypeMacro(binary, Binary);
179 
180  typedef std::map<Tag, Element>::const_iterator const_iterator;
181  const_iterator begin() const { return this->_elements.begin(); }
182  const_iterator end() const { return this->_elements.end(); }
183 
185  bool operator==(DataSet const & other) const;
186 
188  bool operator!=(DataSet const & other) const;
189 
190 private:
191  typedef std::map<Tag, Element> ElementMap;
192 
193  ElementMap _elements;
194 };
195 
196 }
197 
198 #endif // _8424446e_1153_4acc_9f57_e86faa7246e3
VR get_vr(Tag const &tag) const
Return the VR of an element in the data set.
Definition: DataSet.cpp:252
std::vector< String > Strings
String container.
Definition: Value.h:52
Element const & operator[](Tag const &tag) const
Access the given element.
Definition: DataSet.cpp:219
std::vector< Real > Reals
Real container.
Definition: Value.h:49
DataSet()
Create an empty data set.
Definition: DataSet.cpp:25
bool has(Tag const &tag) const
Test whether an element is in the data set.
Definition: DataSet.cpp:245
Definition: Association.cpp:39
A DICOM element tag.
Definition: Tag.h:22
bool operator!=(DataSet const &other) const
Difference test.
Definition: DataSet.cpp:298
bool operator==(DataSet const &other) const
Equality test.
Definition: DataSet.cpp:291
std::vector< Integer > Integers
Integer container.
Definition: Value.h:46
std::vector< DataSet > DataSets
Data sets container.
Definition: Value.h:55
std::vector< uint8_t > Binary
Binary data container.
Definition: Value.h:58
DICOM Data set.
Definition: DataSet.h:66
std::size_t size() const
Return the number of elements in the data set.
Definition: DataSet.cpp:212
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:32
bool empty() const
Test whether the data set is empty.
Definition: DataSet.cpp:205