Odil
A C++11 library for the DICOM standard
Value.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 _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 
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<std::shared_ptr<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 
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 
117 
123  Reals const & as_reals() const;
124 
131 
137  Strings const & as_strings() const;
138 
145 
151  DataSets const & as_data_sets() const;
152 
159 
165  Binary const & as_binary() const;
166 
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 
201 bool ODIL_API operator==(Value::DataSets const & left, Value::DataSets const & right);
202 
204 bool ODIL_API operator!=(Value::DataSets const & left, Value::DataSets const & right);
205 
209 template<typename TVisitor>
210 typename TVisitor::result_type
211 apply_visitor(TVisitor const & visitor, Value const & value);
212 
216 template<typename TVisitor>
217 typename TVisitor::result_type
218 apply_visitor(TVisitor const & visitor, Value & value);
219 
220 }
221 
222 #include "odil/Value.txx"
223 
224 #endif // _dca5b15b_b8df_4925_a446_d42efe06c923
odil::apply_visitor
TVisitor::result_type apply_visitor(TVisitor const &visitor, Element const &element)
Visitor of elements.
odil::operator==
bool operator==(Value::DataSets const &left, Value::DataSets const &right)
Equality test.
odil::Value::operator=
Value & operator=(Value &&)=default
odil::Value::Strings
std::vector< String > Strings
String container.
Definition: Value.h:57
odil::Value::Value
Value(Value const &)=default
odil::Value::operator!=
bool operator!=(Value const &other) const
Difference test.
odil
Definition: Association.h:25
ODIL_API
#define ODIL_API
Definition: odil.h:28
odil::Value::Value
Value(std::initializer_list< std::initializer_list< uint8_t >> const &value)
ODIL_VALUE_CONSTRUCTORS
#define ODIL_VALUE_CONSTRUCTORS(type)
Definition: Value.h:65
odil::Value::Binary
std::vector< std::vector< uint8_t > > Binary
Binary data container.
Definition: Value.h:63
odil::Value
A value held in a DICOM element.
Definition: Value.h:29
odil::Value::as_binary
Binary & as_binary()
Return the binary data contained in the value.
odil::Value::as_integers
Integers & as_integers()
Return the integers contained in the value.
odil::Value::as_reals
Reals & as_reals()
Return the reals contained in the value.
odil::Value::String
std::string String
String type.
Definition: Value.h:48
odil::Value::as_binary
Binary const & as_binary() const
Return the binary data contained in the value.
odil::Value::Real
double Real
Real type.
Definition: Value.h:45
odil.h
odil::Value::clear
void clear()
Clear the value (value.empty() will be true).
odil::operator!=
bool operator!=(Value::DataSets const &left, Value::DataSets const &right)
Difference test.
odil::Value::empty
bool empty() const
Test whether the value is empty.
odil::Value::Type
Type
Possible types stored in the value.
Definition: Value.h:33
odil::Value::size
std::size_t size() const
Return the number of items.
odil::Value::as_strings
Strings const & as_strings() const
Return the strings contained in the value.
odil::Value::as_reals
Reals const & as_reals() const
Return the reals contained in the value.
odil::Value::DataSets
std::vector< std::shared_ptr< DataSet > > DataSets
Data sets container.
Definition: Value.h:60
odil::Value::Value
Value(Value &&)=default
odil::Value::as_data_sets
DataSets & as_data_sets()
Return the data sets contained in the value.
odil::Value::as_data_sets
DataSets const & as_data_sets() const
Return the data sets contained in the value.
odil::Value::~Value
~Value()=default
odil::Value::Integer
int64_t Integer
Integer type.
Definition: Value.h:42
odil::Value::Reals
std::vector< Real > Reals
Real container.
Definition: Value.h:54
odil::Value::as_integers
Integers const & as_integers() const
Return the integers contained in the value.
odil::Value::operator=
Value & operator=(Value const &)=default
odil::Value::as_strings
Strings & as_strings()
Return the strings contained in the value.
odil::Value::Integers
std::vector< Integer > Integers
Integer container.
Definition: Value.h:51
odil::Value::operator==
bool operator==(Value const &other) const
Equality test.
odil::Value::get_type
Type get_type() const
Return the type store in the value.
odil::Value::Value
Value(std::initializer_list< int > const &value)