-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDataSet.hpp
108 lines (87 loc) · 2.47 KB
/
DataSet.hpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
#ifndef DATA_SET_HPP_INCLUDE_GUARD_35758581243
#define DATA_SET_HPP_INCLUDE_GUARD_35758581243
#include <iostream>
#include <boost/any.hpp>
#include <boost/shared_ptr.hpp>
#include <boost/utility.hpp>
#include <boost/type_traits.hpp>
#include <exception>
#include <map>
#include "VR.hpp"
#include "Value.hpp"
#include "Tag.hpp"
namespace dicom
{
//!Set of DICOM data elements
/*!
An element in a DataSet is a tag-value pair.
Multiple elements may have the same tag. This is called
'value multiplicity' in DICOM terminology (see PS3.5/section 6.4).
We implement this by using a std::multimap, and for convenience
provide a couple of accessor functions. Note that you can still
always use any of the functions that std::multimap provides, such
as equal_range(), count() and find()
*/
class DataSet:public std::multimap<Tag,Value>
{
public:
//!access an element
/*!
This isn't ideal, as it will only return the FIRST
element that matches Tag, even if there are more than one. (Value
multiplicity). Use equal_range() or count() to find the multiplicity
of a given tag.
*/
const Value& operator()(const Tag tag) const
{
const_iterator element=find(tag);
if(element==end())
throw TagNotFound(tag);
return element->second;
}
//!Insert an element
/*! I'd rather that the function signature was:
template <VR vr>
size_t Put(Tag tag, const typename TypeFromVR<vr>::Type& data)
but VisualStudio doesn't like it.
*/
template <VR vr, typename T>
void Put(Tag tag, const T& data)
{
StaticVRCheck<T,vr>();
Value v(vr,data);
insert(value_type(tag,v));
}
/** Is it safe to use???
*/
//!Insert an element with zero data length
template <VR vr>
void Put(Tag tag)
{
Value v(vr);
insert(value_type(tag,v));
}
//!Get all values matching tag.
/*!
This helps the user avoid using the somewhat complex equal_range() interface.
*/
std::vector<Value> Values(const Tag tag) const
{
std::pair<const_iterator,const_iterator> P = equal_range(tag);
std::vector<Value> v;
for(const_iterator I=P.first;I!=P.second;I++)
v.push_back(I->second);
return v;
}
//!Check if a Tag exists
/*!
This helps the user avoid running into/dealing with too many exceptions.
*/
bool exists(const Tag tag) const
{
return (find(tag) != end());
}
};
typedef std::vector<DataSet> Sequence;
}//namespace DICOM
#endif //DATA_SET_HPP_INCLUDE_GUARD_35758581243