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
23namespace odil
24{
25
30{
31public:
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 a rvalue reference version of std::initializer_list:
65 * copying a std::initializer_list does not copy the underlying objects.
66 */
67
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
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
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
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
204
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
229private:
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
#define ODIL_DATASET_ADD(type)
Definition: DataSet.h:54
DICOM Data set.
Definition: DataSet.h:30
Value::Strings & as_string(Tag const &tag)
Return the strings contained in an existing element (read-write).
Value::DataSets const & as_data_set(Tag const &tag) const
Return the data sets contained in an existing element (read-only).
bool operator!=(DataSet const &other) const
Difference test.
void add(Tag const &tag, std::initializer_list< std::initializer_list< uint8_t > > const &value, VR vr=VR::UNKNOWN)
Add an element to the dataset.
void add(Tag const &tag, VR vr=VR::UNKNOWN)
Add an empty element to the dataset.
void add(Tag const &tag, Element &&element)
Add an element to the dataset.
VR get_vr(Tag const &tag) const
Return the VR of an element in the data set.
Element & operator[](Tag const &tag)
Access the given element.
Value::Real const & as_real(Tag const &tag, unsigned int position) const
Return an real contained in an existing element (read-only).
bool is_real(Tag const &tag) const
Test whether an existing element has real type.
void add(Tag const &tag, std::initializer_list< int > const &value, VR vr=VR::UNKNOWN)
Add an element to the dataset.
Value::Binary const & as_binary(Tag const &tag) const
Return the binary items contained in an existing element (read-only).
bool operator==(DataSet const &other) const
Equality test.
bool is_int(Tag const &tag) const
Test whether an existing element has integer type.
const_iterator begin() const
Return an iterator to the start of the elements.
Value::Binary::value_type const & as_binary(Tag const &tag, unsigned int position) const
Return a binary item contained in an existing element (read-only).
Element const & operator[](Tag const &tag) const
Access the given element.
void clear(Tag const &tag)
Clear the element (data_set.empty(tag) will be true).
bool empty(Tag const &tag) const
Test whether an element of the data set is empty.
void clear()
Clear the data set (data_set.empty() will be true). All iterators and all references to elements will...
void set_transfer_syntax(std::string const &transfer_syntax)
Set the current transfer syntax.
void remove(Tag const &tag)
Remove an element from the data set.
Value::Binary & as_binary(Tag const &tag)
Return the binary items contained in an existing element (read-write).
Value::Integer const & as_int(Tag const &tag, unsigned int position) const
Return an integer contained in an existing element (read-only).
bool is_binary(Tag const &tag) const
Test whether an existing element has binary type.
const_iterator end() const
Return an iterator to the end of the elements.
Value::Reals const & as_real(Tag const &tag) const
Return the reals contained in an existing element (read-only).
bool has(Tag const &tag) const
Test whether an element is in the data set.
Value::Integers const & as_int(Tag const &tag) const
Return the integers contained in an existing element (read-only).
DataSet(std::string const &transfer_syntax="")
Create an empty data set.
Value::Strings const & as_string(Tag const &tag) const
Return the strings contained in an existing element (read-only).
void add(Tag const &tag, Element const &element)
Add an element to the dataset.
std::map< Tag, Element >::const_iterator const_iterator
Iterator to the elements.
Definition: DataSet.h:200
Value::Reals & as_real(Tag const &tag)
Return the reals contained in an existing element (read-write).
Value::DataSets & as_data_set(Tag const &tag)
Return the data sets contained in an existing element (read-write).
std::string const & get_transfer_syntax() const
Return the current transfer syntax.
std::shared_ptr< DataSet > const & as_data_set(Tag const &tag, unsigned int position) const
Return a data set contained in an existing element (read-only).
std::size_t size() const
Return the number of elements in the data set.
bool empty() const
Test whether the data set is empty.
Value::String const & as_string(Tag const &tag, unsigned int position) const
Return a string contained in an existing element (read-only).
Value::Integers & as_int(Tag const &tag)
Return the integers contained in an existing element (read-write).
std::size_t size(Tag const &tag) const
Return the number of values in an element of the data set.
bool is_data_set(Tag const &tag) const
Test whether an existing element has data set type.
bool is_string(Tag const &tag) const
Test whether an existing element has string type.
Element of a DICOM data set.
Definition: Element.h:27
A DICOM element tag.
Definition: Tag.h:25
std::vector< String > Strings
String container.
Definition: Value.h:57
int64_t Integer
Integer type.
Definition: Value.h:42
std::vector< Integer > Integers
Integer container.
Definition: Value.h:51
std::vector< std::vector< uint8_t > > Binary
Binary data container.
Definition: Value.h:63
std::string String
String type.
Definition: Value.h:48
std::vector< Real > Reals
Real container.
Definition: Value.h:54
std::vector< std::shared_ptr< DataSet > > DataSets
Data sets container.
Definition: Value.h:60
double Real
Real type.
Definition: Value.h:45
DataSet(DataSet const &)=default
~DataSet()=default
DataSet & operator=(DataSet const &)=default
DataSet(DataSet &&)=default
DataSet & operator=(DataSet &&)=default
Definition: Association.h:25
VR
Value representations of DICOM.
Definition: VR.h:23
#define ODIL_API
Definition: odil.h:28