#pragma once #include // This class provides a representation for flags that can be combined with bitwise // operations. However, because the class is templated with an id, it's not possible to // mixup flags belonging to different classes. This avoids many bugs due to confusion of flags types // that occur when all flags are uint32_t values. // // To use this class, define an ID that is different than other flags classes, and do a typedef: // // #define TRANSFER_INFO_FLAGS_TAG 0x8133ea // typedef t_RsFlags32 TransferInfoFlags ; // // Implementation details: // - we cannot have at the same time a implicit contructor from uint32_t and a bool operator, otherwise c++ // mixes up operators and transforms flags into booleans before combining them further. // // So I decided to have: // - an explicit constructor from uint32_t // - an implicit bool operator, that allows test like if(flags & FLAGS_VALUE) // template class t_RsFlags32 { public: inline t_RsFlags32() { _bits=0; } inline explicit t_RsFlags32(uint32_t N) : _bits(N) {} // allows initialization from a set of uint32_t inline t_RsFlags32 operator| (const t_RsFlags32& f) const { return t_RsFlags32(_bits | f._bits) ; } inline t_RsFlags32 operator^ (const t_RsFlags32& f) const { return t_RsFlags32(_bits ^ f._bits) ; } inline t_RsFlags32 operator* (const t_RsFlags32& f) const { return t_RsFlags32(_bits & f._bits) ; } inline bool operator!=(const t_RsFlags32& f) const { return _bits != f._bits ; } inline bool operator==(const t_RsFlags32& f) const { return _bits == f._bits ; } inline bool operator& (const t_RsFlags32& f) const { return (_bits & f._bits)>0 ; } inline t_RsFlags32 operator|=(const t_RsFlags32& f) { _bits |= f._bits ; return *this ;} inline t_RsFlags32 operator^=(const t_RsFlags32& f) { _bits ^= f._bits ; return *this ;} inline t_RsFlags32 operator&=(const t_RsFlags32& f) { _bits &= f._bits ; return *this ;} inline t_RsFlags32 operator~() const { return t_RsFlags32(~_bits) ; } //inline explicit operator bool() const { return _bits>0; } inline uint32_t toUInt32() const { return _bits ; } void clear() { _bits = 0 ; } friend std::ostream& operator<<(std::ostream& o,const t_RsFlags32& f) // friendly print with 0 and I { for(int i=31;i>=0;--i) { std::string res = f._bits&(1< TransferRequestFlags ; // Flags for file storage. Mainly permissions like BROWSABLE/NETWORK_WIDE for groups and peers. // typedef t_RsFlags32 FileStorageFlags ; // Flags for searching in files that could be local, downloads, remote, etc. // typedef t_RsFlags32 FileSearchFlags ; // Service permissions. Will allow each user to use or not use each service. // typedef t_RsFlags32 ServicePermissionFlags ; // Flags for chat lobbies // typedef t_RsFlags32 ChatLobbyFlags ; // Flags for serializer // typedef t_RsFlags32 SerializationFlags ;