vega
fixed_size_element_manipulator_impl.h
Go to the documentation of this file.
3 #include "vega/vega.h"
4 
5 #include <sstream>
6 #include <algorithm>
7 
8 namespace vega {
9  namespace manipulators {
10  template <typename T>
12  : FixedSizeElementManipulator::base_vector(first, last)
13  {}
14 
15  template <typename T>
17  : FixedSizeElementManipulator::base_vector()
18  {}
19 
20  template <typename T>
21  FixedSizeElementManipulator<T>::FixedSizeElementManipulator(std::shared_ptr<dicom::RawValue> raw_value)
22  {
23  if (raw_value->size() % sizeof(T) != 0) throw vega::Exception("Incompatible size for FixedSizeElementManipulator");
24 
25  std::copy(
26  reinterpret_cast<const T * const>(&*raw_value->begin()),
27  reinterpret_cast<const T * const>(&*raw_value->end()),
28  std::back_inserter(*this)
29  );
30  }
31 
32  template <typename T>
33  std::shared_ptr<dicom::RawValue> FixedSizeElementManipulator<T>::raw_value() {
34  return std::make_shared<dicom::RawValue>(
35  reinterpret_cast<const char * const>(&*this->begin()),
36  reinterpret_cast<const char * const>(&*this->end())
37  );
38  }
39 
40  template <typename T>
42  std::stringstream ss;
43 
44  for (size_t i = 0; i < this->size(); ++i) {
45  ss << vega::to_string<T>((*this)[i]);
46  if (i < this->size()-1) {
47  ss << '\\';
48  }
49  }
50 
51  return ss.str();
52  }
53 
54  template <typename T>
55  bool FixedSizeElementManipulator<T>::read_from(dicom::RawReader* reader, size_t num_bytes) {
56  this->clear();
57 
58  if (num_bytes % sizeof(T) != 0) throw vega::Exception("Incompatible num_bytes for FixedSizeElementManipulator");
59 
60  for (size_t i = 0; i < num_bytes; i += sizeof(T)) {
61  this->emplace_back();
62  if (!reader->read_into(&this->back())) return false;
63  }
64 
65  return true;
66  }
67 
68  template <typename T>
69  size_t FixedSizeElementManipulator<T>::write_to(dicom::RawWriter* writer) const {
70  return writer->write_from(this->begin(), this->end());
71  }
72 
73  template <typename T>
75  const FixedSizeElementManipulator<T>* other_ptr = dynamic_cast<const FixedSizeElementManipulator<T>*>(&other);
76  if (!other_ptr) return false;
77 
78  if (this->size() != other_ptr->size()) return false;
79  return std::equal(this->begin(), this->end(), other_ptr->begin());
80  }
81 
82  template <typename T>
84  return !(*this == other);
85  }
86  }
87 }
The base class for exceptions that are raised by the vega library.
Definition: vega.h:11
base_vector::const_iterator const_iterator
Definition: fixed_size_element_manipulator.h:28
Definition: value_manipulator.h:29
FixedSizeElementManipulator()
Definition: fixed_size_element_manipulator_impl.h:16
virtual std::string str() const override
Definition: fixed_size_element_manipulator_impl.h:41
A manipulator class for VR that represent fixed size elements like integers and floating point number...
Definition: fixed_size_element_manipulator.h:20
Definition: age.h:6