Odil
A C++11 library for the DICOM standard
Message.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 _dcfa5213_ad7e_4194_8b4b_e630aa0df2e8
10 #define _dcfa5213_ad7e_4194_8b4b_e630aa0df2e8
11 
12 #include "odil/DataSet.h"
13 #include "odil/odil.h"
14 #include "odil/registry.h"
15 #include "odil/Value.h"
16 
17 namespace odil
18 {
19 
20 namespace message
21 {
22 
23 #define ODIL_MESSAGE_MANDATORY_FIELD_MACRO(name, tag, TValueType, function) \
24  \
25  TValueType const & get_##name() const \
26  { \
27  auto const & data = this->_command_set->function(tag); \
28  if(data.empty()) \
29  { \
30  throw Exception("Empty element"); \
31  } \
32  return data[0]; \
33  } \
34  \
35  void set_##name(TValueType const & value) \
36  { \
37  if(!this->_command_set->has(tag)) \
38  { \
39  this->_command_set->add(tag); \
40  } \
41  this->_command_set->function(tag) = { value }; \
42  }
43 
44 #define ODIL_MESSAGE_OPTIONAL_FIELD_MACRO(name, tag, TValueType, function) \
45  ODIL_MESSAGE_MANDATORY_FIELD_MACRO(name, tag, TValueType, function) \
46  bool has_##name() const \
47  { \
48  return this->_command_set->has(tag);; \
49  } \
50  void delete_##name() \
51  { \
52  this->_command_set->remove(tag); \
53  }
54 
55 #define ODIL_MESSAGE_SET_OPTIONAL_FIELD_MACRO(dataset, name, tag, function) \
56  if(dataset->has(tag)) \
57  { \
58  this->set_##name(dataset->function(tag, 0)); \
59  }
60 
61 #define ODIL_MESSAGE_MANDATORY_FIELD_INTEGER_MACRO(name, tag) \
62  ODIL_MESSAGE_MANDATORY_FIELD_MACRO(name, tag, Value::Integer, as_int)
63 
64 #define ODIL_MESSAGE_MANDATORY_FIELD_STRING_MACRO(name, tag) \
65  ODIL_MESSAGE_MANDATORY_FIELD_MACRO(name, tag, Value::String, as_string)
66 
67 #define ODIL_MESSAGE_OPTIONAL_FIELD_INTEGER_MACRO(name, tag) \
68  ODIL_MESSAGE_OPTIONAL_FIELD_MACRO(name, tag, Value::Integer, as_int)
69 
70 #define ODIL_MESSAGE_OPTIONAL_FIELD_STRING_MACRO(name, tag) \
71  ODIL_MESSAGE_OPTIONAL_FIELD_MACRO(name, tag, Value::String, as_string)
72 
77 {
78 public:
79  enum Command
80  {
81  C_STORE_RQ = 0x0001,
82  C_STORE_RSP = 0x8001,
83 
84  C_FIND_RQ = 0x0020,
85  C_FIND_RSP = 0x8020,
86 
87  C_CANCEL_RQ = 0x0FFF,
88 
89  C_GET_RQ = 0x0010,
90  C_GET_RSP = 0x8010,
91 
92  C_MOVE_RQ = 0x0021,
93  C_MOVE_RSP = 0x8021,
94 
95  C_ECHO_RQ = 0x0030,
96  C_ECHO_RSP = 0x8030,
97 
98  N_EVENT_REPORT_RQ = 0x0100,
99  N_EVENT_REPORT_RSP = 0x8100,
100 
101  N_GET_RQ = 0x0110,
102  N_GET_RSP = 0x8110,
103 
104  N_SET_RQ = 0x0120,
105  N_SET_RSP = 0x8120,
106 
107  N_ACTION_RQ = 0x0130,
108  N_ACTION_RSP = 0x8130,
109 
110  N_CREATE_RQ = 0x0140,
111  N_CREATE_RSP = 0x8140,
112 
113  N_DELETE_RQ = 0x0150,
114  N_DELETE_RSP = 0x8150,
115  };
116 
117  enum Priority
118  {
119  LOW = 0x0002,
120  MEDIUM = 0x0000,
121  HIGH = 0x0001,
122  };
123 
125  {
126  PRESENT = 0x0000,
127  ABSENT = 0x0101,
128  };
129 
132  std::shared_ptr<DataSet> command_set=std::make_shared<DataSet>(),
133  std::shared_ptr<DataSet> data_set={});
134 
135  Message(Message const &) = default;
136  Message(Message &&) = default;
137  Message & operator=(Message const &) = default;
138  Message & operator=(Message &&) = default;
139  virtual ~Message() = default;
140 
142  std::shared_ptr<DataSet const> get_command_set() const;
143 
145  bool has_data_set() const;
146 
151  std::shared_ptr<DataSet const> get_data_set() const;
152 
157  std::shared_ptr<DataSet> get_data_set();
158 
160  void set_data_set(std::shared_ptr<DataSet> data_set);
161 
164 
166  command_field, registry::CommandField)
167 
168 protected:
170  std::shared_ptr<DataSet> _command_set;
171 
173  std::shared_ptr<DataSet> _data_set;
174 };
175 
176 }
177 
178 }
179 
180 #endif // _dcfa5213_ad7e_4194_8b4b_e630aa0df2e8
Base class for all DIMSE messages.
Definition: Message.h:77
std::shared_ptr< DataSet const > get_command_set() const
Return the command set of the message (by reference or shared pointer).
Message & operator=(Message const &)=default
Command
Definition: Message.h:80
Message(Message &&)=default
Message & operator=(Message &&)=default
Priority
Definition: Message.h:118
void delete_data_set()
Delete the data set in this message.
std::shared_ptr< DataSet > _data_set
Data set of the message.
Definition: Message.h:173
Message(std::shared_ptr< DataSet > command_set=std::make_shared< DataSet >(), std::shared_ptr< DataSet > data_set={})
Create a message with an empty command set and no data set.
Message(Message const &)=default
bool has_data_set() const
Test whether as data set is present in the message.
virtual ~Message()=default
std::shared_ptr< DataSet > _command_set
Command set of the message.
Definition: Message.h:170
void set_data_set(std::shared_ptr< DataSet > data_set)
Set the data set of the message.
std::shared_ptr< DataSet const > get_data_set() const
Return the data set of the message, raise an exception if no data set is present.
std::shared_ptr< DataSet > get_data_set()
Return the data set of the message, raise an exception if no data set is present.
DataSetType
Definition: Message.h:125
#define ODIL_MESSAGE_MANDATORY_FIELD_INTEGER_MACRO(name, tag)
Definition: Message.h:61
Tag const CommandField(0x0000, 0x0100)
Definition: Association.h:25
#define ODIL_API
Definition: odil.h:28