libzypp 17.31.23
zypp::base::Flags< TEnum > Class Template Reference

A type-safe way of storing OR-combinations of enum values (like QTs QFlags). More...

#include <base/Flags.h>

Public Types

typedef TEnum Enum
 The underlying enum type.
 
typedef std::underlying_type< Enum >::type Integral
 The underlying integral type.
 

Public Member Functions

constexpr Flags ()
 
constexpr Flags (Enum flag_r)
 
constexpr Flags (Integral flag_r)
 
constexpr bool isNone () const
 
constexpr bool isAll () const
 
Flagsoperator&= (Flags rhs)
 
Flagsoperator&= (Enum rhs)
 
Flagsoperator|= (Flags rhs)
 
Flagsoperator|= (Enum rhs)
 
Flagsoperator^= (Flags rhs)
 
Flagsoperator^= (Enum rhs)
 
constexpr operator Integral () const
 
constexpr Flags operator& (Flags rhs) const
 
constexpr Flags operator& (Enum rhs) const
 
constexpr Flags operator| (Flags rhs) const
 
constexpr Flags operator| (Enum rhs) const
 
constexpr Flags operator^ (Flags rhs) const
 
constexpr Flags operator^ (Enum rhs) const
 
constexpr Flags operator~ () const
 
constexpr bool operator== (Enum rhs) const
 
constexpr bool operator!= (Enum rhs) const
 
FlagssetFlag (Flags flag_r, bool newval_r)
 
FlagssetFlag (Enum flag_r, bool newval_r)
 
FlagssetFlag (Flags flag_r)
 
FlagssetFlag (Enum flag_r)
 
FlagsunsetFlag (Flags flag_r)
 
FlagsunsetFlag (Enum flag_r)
 
constexpr bool testFlag (Flags flag_r) const
 
constexpr bool testFlag (Enum flag_r) const
 

Static Public Member Functions

static constexpr Flags none ()
 
static constexpr Flags all ()
 

Private Member Functions

constexpr bool testFlag (Integral flag) const
 

Static Private Member Functions

static constexpr Integral integral (Flags obj)
 
static constexpr Integral integral (Enum obj)
 

Private Attributes

Integral _val
 

Related Functions

(Note that these are not member functions.)

template<typename Enum >
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="]")
 Stringify Build a string of OR'ed names of each flag value set in flag_r.
 

Detailed Description

template<typename TEnum>
class zypp::base::Flags< TEnum >

A type-safe way of storing OR-combinations of enum values (like QTs QFlags).

See also
QFlags Class Reference
class RpmDb
{
public:
enum DbStateInfoBits {
DbSI_NO_INIT = 0x0000,
DbSI_HAVE_V4 = 0x0001,
DbSI_MADE_V4 = 0x0002,
DbSI_MODIFIED_V4 = 0x0004,
DbSI_HAVE_V3 = 0x0008,
DbSI_HAVE_V3TOV4 = 0x0010,
DbSI_MADE_V3TOV4 = 0x0020
};
ZYPP_DECLARE_FLAGS(DbStateInfo,DbStateInfoBits);
};
...
enum Other { OTHERVAL = 13 };
{
XRpmDb::DbStateInfo s;
s = XRpmDb::DbSI_MODIFIED_V4|XRpmDb::DbSI_HAVE_V4;
// s |= OTHERVAL; // As desired: it does not compile
}
#define ZYPP_DECLARE_OPERATORS_FOR_FLAGS(Name)
Definition: Flags.h:177
#define ZYPP_DECLARE_FLAGS(Name, Enum)
Definition: Flags.h:174

Definition at line 58 of file Flags.h.

Member Typedef Documentation

◆ Enum

template<typename TEnum >
typedef TEnum zypp::base::Flags< TEnum >::Enum

The underlying enum type.

Definition at line 61 of file Flags.h.

◆ Integral

template<typename TEnum >
typedef std::underlying_type<Enum>::type zypp::base::Flags< TEnum >::Integral

The underlying integral type.

Definition at line 62 of file Flags.h.

Constructor & Destructor Documentation

◆ Flags() [1/3]

