vega
fixed_size_element_manipulator.h
Go to the documentation of this file.
1 #pragma once
2 
3 #include "vega/uid.h"
5 #include "vega/string.h"
6 
7 #include <vector>
8 #include <string>
9 
10 namespace vega {
11  namespace manipulators {
19  template <typename T>
20  class FixedSizeElementManipulator : public ValueManipulator, private std::vector<T> {
21  private:
22  typedef std::vector<T> base_vector;
23 
24  public:
25  typedef typename base_vector::value_type value_type;
26  typedef typename base_vector::size_type size_type;
27  typedef typename base_vector::iterator iterator;
28  typedef typename base_vector::const_iterator const_iterator;
29  typedef typename base_vector::reference reference;
30  typedef typename base_vector::const_reference const_reference;
31 
32  using base_vector::operator[];
33  using base_vector::at;
34 
35  using base_vector::clear;
36  using base_vector::erase;
37  using base_vector::reserve;
38  using base_vector::resize;
39  using base_vector::size;
40  using base_vector::begin;
41  using base_vector::end;
42  using base_vector::front;
43  using base_vector::back;
44  using base_vector::push_back;
45  using base_vector::emplace_back;
46 
47  FixedSizeElementManipulator(const_iterator first, const_iterator last);
48 
50  explicit FixedSizeElementManipulator(std::shared_ptr<dicom::RawValue> raw_value);
51 
52  template <typename U>
53  U& get(size_t i) {
54  static_assert(sizeof(U) == sizeof(T), "Type T and U must have same size in FixedSizeElementManipulator::get()");
55  return *((U*)&(*this)[i]);
56  }
57 
58  template <typename U>
59  const U& get(size_t i) const {
60  static_assert(sizeof(U) == sizeof(T), "Type T and U must have same size in FixedSizeElementManipulator::get()");
61  return *((const U*)&(*this)[i]);
62  }
63 
64  virtual std::shared_ptr<dicom::RawValue> raw_value() override;
65  virtual std::string str() const override;
66  virtual bool read_from(dicom::RawReader* reader, size_t num_bytes) override;
67  virtual size_t write_to(dicom::RawWriter* writer) const override;
68 
69  virtual bool operator==(const ValueManipulator& other) const override;
70  virtual bool operator!=(const ValueManipulator& other) const override;
71  };
72  }
73 }
74 
virtual bool read_from(dicom::RawReader *reader, size_t num_bytes) override
Definition: fixed_size_element_manipulator_impl.h:55
virtual bool operator!=(const ValueManipulator &other) const override
Definition: fixed_size_element_manipulator_impl.h:83
base_vector::iterator iterator
Definition: fixed_size_element_manipulator.h:27
base_vector::reference reference
Definition: fixed_size_element_manipulator.h:29
virtual std::shared_ptr< dicom::RawValue > raw_value() override
Definition: fixed_size_element_manipulator_impl.h:33
virtual size_t write_to(dicom::RawWriter *writer) const override
Definition: fixed_size_element_manipulator_impl.h:69
base_vector::value_type value_type
Definition: fixed_size_element_manipulator.h:25
base_vector::size_type size_type
Definition: fixed_size_element_manipulator.h:26
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
virtual bool operator==(const ValueManipulator &other) const override
Definition: fixed_size_element_manipulator_impl.h:74
Definition: age.h:6
base_vector::const_reference const_reference
Definition: fixed_size_element_manipulator.h:30