Emergency 20 Dokumentation  4.2.0
BitStreamAndEnumClassHelper.h
Go to the documentation of this file.
1 // Copyright (C) 2012-2018 Promotion Software GmbH
2 
3 
4 //[-------------------------------------------------------]
5 //[ Header guard ]
6 //[-------------------------------------------------------]
7 #pragma once
8 
9 
10 //[-------------------------------------------------------]
11 //[ Includes ]
12 //[-------------------------------------------------------]
14 
15 
16 //[-------------------------------------------------------]
17 //[ Namespace ]
18 //[-------------------------------------------------------]
19 namespace em5
20 {
21  namespace multiplayer
22  {
23 
28  template <class T>
29  inline void writeToBitstream(qsf::game::BitStream& bitStream, const T& enumClassValue)
30  {
31  bitStream.write(static_cast<typename std::underlying_type<T>::type>(enumClassValue));
32  }
33 
34  template <class T>
35  inline void writeToBitstream(qsf::game::BitStream& bitStream, const T& enumClassValue, size_t bitCount)
36  {
37  bitStream.write(static_cast<typename std::underlying_type<T>::type>(enumClassValue), bitCount);
38  }
39 
40  template <class T>
41  inline bool readFromBitstream(const qsf::game::BitStream& bitStream, T& enumClassValue)
42  {
43  typename std::underlying_type<T>::type value;
44  if (bitStream.read(value))
45  {
46  enumClassValue = static_cast<T>(value);
47  return true;
48  }
49 
50  return false;
51  }
52 
53  template <class T>
54  inline bool readFromBitstream(const qsf::game::BitStream& bitStream, T& enumClassValue, size_t bitCount)
55  {
56  typename std::underlying_type<T>::type value;
57  if (bitStream.read(value, bitCount))
58  {
59  enumClassValue = static_cast<T>(value);
60  return true;
61  }
62 
63  return false;
64  }
65 
66 
67 //[-------------------------------------------------------]
68 //[ Namespace ]
69 //[-------------------------------------------------------]
70  } // multiplayer
71 } // em5
Definition: ActionPriority.h:13
void writeToBitstream(qsf::game::BitStream &bitStream, const T &enumClassValue)
Helper methods to read/write enum class values from/to bit stream.
Definition: BitStreamAndEnumClassHelper.h:29
bool readFromBitstream(const qsf::game::BitStream &bitStream, T &enumClassValue)
Definition: BitStreamAndEnumClassHelper.h:41
Game bit stream class (just a wrapper for linnet bit stream)
Definition: BitStream.h:40
bool read(bool &value) const
void write(bool value)