Skip to content

Commit

Permalink
Handling enums with fixed underlying type
Browse files Browse the repository at this point in the history
This is absolutely mandatory to cope with some compiler's bugs (int
instead of short/char) and with the C++ standard defect there (call is
ambigous).
  • Loading branch information
germinolegrand committed May 12, 2013
1 parent 80d0e70 commit 7515b96
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions include/SFML/Network/Packet.hpp
Expand Up @@ -175,6 +175,8 @@ public :
/// Overloads of operator >> to read data from the packet
///
////////////////////////////////////////////////////////////
template <class EnumT> inline
Packet& operator >>(EnumT& data);
Packet& operator >>(bool& data);
Packet& operator >>(Int8& data);
Packet& operator >>(Uint8& data);
Expand All @@ -194,6 +196,8 @@ public :
/// Overloads of operator << to write data into the packet
///
////////////////////////////////////////////////////////////
template <class EnumT> inline
Packet& operator <<(EnumT data);
Packet& operator <<(bool data);
Packet& operator <<(Int8 data);
Packet& operator <<(Uint8 data);
Expand Down Expand Up @@ -317,6 +321,22 @@ inline void Packet::overwrite(size_t writePos, size_t begin)
m_data.resize(begin);
}

template <class EnumT> inline
sf::Packet& sf::Packet::operator>>(EnumT& en)
{
typename std::underlying_type<EnumT>::type en_t(0);
*this >> en_t;
en = static_cast<EnumT>(en_t);
return *this;
}

template <class EnumT> inline
sf::Packet& sf::Packet::operator<<(EnumT en)
{
*this << static_cast<typename std::underlying_type<EnumT>::type>(en);
return *this;
}

} // namespace sf


Expand Down

0 comments on commit 7515b96

Please sign in to comment.