vega
vr.h
Go to the documentation of this file.
1 #pragma once
2 
3 #include "vega/vega.h"
4 
5 #include <typeinfo>
6 #include <stdint.h>
7 #include <string>
8 
9 namespace vega {
13  class VR {
14  public:
15  template <typename T>
17  public:
19  : vega::Exception(
20  std::string("Invalid type ") +
21  typeid(T).name() +
22  std::string(" for VR ") +
23  vr.str()
24  )
25  {
26  }
27  };
28 
29  typedef uint16_t value_type;
30 
31  union Data {
32  value_type value;
33  char characters[2];
34  };
35 
36  private:
37  Data m_data;
38 
39  public:
40  constexpr VR() : m_data() {}
41  explicit constexpr VR(Data data) : m_data(data) {}
42  explicit constexpr VR(value_type value) : m_data{ .value = value } {}
43  explicit constexpr VR(char c1, char c2) : m_data{ .characters = {c1, c2} } {}
44  explicit VR(const std::string& chars) : m_data{ .characters = {chars[0], chars[1]} } {}
45 
46  const Data& data() const { return m_data; }
47  Data& data() { return m_data; }
48  bool operator==(const VR& other) const;
49  bool operator!=(const VR& other) const;
50  bool operator<(const VR& other) const;
51 
52  std::string name() const;
53 
54  std::string str() const;
55  std::string long_str() const;
56 
57  bool valid() const;
58  bool needs_two_byte_padding() const;
59  bool is_sequence() const;
60  // True if type ox, xs, xw, uw, those which stand for multiple actual VRs
61  bool is_combined_vr() const;
62 
63  // Returns 0 if ambiguous/unknown
64  size_t block_size() const;
65 
66  friend std::ostream& operator<<(std::ostream& os, const VR& tag);
67 
68  template <typename T>
69  void validate_value_manipulator() const;
70  };
71 
72  namespace vr {
73  // Manipulators are invalid in general, specifics cases will override to allow
74  template <typename T>
76  return false;
77  }
78  }
79 
80  template <typename T>
82  if (!vr::manipulator_is_valid_for<T>(m_data.value)) {
83  throw InvalidValueManipulator<T>(*this);
84  }
85  }
86 }
87 
88 #include "vega/vr_constants.h"
bool operator<(const VR &other) const
bool operator!=(const VR &other) const
value_type value
Definition: vr.h:32
bool is_sequence() const
constexpr VR(value_type value)
Definition: vr.h:42
bool needs_two_byte_padding() const
friend std::ostream & operator<<(std::ostream &os, const VR &tag)
std::string name() const
Definition: vr.h:13
bool operator==(const VR &other) const
bool is_combined_vr() const
VR(const std::string &chars)
Definition: vr.h:44
const Data & data() const
Definition: vr.h:46
bool manipulator_is_valid_for(VR::value_type value)
Definition: vr.h:75
size_t block_size() const
Data & data()
Definition: vr.h:47
The base class for exceptions that are raised by the vega library.
Definition: vega.h:11
char characters[2]
Definition: vr.h:33
uint16_t value_type
Definition: vr.h:29
constexpr VR(Data data)
Definition: vr.h:41
Definition: vr.h:31
std::string long_str() const
constexpr VR(char c1, char c2)
Definition: vr.h:43
InvalidValueManipulator(const VR &vr)
Definition: vr.h:18
Definition: age.h:6
bool valid() const
constexpr VR()
Definition: vr.h:40
std::string str() const
void validate_value_manipulator() const
Definition: vr.h:81