libzypp: zypp-core/base/EnumClass.h Source File

libzypp 17.38.15

EnumClass.h
Go to the documentation of this file.
1/*---------------------------------------------------------------------\
2| ____ _ __ __ ___ |
3| |__ / \ / / . \ . \ |
4| / / \ V /| _/ _/ |
5| / /__ | | | | | | |
6| /_____||_| |_| |_| |
7| |
8\---------------------------------------------------------------------*/
11#ifndef ZYPP_BASE_ENUMCLASS_H
12#define ZYPP_BASE_ENUMCLASS_H
13
14#include <iosfwd>
15
16#include <zypp-core/base/PtrTypes.h>
17
19namespace zypp
20{
22 namespace base
23 {
46 template<typename TEnumDef>
47 class EnumClass : public TEnumDef
48 {
49 public:
50 using Enum = typename TEnumDef::Enum;
51 using Integral = std::underlying_type_t<Enum>;
52
53 EnumClass( Enum val_r ) : _val( val_r ) {}
54
64 Enum asEnum() const { return _val; }
65
75 Integral asIntegral() const { return static_cast<Integral>(_val); }
76
77 friend bool operator==( const EnumClass & lhs, const EnumClass & rhs ) { return lhs._val == rhs._val; }
78 friend bool operator!=( const EnumClass & lhs, const EnumClass & rhs ) { return lhs._val != rhs._val; }
79 friend bool operator< ( const EnumClass & lhs, const EnumClass & rhs ) { return lhs._val < rhs._val; }
80 friend bool operator<=( const EnumClass & lhs, const EnumClass & rhs ) { return lhs._val <= rhs._val; }
81 friend bool operator> ( const EnumClass & lhs, const EnumClass & rhs ) { return lhs._val > rhs._val; }
82 friend bool operator>=( const EnumClass & lhs, const EnumClass & rhs ) { return lhs._val >= rhs._val; }
83
84 private:
85 Enum _val;
86 };
87 } // namespace base
89} // namespace zypp
91#endif // ZYPP_BASE_ENUMCLASS_H
PtrTypes.h
zypp::base
Definition Random.cc:7
zypp
Easy-to use interface to the ZYPP dependency resolver.
Definition CodePitfalls.doc:2
zypp::operator>=
bool operator>=(const IdString &lhs, const IdString &rhs)
relates: IdString GreaterEqual
Definition IdString.h:239
zypp::operator!=
bool operator!=(const Capability &lhs, const Capability &rhs)
relates: Capability
Definition Capability.h:313
zypp::operator<=
bool operator<=(const IdString &lhs, const IdString &rhs)
relates: IdString LessEqual
Definition IdString.h:207
zypp::operator==
bool operator==(const Capability &lhs, const Capability &rhs)
relates: Capability
Definition Capability.h:309