12 #ifndef ZYPP_BASE_FLAGS_H
13 #define ZYPP_BASE_FLAGS_H
57 template<
typename TEnum>
62 typedef typename std::underlying_type<Enum>::type
Integral;
136 template<
typename Enum>
138 std::string intro_r =
"[", std::string sep_r =
"|", std::string extro_r =
"]" )
140 std::string ret( std::move(intro_r) );
144 for (
const auto & pair : flaglist_r )
146 if ( flag_r.
testFlag( pair.first ) )
151 if ( sep.empty() && !sep_r.empty() )
152 { sep = std::move(sep_r); }
155 mask = flag_r & ~mask;
161 ret += std::move(extro_r);
165 template<
typename TEnum>
166 inline std::ostream & operator<<( std::ostream & str, const Flags<TEnum> & obj )
169 template<
typename TEnum>
170 inline std::ostream & operator<<( std::ostream & str, const typename Flags<TEnum>::Enum & obj )
171 {
return str << Flags<TEnum>(obj); }
174 #define ZYPP_DECLARE_FLAGS(Name,Enum) typedef zypp::base::Flags<Enum> Name
177 #define ZYPP_DECLARE_OPERATORS_FOR_FLAGS(Name) \
178 inline constexpr bool operator==( Name::Enum lhs, Name rhs ) { return( rhs == lhs ); } \
179 inline constexpr bool operator!=(Name:: Enum lhs, Name rhs ) { return( rhs != lhs ); } \
180 inline constexpr Name operator&( Name::Enum lhs, Name::Enum rhs ) { return Name( lhs ) & rhs; } \
181 inline constexpr Name operator&( Name::Enum lhs, Name rhs ) { return rhs & lhs; } \
182 inline constexpr Name operator|( Name::Enum lhs, Name::Enum rhs ) { return Name( lhs ) | rhs; } \
183 inline constexpr Name operator|( Name::Enum lhs, Name rhs ) { return rhs | lhs; } \
184 inline constexpr Name operator^( Name::Enum lhs, Name::Enum rhs ) { return Name( lhs ) ^ rhs; } \
185 inline constexpr Name operator^( Name::Enum lhs, Name rhs ) { return rhs ^ lhs; } \
186 inline constexpr Name operator~( Name::Enum lhs ) { return ~Name( lhs ); }
189 #define ZYPP_DECLARE_FLAGS_AND_OPERATORS(Name,Enum) \
190 ZYPP_DECLARE_FLAGS(Name,Enum); \
191 ZYPP_DECLARE_OPERATORS_FOR_FLAGS(Name)
199 #endif // ZYPP_BASE_FLAGS_H
constexpr Flags(Integral flag_r)
Flags & operator|=(Flags rhs)
constexpr Flags(Enum flag_r)
constexpr Flags operator~() const
TEnum Enum
The underlying enum type.
Flags & operator^=(Enum rhs)
constexpr bool testFlag(Flags flag_r) const
constexpr bool operator==(Enum rhs) const
constexpr Flags operator^(Enum rhs) const
static constexpr Integral integral(Flags obj)
std::string stringify(const Flags< Enum > &flag_r, const std::initializer_list< std::pair< Flags< Enum >, std::string > > &flaglist_r={}, std::string intro_r="[", std::string sep_r="|", std::string extro_r="]")
constexpr Flags operator|(Enum rhs) const
constexpr bool testFlag(Integral flag)
A type-safe way of storing OR-combinations of enum values (like QTs QFlags).
Flags & operator&=(Flags rhs)
Flags & operator|=(Enum rhs)
Flags & setFlag(Enum flag_r)
static constexpr Integral integral(Enum obj)
Flags & operator&=(Enum rhs)
constexpr bool testFlag(Enum flag_r) const
Flags & unsetFlag(Flags flag_r)
static constexpr Flags all()
constexpr bool operator!=(Enum rhs) const
Flags & operator^=(Flags rhs)
constexpr bool isNone() const
constexpr bool isAll() const
constexpr Flags operator^(Flags rhs) const
Flags & setFlag(Flags flag_r, bool newval_r)
Flags & unsetFlag(Enum flag_r)
constexpr Flags operator&(Flags rhs) const
Flags & setFlag(Enum flag_r, bool newval_r)
std::underlying_type< Enum >::type Integral
The underlying integral type.
static constexpr Flags none()
constexpr Flags operator&(Enum rhs) const
constexpr Flags operator|(Flags rhs) const
Flags & setFlag(Flags flag_r)
std::string hexstring(char n, int w=4)