template<typename TEnum >
constexpr zypp::base::Flags< TEnum >::Flags ( )
inlineconstexpr

Definition at line 65 of file Flags.h.

◆ Flags() [2/3]

template<typename TEnum >
constexpr zypp::base::Flags< TEnum >::Flags ( Enum  flag_r)
inlineconstexpr

Definition at line 66 of file Flags.h.

◆ Flags() [3/3]

template<typename TEnum >
constexpr zypp::base::Flags< TEnum >::Flags ( Integral  flag_r)
inlineexplicitconstexpr

Definition at line 67 of file Flags.h.

Member Function Documentation

◆ none()

template<typename TEnum >
static constexpr Flags zypp::base::Flags< TEnum >::none ( )
inlinestaticconstexpr

Definition at line 69 of file Flags.h.

◆ all()

template<typename TEnum >
static constexpr Flags zypp::base::Flags< TEnum >::all ( )
inlinestaticconstexpr

Definition at line 70 of file Flags.h.

◆ isNone()

template<typename TEnum >
constexpr bool zypp::base::Flags< TEnum >::isNone ( ) const
inlineconstexpr

Definition at line 72 of file Flags.h.

◆ isAll()

template<typename TEnum >
constexpr bool zypp::base::Flags< TEnum >::isAll ( ) const
inlineconstexpr

Definition at line 73 of file Flags.h.

◆ operator&=() [1/2]

template<typename TEnum >
Flags & zypp::base::Flags< TEnum >::operator&= ( Flags< TEnum >  rhs)
inline

Definition at line 75 of file Flags.h.

◆ operator&=() [2/2]

template<typename TEnum >
Flags & zypp::base::Flags< TEnum >::operator&= ( Enum  rhs)
inline

Definition at line 76 of file Flags.h.

◆ operator|=() [1/2]

template<typename TEnum >
Flags & zypp::base::Flags< TEnum >::operator|= ( Flags< TEnum >  rhs)
inline

Definition at line 78 of file Flags.h.

◆ operator|=() [2/2]

template<typename TEnum >
Flags & zypp::base::Flags< TEnum >::operator|= ( Enum  rhs)
inline

Definition at line 79 of file Flags.h.

◆ operator^=() [1/2]

template<typename TEnum >
Flags & zypp::base::Flags< TEnum >::operator^= ( Flags< TEnum >  rhs)
inline

Definition at line 81 of file Flags.h.

◆ operator^=() [2/2]

template<typename TEnum >
Flags & zypp::base::Flags< TEnum >::operator^= ( Enum  rhs)
inline

Definition at line 82 of file Flags.h.

◆ operator Integral()

template<typename TEnum >
constexpr zypp::base::Flags< TEnum >::operator Integral ( ) const
inlineconstexpr

Definition at line 85 of file Flags.h.

◆ operator&() [1/2]

template<typename TEnum >
constexpr Flags zypp::base::Flags< TEnum >::operator& ( Flags< TEnum >  rhs) const
inlineconstexpr

Definition at line 87 of file Flags.h.

◆ operator&() [2/2]

template<typename TEnum >
constexpr Flags zypp::base::Flags< TEnum >::operator& ( Enum  rhs) const
inlineconstexpr

Definition at line 88 of file Flags.h.

◆ operator|() [1/2]

template<typename TEnum >
constexpr Flags zypp::base::Flags< TEnum >::operator| ( Flags< TEnum >  rhs) const
inlineconstexpr

Definition at line 90 of file Flags.h.

◆ operator|() [2/2]

template<typename TEnum >
constexpr Flags zypp::base::Flags< TEnum >::operator| ( Enum  rhs) const
inlineconstexpr

Definition at line 91 of file Flags.h.

◆ operator^() [1/2]

template<typename TEnum >
constexpr Flags zypp::base::Flags< TEnum >::operator^ ( Flags< TEnum >  rhs) const
inlineconstexpr

Definition at line 93 of file Flags.h.

◆ operator^() [2/2]

template<typename TEnum >
constexpr Flags zypp::base::Flags< TEnum >::operator^ ( Enum  rhs) const
inlineconstexpr

