chigraph  master
Systems programming language written for beginners in LLVM
chi::Flags< Enum > Struct Template Reference

A template class for type-safe flags. More...

#include <chi/Support/Flags.hpp>

Public Member Functions

 Flags ()=default
 Default constructor.
 
 Flags (Enum e)
 Constructor from an Enum type. More...
 
 Flags (const Flags &fl)=default
 Copy constructor. More...
 
 Flags (Flags &&fl)=default
 Move constructor. More...
 
Flags operator & (const Flags &rhs) const
 Bitwise AND. More...
 
Flagsoperator &= (const Flags &rhs)
 Bitwise AND assignment. More...
 
 operator bool () const
 Check if the flags object isn't set to zero Useful for use after a & More...
 
bool operator! () const
 See if one Flags object isn't equal to the other. More...
 
Flagsoperator= (const Flags &fl)=default
 Copy assignment. More...
 
Flagsoperator= (Flags &&fl)=default
 Move assignment. More...
 
bool operator== (const Flags &rhs) const
 See if one Flags object is equal to the other. More...
 
Flags operator| (const Flags &rhs) const
 Bitwise OR. More...
 
Flagsoperator|= (const Flags &rhs)
 Bitwise OR assignment. More...
 

Detailed Description

template<typename Enum>
struct chi::Flags< Enum >

A template class for type-safe flags.

Usage:

enum class MyOpts {
First = 1u,
Second = 1u << 1,
FirstAndSecond = First | Second,
};
chi::Flags<MyOpts> fl{MyOpts::First | MyOpts::Second};
assert(fl & MyOpts::First);

Definition at line 26 of file Flags.hpp.

Constructor & Destructor Documentation

◆ Flags() [1/3]

template<typename Enum>
chi::Flags< Enum >::Flags ( Enum  e)
inline

Constructor from an Enum type.

Parameters
eThe enum to copy from

Definition at line 34 of file Flags.hpp.

References chi::Flags< Enum >::Flags(), and chi::Flags< Enum >::operator=().

+ Here is the call graph for this function:

◆ Flags() [2/3]

template<typename Enum>
chi::Flags< Enum >::Flags ( const Flags< Enum > &  fl)
default

Copy constructor.

Parameters
flThe Flags object to copy from

◆ Flags() [3/3]

template<typename Enum>
chi::Flags< Enum >::Flags ( Flags< Enum > &&  fl)
default

Move constructor.

Parameters
flThe Flags object to move from

Member Function Documentation

◆ operator &()

template<typename Enum>
Flags chi::Flags< Enum >::operator& ( const Flags< Enum > &  rhs) const
inline

Bitwise AND.

Parameters
rhsThe Flags object to AND with
Returns
The new Flags object

Definition at line 76 of file Flags.hpp.

◆ operator &=()

template<typename Enum>
Flags& chi::Flags< Enum >::operator&= ( const Flags< Enum > &  rhs)
inline

Bitwise AND assignment.

Parameters
rhsThe Flags obejct to AND *this with
Returns
*this

Definition at line 89 of file Flags.hpp.

References chi::Flags< Enum >::Flags().

+ Here is the call graph for this function:

◆ operator bool()

template<typename Enum>
chi::Flags< Enum >::operator bool ( ) const
inlineexplicit

Check if the flags object isn't set to zero Useful for use after a &

Returns
true if it's not zero

Definition at line 66 of file Flags.hpp.

◆ operator!()

template<typename Enum>
bool chi::Flags< Enum >::operator! ( ) const
inline

See if one Flags object isn't equal to the other.

Returns
if they are equal

Definition at line 61 of file Flags.hpp.

◆ operator=() [1/2]

template<typename Enum>
Flags& chi::Flags< Enum >::operator= ( const Flags< Enum > &  fl)
default

Copy assignment.

Parameters
flThe Flags object to copy from
Returns
*this

Referenced by chi::Flags< Enum >::Flags().

+ Here is the caller graph for this function:

◆ operator=() [2/2]

template<typename Enum>
Flags& chi::Flags< Enum >::operator= ( Flags< Enum > &&  fl)
default

Move assignment.

Parameters
TheFlags object to move from
Returns
*this

◆ operator==()

template<typename Enum>
bool chi::Flags< Enum >::operator== ( const Flags< Enum > &  rhs) const
inline

See if one Flags object is equal to the other.

Parameters
rhsThe Flags object to comare to
Returns
if they are equal

Definition at line 57 of file Flags.hpp.

◆ operator|()

template<typename Enum>
Flags chi::Flags< Enum >::operator| ( const Flags< Enum > &  rhs) const
inline

Bitwise OR.

Parameters
rhsThe Flags object to OR with
Returns
The new Flags object

Definition at line 71 of file Flags.hpp.

◆ operator|=()

template<typename Enum>
Flags& chi::Flags< Enum >::operator|= ( const Flags< Enum > &  rhs)
inline

Bitwise OR assignment.

Parameters
rhsThe Flags obejct to OR *this with
Returns
*this

Definition at line 81 of file Flags.hpp.


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