vega
data_element.h
Go to the documentation of this file.
1 #pragma once
2 
3 #include <stdint.h>
4 #include <memory>
5 #include <vector>
6 #include <string>
7 
8 #include "vega/vega.h"
11 #include "vega/logger.h"
12 
14 
15 namespace vega {
16  namespace dicom {
17  class DataSet;
18 
69  class DataElement {
70  private:
71  DataElementHeader m_header;
72  std::shared_ptr<const dictionary::Page> m_page;
73 
74  std::weak_ptr<DataSet> m_parent;
75  std::vector<std::shared_ptr<DataSet>> m_data_sets;
76 
77  std::shared_ptr<manipulators::ValueManipulator> m_manipulator;
78 
79  public:
82  DataElement(std::shared_ptr<DataSet> parent = nullptr);
95  DataElement(const std::string& name, std::shared_ptr<DataSet> parent = nullptr);
107  DataElement(const Tag& tag, std::shared_ptr<DataSet> parent = nullptr);
118  DataElement(const Tag& tag, const VR& vr, std::shared_ptr<DataSet> parent = nullptr);
119 
121  const std::shared_ptr<const dictionary::Page>& page() const;
123  void set_page(std::shared_ptr<const dictionary::Page> page);
124 
125  const DataElementHeader& header() const;
127 
128  const Tag& tag() const;
129  Tag& tag();
130 
131  const VR& vr() const;
132  VR& vr();
133 
134  const DataElementHeader::length_type& length() const;
136 
137  const std::weak_ptr<DataSet>& parent() const;
138  std::weak_ptr<DataSet>& parent();
139 
141  const std::vector<std::shared_ptr<DataSet>>& data_sets() const;
144  std::vector<std::shared_ptr<DataSet>>& data_sets();
145 
147  std::shared_ptr<manipulators::ValueManipulator> manipulator() { return m_manipulator; }
148  std::shared_ptr<const manipulators::ValueManipulator> manipulator() const {
149  return std::static_pointer_cast<const manipulators::ValueManipulator>(m_manipulator);
150  }
152 
157  template <typename T>
158  void set_manipulator(std::shared_ptr<T> manipulator) {
159  if (!manipulator->is_valid_for(this->vr())) {
160  throw vega::Exception(std::string("DataElement::set_manipulator, received manipulator does not support VR ") + this->vr().str());
161  }
162  m_manipulator = std::dynamic_pointer_cast<manipulators::ValueManipulator>(manipulator);
163  }
164 
179  template <typename T>
180  std::shared_ptr<T> get_manipulator() {
181  this->vr().validate_value_manipulator<T>();
182 
183  // Brand new
184  if (!m_manipulator) {
185  m_manipulator = std::make_shared<T>();
186  return std::static_pointer_cast<T>(m_manipulator);
187  }
188 
189  // If type is same as already stored manipulator, just return
190  std::shared_ptr<T> manipulator = std::dynamic_pointer_cast<T>(m_manipulator);
191  if (manipulator) return manipulator;
192 
193  // Otherwise, update internal manipulator and return
194  m_manipulator = std::make_shared<T>(m_manipulator->raw_value());
195  return std::static_pointer_cast<T>(m_manipulator);
196  }
197 
199  std::string str() const;
200 
202  bool is_sequence() const;
204  bool is_undefined_length() const;
206 
207  std::vector<std::shared_ptr<DataSet>>::iterator begin() {
208  return m_data_sets.begin();
209  }
210  std::vector<std::shared_ptr<DataSet>>::const_iterator begin() const {
211  return m_data_sets.begin();
212  }
213 
214  std::vector<std::shared_ptr<DataSet>>::iterator end() {
215  return m_data_sets.end();
216  }
217  std::vector<std::shared_ptr<DataSet>>::const_iterator end() const {
218  return m_data_sets.end();
219  }
220 
221  bool operator==(const DataElement& other) const;
222  bool operator!=(const DataElement& other) const;
223 
224  void log(Logger& logger) const;
225  };
226  }
227 }
Definition: logger.h:7
std::vector< std::shared_ptr< DataSet > >::const_iterator end() const
Definition: data_element.h:217
This class is used to contain the information in a single DataElement.
Definition: data_element.h:69
const std::weak_ptr< DataSet > & parent() const
std::shared_ptr< T > get_manipulator()
Definition: data_element.h:180
const DataElementHeader & header() const
Definition: vr.h:13
bool operator!=(const DataElement &other) const
void set_page(std::shared_ptr< const dictionary::Page > page)
Sets the dictionary::Page for blank DataElements.
uint32_t length_type
Definition: data_element_header.h:16
const VR & vr() const
const std::shared_ptr< const dictionary::Page > & page() const
The base class for exceptions that are raised by the vega library.
Definition: vega.h:11
An object that stores the header information for DataElements.
Definition: data_element_header.h:15
const std::vector< std::shared_ptr< DataSet > > & data_sets() const
std::vector< std::shared_ptr< DataSet > >::iterator begin()
Definition: data_element.h:207
const DataElementHeader::length_type & length() const
Stores a set of DataElements.
Definition: data_set.h:29
Definition: value_manipulator.h:29
DataElement(std::shared_ptr< DataSet > parent=nullptr)
const Tag & tag() const
bool operator==(const DataElement &other) const
std::vector< std::shared_ptr< DataSet > >::const_iterator begin() const
Definition: data_element.h:210
Definition: age.h:6
std::string str() const
Builds a string representation of the content of this DataElement.
std::vector< std::shared_ptr< DataSet > >::iterator end()
Definition: data_element.h:214
void log(Logger &logger) const
Class for working with DICOM data element tags.
Definition: tag.h:15
void validate_value_manipulator() const
Definition: vr.h:81
void set_manipulator(std::shared_ptr< T > manipulator)
Definition: data_element.h:158