odil
C++11libraryfortheDICOMstandard
Element.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 _9c3d8f32_0310_4e3a_b5d2_6d69f229a2cf
10 #define _9c3d8f32_0310_4e3a_b5d2_6d69f229a2cf
11 
12 #include <cstddef>
13 #include <initializer_list>
14 
15 #include "odil/odil.h"
16 #include "odil/Tag.h"
17 #include "odil/Value.h"
18 #include "odil/VR.h"
19 
20 namespace odil
21 {
22 
26 class ODIL_API Element
27 {
28 public:
29 
31  VR vr;
32 
34  Element(VR const & vr);
35 
37  Element(Value const & value, VR const & vr);
38 
40  Element(Value && value, VR const & vr);
41 
42 #define ODIL_ELEMENT_CONSTRUCTORS(type) \
43  Element(Value::type const & value, VR const & vr=VR::INVALID); \
44  Element(Value::type && value, VR const & vr=VR::INVALID); \
45  Element(\
46  std::initializer_list<Value::type::value_type> const & value, \
47  VR const & vr=VR::INVALID);
48  /*
49  * No need for for a rvalue reference version of std::initializer_list:
50  * copying a std::initializer_list does not copy the underlying objects.
51  */
52 
53  ODIL_ELEMENT_CONSTRUCTORS(Integers);
54  ODIL_ELEMENT_CONSTRUCTORS(Reals);
55  ODIL_ELEMENT_CONSTRUCTORS(Strings);
56  ODIL_ELEMENT_CONSTRUCTORS(DataSets);
57  ODIL_ELEMENT_CONSTRUCTORS(Binary);
58 #undef ODIL_ELEMENT_CONSTRUCTORS
59 
60  Element(
61  std::initializer_list<int> const & value, VR const & vr=VR::INVALID);
62 
63  Element(
64  std::initializer_list<std::initializer_list<uint8_t>> const & value,
65  VR const & vr=VR::INVALID);
66 
70  ~Element() =default;
71  Element(Element const &) =default;
72  Element(Element &&) =default;
73  Element & operator=(Element const &) =default;
74  Element & operator=(Element &&) =default;
76 
78  bool empty() const;
79 
81  std::size_t size() const;
82 
84  Value const & get_value() const;
85 
87  bool is_int() const;
88 
94  Value::Integers const & as_int() const;
95 
101  Value::Integers & as_int();
102 
104  bool is_real() const;
105 
111  Value::Reals const & as_real() const;
112 
118  Value::Reals & as_real();
119 
121  bool is_string() const;
122 
128  Value::Strings const & as_string() const;
129 
135  Value::Strings & as_string();
136 
138  bool is_data_set() const;
139 
145  Value::DataSets const & as_data_set() const;
146 
152  Value::DataSets & as_data_set();
153 
155  bool is_binary() const;
156 
162  Value::Binary const & as_binary() const;
163 
169  Value::Binary & as_binary();
170 
172  bool operator==(Element const & other) const;
173 
175  bool operator!=(Element const & other) const;
176 
178  void clear();
179 
180 private:
181  Value _value;
182 };
183 
187 template<typename TVisitor>
188 typename TVisitor::result_type
189 apply_visitor(TVisitor const & visitor, Element const & element);
190 
191 
192 }
193 
194 #include "odil/Element.txx"
195 
196 #endif // _9c3d8f32_0310_4e3a_b5d2_6d69f229a2cf
197 
std::vector< String > Strings
String container.
Definition: Value.h:57
std::vector< Real > Reals
Real container.
Definition: Value.h:54
A value held in a DICOM element.
Definition: Value.h:28
VR vr
VR of the element.
Definition: Element.h:31
Definition: Association.cpp:39
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
Element of a DICOM data set.
Definition: Element.h:26