D++ (DPP)
C++ Discord API Bot Library
All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Pages
dpp::permission Class Reference

Represents a permission bitmask (refer to enum dpp::permissions) which are held in an uint64_t. More...

+ Collaboration diagram for dpp::permission:

Public Member Functions

constexpr permission ()=default
 Default constructor, initializes permission to 0. More...
 
constexpr permission (uint64_t value) noexcept
 Bitmask constructor, initializes permission to the argument. More...
 
constexpr operator uint64_t () const noexcept
 For acting like an integer. More...
 
constexpr operator uint64_t & () noexcept
 For acting like an integer. More...
 
template<typename... T>
constexpr bool has (T... values) const noexcept
 Check for permission flags set. It uses the Bitwise AND operator. More...
 
template<typename... T>
constexpr std::enable_if_t<(std::is_convertible_v< T, uint64_t > &&...), permission & > add (T... values) noexcept
 Add a permission with the Bitwise OR operation. More...
 
template<typename... T>
constexpr std::enable_if_t<(std::is_convertible_v< T, uint64_t > &&...), permission & > set (T... values) noexcept
 Assign a permission. This will reset the bitmask to the new value. More...
 
template<typename... T>
constexpr std::enable_if_t<(std::is_convertible_v< T, uint64_t > &&...), permission & > remove (T... values) noexcept
 Remove a permission with the Bitwise NOT operation. More...
 

Protected Attributes

uint64_t value {0}
 The permission bitmask value. More...
 

Detailed Description

Represents a permission bitmask (refer to enum dpp::permissions) which are held in an uint64_t.

Constructor & Destructor Documentation

◆ permission() [1/2]

constexpr dpp::permission::permission ( )
constexprdefault

Default constructor, initializes permission to 0.

◆ permission() [2/2]

constexpr dpp::permission::permission ( uint64_t  value)
inlineconstexprnoexcept

Bitmask constructor, initializes permission to the argument.

Parameters
valueThe bitmask to initialize the permission to

Member Function Documentation

◆ add()

template<typename... T>
constexpr std::enable_if_t<(std::is_convertible_v<T, uint64_t> && ...), permission&> dpp::permission::add ( T...  values)
inlineconstexprnoexcept

Add a permission with the Bitwise OR operation.

Template Parameters
Tone or more uint64_t permission bits
Parameters
valuesThe permissions (from dpp::permissions) to add

Example:

permission.add(dpp::p_view_channel, dpp::p_send_messages);
// Adds p_view_channel and p_send_messages to the permission bitmask
Returns
permission& reference to self for chaining

◆ has()

template<typename... T>
constexpr bool dpp::permission::has ( T...  values) const
inlineconstexprnoexcept

Check for permission flags set. It uses the Bitwise AND operator.

Template Parameters
Tone or more uint64_t permission bits
Parameters
valuesThe permissions (from dpp::permissions) to check for

Example:

bool is_mod = permission.has(dpp::p_kick_members, dpp::p_ban_members);
// Returns true if the permission bitmask contains p_kick_members and p_ban_members
Returns
bool True if it has all the given permissions

◆ operator uint64_t()

constexpr dpp::permission::operator uint64_t ( ) const
inlineconstexprnoexcept

For acting like an integer.

Returns
The permission bitmask value

◆ operator uint64_t &()

constexpr dpp::permission::operator uint64_t & ( )
inlineconstexprnoexcept

For acting like an integer.

Returns
A reference to the permission bitmask value

◆ remove()

template<typename... T>
constexpr std::enable_if_t<(std::is_convertible_v<T, uint64_t> && ...), permission&> dpp::permission::remove ( T...  values)
inlineconstexprnoexcept

Remove a permission with the Bitwise NOT operation.

Template Parameters
Tone or more uint64_t permission bits
Parameters
valuesThe permissions (from dpp::permissions) to remove

Example:

permission.remove(dpp::p_view_channel, dpp::p_send_messages);
// Removes p_view_channel and p_send_messages permission
Returns
permission& reference to self for chaining

◆ set()

template<typename... T>
constexpr std::enable_if_t<(std::is_convertible_v<T, uint64_t> && ...), permission&> dpp::permission::set ( T...  values)
inlineconstexprnoexcept

Assign a permission. This will reset the bitmask to the new value.

Template Parameters
Tone or more uint64_t permission bits
Parameters
valuesThe permissions (from dpp::permissions) to set

Example:

permission.set(dpp::p_view_channel, dpp::p_send_messages);
Returns
permission& reference to self for chaining

Member Data Documentation

◆ value

uint64_t dpp::permission::value {0}
protected

The permission bitmask value.

dpp::permission::permission
constexpr permission()=default
Default constructor, initializes permission to 0.
dpp::p_kick_members
@ p_kick_members
allows kicking members
Definition: permissions.h:72
dpp::p_send_messages
@ p_send_messages
allows for sending messages in a channel
Definition: permissions.h:82
dpp::p_view_channel
@ p_view_channel
allows guild members to view a channel, which includes reading messages in text channels and joining ...
Definition: permissions.h:81
dpp::p_ban_members
@ p_ban_members
allows banning members
Definition: permissions.h:73
D++ Library version 9.0.13D++ Library version 9.0.12D++ Library version 9.0.11D++ Library version 9.0.10D++ Library version 9.0.9D++ Library version 9.0.8D++ Library version 9.0.7D++ Library version 9.0.6D++ Library version 9.0.5D++ Library version 9.0.4D++ Library version 9.0.3D++ Library version 9.0.2D++ Library version 9.0.1D++ Library version 9.0.0D++ Library version 1.0.2D++ Library version 1.0.1D++ Library version 1.0.0