Zserio C++ runtime library  1.2.0
Built for Zserio 2.16.0
ParsingInfo.h
Go to the documentation of this file.
1 #ifndef ZSERIO_PARSING_INFO_INC_H
2 #define ZSERIO_PARSING_INFO_INC_H
3 
4 #include <cstddef>
5 #include <limits>
6 
8 
9 namespace zserio
10 {
11 
17 {
18 public:
23  m_bitPosition(INVALID_BIT_POSITION),
24  m_bitSize(INVALID_BIT_SIZE)
25  {}
26 
32  explicit ParsingInfo(size_t bitPosition) :
33  m_bitPosition(bitPosition),
34  m_bitSize(INVALID_BIT_SIZE)
35  {}
36 
46  void initializeBitSize(size_t endBitPosition)
47  {
48  const size_t bitPosition = getBitPosition();
49  if (endBitPosition < bitPosition)
50  {
51  throw CppRuntimeException("Invalid end bit position argument (")
52  << endBitPosition << " < " << bitPosition << ")!";
53  }
54 
55  m_bitSize = endBitPosition - getBitPosition();
56  }
57 
65  size_t getBitPosition() const
66  {
67  if (m_bitPosition == INVALID_BIT_POSITION)
68  {
69  throw CppRuntimeException("Invalid bit position, call the reader constructor first!");
70  }
71 
72  return m_bitPosition;
73  }
74 
82  size_t getBitSize() const
83  {
84  if (m_bitSize == INVALID_BIT_SIZE)
85  {
86  throw CppRuntimeException("Invalid bit size, call the reader constructor first!");
87  }
88 
89  return m_bitSize;
90  }
91 
92 private:
93  static constexpr size_t INVALID_BIT_POSITION = std::numeric_limits<size_t>::max();
94  static constexpr size_t INVALID_BIT_SIZE = std::numeric_limits<size_t>::max();
95 
96  size_t m_bitPosition;
97  size_t m_bitSize;
98 };
99 
100 } // namespace zserio
101 
102 #endif // ZSERIO_PARSING_INFO_INC_H
ParsingInfo(size_t bitPosition)
Definition: ParsingInfo.h:32
void initializeBitSize(size_t endBitPosition)
Definition: ParsingInfo.h:46
size_t getBitSize() const
Definition: ParsingInfo.h:82
size_t getBitPosition() const
Definition: ParsingInfo.h:65