C/C++ API Reference
Loading...
Searching...
No Matches
capability.h
1// Copyright 2024 The Pigweed Authors
2//
3// Licensed under the Apache License, Version 2.0 (the "License"); you may not
4// use this file except in compliance with the License. You may obtain a copy of
5// the License at
6//
7// https://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
11// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
12// License for the specific language governing permissions and limitations under
13// the License.
14#pragma once
15
16#include <cstdint>
17
18namespace pw::allocator {
19
21
28enum Capability : uint32_t {
29 // clang-format off
30 kCanAllocateArbitraryLayout = 1 << 0,
31 kImplementsGetRequestedLayout = 1 << 1,
32 kImplementsGetUsableLayout = 1 << 2,
33 kImplementsGetAllocatedLayout = 1 << 3,
34 kImplementsGetCapacity = 1 << 4,
35 kImplementsRecognizes = 1 << 5,
36 kSkipsDestroy = 1 << 6,
37 // clang-format on
38};
39
66 public:
67 constexpr Capabilities() : capabilities_(0) {}
68 constexpr Capabilities(uint32_t capabilities) : capabilities_(capabilities) {}
69
70 constexpr bool has(Capability capability) const {
71 return (capabilities_ & capability) == capability;
72 }
73
74 constexpr uint32_t get() const { return capabilities_; }
75
76 private:
77 const uint32_t capabilities_;
78};
79
80inline constexpr bool operator==(const Capabilities& lhs,
81 const Capabilities& rhs) {
82 return lhs.get() == rhs.get();
83}
84
85inline constexpr bool operator!=(const Capabilities& lhs,
86 const Capabilities& rhs) {
87 return lhs.get() != rhs.get();
88}
89
90inline constexpr Capabilities operator|(const Capabilities& lhs,
91 const Capabilities& rhs) {
92 return Capabilities(lhs.get() | rhs.get());
93}
94
95inline constexpr Capabilities operator&(const Capabilities& lhs,
96 const Capabilities& rhs) {
97 return Capabilities(lhs.get() & rhs.get());
98}
99
100inline constexpr Capabilities operator^(const Capabilities& lhs,
101 const Capabilities& rhs) {
102 return Capabilities(lhs.get() ^ rhs.get());
103}
104
106
107} // namespace pw::allocator
Definition: capability.h:65
Capability
Definition: capability.h:28