odil
C++11libraryfortheDICOMstandard
Value.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 _dca5b15b_b8df_4925_a446_d42efe06c923
10 #define _dca5b15b_b8df_4925_a446_d42efe06c923
11 
12 #include <cstdint>
13 #include <initializer_list>
14 #include <memory>
15 #include <string>
16 #include <vector>
17 
18 #include "odil/odil.h"
19 
20 namespace odil
21 {
22 
23 class DataSet;
24 
28 class ODIL_API Value
29 {
30 public:
32  enum class Type
33  {
34  Integers,
35  Reals,
36  Strings,
37  DataSets,
38  Binary
39  };
40 
42  typedef int64_t Integer;
43 
45  typedef double Real;
46 
48  typedef std::string String;
49 
51  typedef std::vector<Integer> Integers;
52 
54  typedef std::vector<Real> Reals;
55 
57  typedef std::vector<String> Strings;
58 
60  typedef std::vector<DataSet> DataSets;
61 
63  typedef std::vector<std::vector<uint8_t>> Binary;
64 
65 #define ODIL_VALUE_CONSTRUCTORS(type) \
66  Value(type const & value); \
67  Value(type && value); \
68  Value(std::initializer_list<type::value_type> const & value);
69  /*
70  * No need for for a rvalue reference version of std::initializer_list:
71  * copying a std::initializer_list does not copy the underlying objects.
72  */
73 
74  ODIL_VALUE_CONSTRUCTORS(Integers);
75  ODIL_VALUE_CONSTRUCTORS(Reals);
76  ODIL_VALUE_CONSTRUCTORS(Strings);
77  ODIL_VALUE_CONSTRUCTORS(DataSets);
78  ODIL_VALUE_CONSTRUCTORS(Binary);
79 #undef ODIL_VALUE_CONSTRUCTORS
80 
81  Value(std::initializer_list<int> const & value);
82 
83  Value(std::initializer_list<std::initializer_list<uint8_t>> const & value);
84 
88  ~Value() =default;
89  Value(Value const &) =default;
90  Value(Value &&) =default;
91  Value & operator=(Value const &) =default;
92  Value & operator=(Value &&) =default;
94 
96  Type get_type() const;
97 
99  bool empty() const;
100 
102  std::size_t size() const;
103 
109  Integers const & as_integers() const;
110 
116  Integers & as_integers();
117 
123  Reals const & as_reals() const;
124 
130  Reals & as_reals();
131 
137  Strings const & as_strings() const;
138 
144  Strings & as_strings();
145 
151  DataSets const & as_data_sets() const;
152 
158  DataSets & as_data_sets();
159 
165  Binary const & as_binary() const;
166 
172  Binary & as_binary();
173 
175  bool operator==(Value const & other) const;
176 
178  bool operator!=(Value const & other) const;
179 
181  void clear();
182 
183 private:
184  Integers _integers;
185  Reals _reals;
186  Strings _strings;
187  // NOTE: can't use std::vector<DataSet> with forward-declaration of DataSet
188  // cf. C++11, 17.6.4.8, last bullet of clause 2
189  std::shared_ptr<DataSets> _data_sets;
190  Binary _binary;
191 
192  Type _type;
193 };
194 
198 template<typename TVisitor>
199 typename TVisitor::result_type
200 apply_visitor(TVisitor const & visitor, Value const & value);
201 
205 template<typename TVisitor>
206 typename TVisitor::result_type
207 apply_visitor(TVisitor const & visitor, Value & value);
208 
209 }
210 
211 #include "odil/Value.txx"
212 
213 #endif // _dca5b15b_b8df_4925_a446_d42efe06c923
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
Type
Possible types stored in the value.
Definition: Value.h:32
double Real
Real type.
Definition: Value.h:45
Definition: Association.cpp:39
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
int64_t Integer
Integer type.
Definition: Value.h:42