Definition at line 94 of file Flags.h.

◆ operator~()

template<typename TEnum >
constexpr Flags zypp::base::Flags< TEnum >::operator~ ( ) const
inlineconstexpr

Definition at line 96 of file Flags.h.

◆ operator==()

template<typename TEnum >
constexpr bool zypp::base::Flags< TEnum >::operator== ( Enum  rhs) const
inlineconstexpr

Definition at line 98 of file Flags.h.

◆ operator!=()

template<typename TEnum >
constexpr bool zypp::base::Flags< TEnum >::operator!= ( Enum  rhs) const
inlineconstexpr

Definition at line 99 of file Flags.h.

◆ setFlag() [1/4]

template<typename TEnum >
Flags & zypp::base::Flags< TEnum >::setFlag ( Flags< TEnum >  flag_r,
bool  newval_r 
)
inline

Definition at line 102 of file Flags.h.

◆ setFlag() [2/4]

template<typename TEnum >
Flags & zypp::base::Flags< TEnum >::setFlag ( Enum  flag_r,
bool  newval_r 
)
inline

Definition at line 103 of file Flags.h.

◆ setFlag() [3/4]

template<typename TEnum >
Flags & zypp::base::Flags< TEnum >::setFlag ( Flags< TEnum >  flag_r)
inline

Definition at line 105 of file Flags.h.

◆ setFlag() [4/4]

template<typename TEnum >
Flags & zypp::base::Flags< TEnum >::setFlag ( Enum  flag_r)
inline

Definition at line 106 of file Flags.h.

◆ unsetFlag() [1/2]

template<typename TEnum >
Flags & zypp::base::Flags< TEnum >::unsetFlag ( Flags< TEnum >  flag_r)
inline

Definition at line 108 of file Flags.h.

◆ unsetFlag() [2/2]

template<typename TEnum >
Flags & zypp::base::Flags< TEnum >::unsetFlag ( Enum  flag_r)
inline

Definition at line 109 of file Flags.h.

◆ testFlag() [1/3]

template<typename TEnum >
constexpr bool zypp::base::Flags< TEnum >::testFlag ( Flags< TEnum >  flag_r) const
inlineconstexpr

Definition at line 111 of file Flags.h.

◆ testFlag() [2/3]

template<typename TEnum >
constexpr bool zypp::base::Flags< TEnum >::testFlag ( Enum  flag_r) const
inlineconstexpr

Definition at line 112 of file Flags.h.

◆ testFlag() [3/3]

template<typename TEnum >
constexpr bool zypp::base::Flags< TEnum >::testFlag ( Integral  flag) const
inlineconstexprprivate

Definition at line 115 of file Flags.h.

◆ integral() [1/2]

template<typename TEnum >
static constexpr Integral zypp::base::Flags< TEnum >::integral ( Flags< TEnum >  obj)
inlinestaticconstexprprivate

Definition at line 117 of file Flags.h.

◆ integral() [2/2]

template<typename TEnum >
static constexpr Integral zypp::base::Flags< TEnum >::integral ( Enum  obj)
inlinestaticconstexprprivate

Definition at line 118 of file Flags.h.

Friends And Related Function Documentation

◆ stringify()

template<typename Enum >
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 = "]" 
)
related

Stringify Build a string of OR'ed names of each flag value set in flag_r.

Remaining bits in flag_r are added as hexstring.

enum E { a=1, b=2, c=4 };
ZYPP_DECLARE_FLAGS( E, MyFlags );
MyFlags f = a|b|c;
cout << f << " = " << stringify( f, { {a,"A"}, {b,"B"} } ) << endl;
// prints: 0x0007 = [A|B|0x4]
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="]")
Stringify Build a string of OR'ed names of each flag value set in flag_r.
Definition: Flags.h:137
unsigned short a
unsigned short b

Definition at line 137 of file Flags.h.

Member Data Documentation

◆ _val

template<typename TEnum >
Integral zypp::base::Flags< TEnum >::_val
private

Definition at line 120 of file Flags.h.


The documentation for this class was generated from the following file: