Odil
A C++11 library for the DICOM standard
Item.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 _1c7b57cc_79f5_497c_815c_920e0711a864
10#define _1c7b57cc_79f5_497c_815c_920e0711a864
11
12#include <cstdint>
13#include <istream>
14#include <ostream>
15#include <string>
16#include <utility>
17#include <vector>
18
19#include "odil/odil.h"
20
21namespace odil
22{
23
24namespace pdu
25{
26
29{
30public:
33 {
34 public:
36 enum class Type
37 {
38 unsigned_int_8,
39 unsigned_int_16,
40 unsigned_int_32,
41 string,
42 items
43 };
44
46 Field(uint8_t value);
47
49 Field(uint16_t value);
50
52 Field(uint32_t value);
53
55 Field(std::string const & value);
56
58 Field(std::vector<Item> const & value);
59
61 Type get_type() const;
62
68 uint8_t as_unsigned_int_8() const;
69
75 uint8_t & as_unsigned_int_8();
76
82 uint16_t as_unsigned_int_16() const;
83
89 uint16_t & as_unsigned_int_16();
90
96 uint32_t as_unsigned_int_32() const;
97
103 uint32_t & as_unsigned_int_32();
104
110 std::string const & as_string() const;
111
117 std::string & as_string();
118
124 std::vector<Item> const & as_items() const;
125
131 std::vector<Item> & as_items();
132
133 private:
134 Type _type;
135 uint8_t _uint8;
136 uint16_t _uint16;
137 uint32_t _uint32;
138 std::string _string;
139 std::vector<Item> _items;
140 };
141
142 typedef std::vector<std::pair<std::string, Field>> Container;
143
146
148 Item(std::vector<std::pair<std::string, Field>> const & fields);
149
151 Item & add(std::string const & name, Field const & field);
152
154 Container::size_type size() const;
155
157 bool empty() const;
158
160 bool has_field(std::string const & name) const;
161
163 Field const & operator[](std::string const & name) const;
164
166 Field & operator[](std::string const & name);
167
174 uint8_t as_unsigned_int_8(std::string const & name) const;
175
182 uint8_t & as_unsigned_int_8(std::string const & name);
183
190 uint16_t as_unsigned_int_16(std::string const & name) const;
191
198 uint16_t & as_unsigned_int_16(std::string const & name);
199
206 uint32_t as_unsigned_int_32(std::string const & name) const;
207
214 uint32_t & as_unsigned_int_32(std::string const & name);
215
222 std::string const & as_string(std::string const & name) const;
223
230 std::string & as_string(std::string const & name);
231
232 std::vector<Item> const & as_items(std::string const & name) const;
233
240 std::vector<Item> & as_items(std::string const & name);
241
242 typedef Container::const_iterator const_iterator;
245
251 void read(
252 std::istream & stream,std::string const & name, Field::Type type,
253 std::streamsize size=0);
254
255private:
256 std::vector<std::pair<std::string, Field>> _fields;
257};
258
259// No operator>> since we need explicit names and types.
260
262std::ostream &
263operator<<(std::ostream & stream, Item const & item);
264
265}
266
267}
268
269#endif // _1c7b57cc_79f5_497c_815c_920e0711a864
Generic field.
Definition: Item.h:33
uint32_t as_unsigned_int_32() const
Return the uint32_t stored in the field.
Field(uint32_t value)
Constructor.
uint16_t & as_unsigned_int_16()
Return the uint16_t stored in the field.
std::vector< Item > const & as_items() const
Return the items stored in the field.
uint8_t as_unsigned_int_8() const
Return the uint8_t stored in the field.
Field(std::string const &value)
Constructor.
Field(uint16_t value)
Constructor.
Type get_type() const
Return the concrete type stored in the field.
Field(std::vector< Item > const &value)
Constructor.
std::string & as_string()
Return the string stored in the field.
std::string const & as_string() const
Return the string stored in the field.
Field(uint8_t value)
Constructor.
uint8_t & as_unsigned_int_8()
Return the uint8_t stored in the field.
uint16_t as_unsigned_int_16() const
Return the uint16_t stored in the field.
Type
Possible types stored in the field.
Definition: Item.h:37
uint32_t & as_unsigned_int_32()
Return the uint32_t stored in the field.
std::vector< Item > & as_items()
Return the items stored in the field.
A sequence of fields forming a full PDU or a part of it.
Definition: Item.h:29
uint32_t as_unsigned_int_32(std::string const &name) const
Return the named field as an uint32_t.
Field & operator[](std::string const &name)
Return the named field. Raise an exception if no such field exists.
std::vector< std::pair< std::string, Field > > Container
Definition: Item.h:142
Container::size_type size() const
Return the number of fields.
Container::const_iterator const_iterator
Definition: Item.h:242
uint8_t as_unsigned_int_8(std::string const &name) const
Return the named field as an uint8_t.
const_iterator end() const
uint32_t & as_unsigned_int_32(std::string const &name)
Return the named field as an uint32_t.
bool has_field(std::string const &name) const
Test whether the PDU item contains a field with a given name.
uint16_t & as_unsigned_int_16(std::string const &name)
Return the named field as an uint16_t.
const_iterator begin() const
Item(std::vector< std::pair< std::string, Field > > const &fields)
Create an initialized PDU item.
uint16_t as_unsigned_int_16(std::string const &name) const
Return the named field as an uint16_t.
Item & add(std::string const &name, Field const &field)
Add a new field to the PDU item.
std::vector< Item > & as_items(std::string const &name)
Return the named field as a sequence of items.
std::string const & as_string(std::string const &name) const
Return the named field as a string.
std::vector< Item > const & as_items(std::string const &name) const
Item()
Create an empty PDU item.
std::string & as_string(std::string const &name)
Return the named field as a sequence of items.
bool empty() const
Test whether the container is empty.
uint8_t & as_unsigned_int_8(std::string const &name)
Return the named field as an uint8_t.
void read(std::istream &stream, std::string const &name, Field::Type type, std::streamsize size=0)
Read a field from a stream.
Field const & operator[](std::string const &name) const
Return the named field. Raise an exception if no such field exists.
std::ostream & operator<<(std::ostream &stream, Item const &item)
Definition: Association.h:25
#define ODIL_API
Definition: odil.h:28