Skip to content

Commit

Permalink
pw_bluetooth: Add CharacteristicPropertyBits operators
Browse files Browse the repository at this point in the history
CharacteristicPropertyBits are normally combined with operator| when
defining services that support multiple properties for the same
characteristic, for example kRead and kWrite. This patch adds operator|,
operator& and operator|= to help combine and compare these values
without needing multiple static_cast<> statements.

Change-Id: I5ee6407c1479c5a09848cb4ebe5a7c3406682461
Reviewed-on: https://pigweed-review.googlesource.com/c/pigweed/pigweed/+/122210
Reviewed-by: Ben Lawson <[email protected]>
Commit-Queue: Alex Deymo <[email protected]>
  • Loading branch information
deymo authored and CQ Bot Account committed Dec 1, 2022
1 parent 4de5042 commit 826e442
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions pw_bluetooth/public/pw_bluetooth/gatt/types.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,27 @@ enum class CharacteristicPropertyBits : uint16_t {
kWritableAuxiliaries = 0x200
};

// Helper operators to allow combining and comparing CharacteristicPropertyBits
// values.
inline constexpr bool operator&(CharacteristicPropertyBits left,
CharacteristicPropertyBits right) {
return static_cast<bool>(
static_cast<std::underlying_type_t<CharacteristicPropertyBits>>(left) &
static_cast<std::underlying_type_t<CharacteristicPropertyBits>>(right));
}

inline constexpr CharacteristicPropertyBits operator|(
CharacteristicPropertyBits left, CharacteristicPropertyBits right) {
return static_cast<CharacteristicPropertyBits>(
static_cast<std::underlying_type_t<CharacteristicPropertyBits>>(left) |
static_cast<std::underlying_type_t<CharacteristicPropertyBits>>(right));
}

inline constexpr CharacteristicPropertyBits& operator|=(
CharacteristicPropertyBits& left, CharacteristicPropertyBits right) {
return left = left | right;
}

// Represents encryption, authentication, and authorization permissions that can
// be assigned to a specific access permission.
struct SecurityRequirements {
Expand Down

0 comments on commit 826e442

Please sign in to comment.