VIPRA Documentation
Loading...
Searching...
No Matches
pedestrian_types.hpp
1#pragma once
2
3#include <cstdint>
4#include <functional>
5
6#include "vipra/geometry/f3d.hpp"
7#include "vipra/types/size.hpp"
8
9#include "vipra/vipra_behaviors/util/class_types.hpp"
10
11namespace VIPRA::Behaviors {
12
17using typeUID = uint64_t;
18
23class Ptype {
24 DEFAULT_CONSTRUCTIBLE(Ptype)
25 COPYABLE(Ptype)
26 MOVEABLE(Ptype)
27
28 public:
29 typeUID fullType = 0;
30
31 explicit constexpr Ptype(typeUID tid) noexcept : fullType(tid) {}
32
38 [[nodiscard]] inline constexpr auto type_count() const -> VIPRA::size
39 {
40 VIPRA::size count = 0;
41 typeUID check = 1;
42 while ( (check & fullType) != 0U ) {
43 check = check << 1U;
44 ++count;
45 }
46
47 return count;
48 }
49
55 void for_each_type(std::function<void(typeUID)> const& func) const
56 {
57 typeUID type = fullType;
58 typeUID check = 1;
59 while ( check <= type ) {
60 if ( (type & check) != 0U ) {
61 func(check);
62 }
63 check = check << 1U;
64 }
65 }
66
72 [[nodiscard]] inline constexpr auto is_type(typeUID type) const noexcept -> bool
73 {
74 return ((type & fullType) != 0U) && ((~type & fullType) == 0);
75 }
76
82 [[nodiscard]] inline constexpr auto has_type(typeUID type) const noexcept -> bool
83 {
84 return (type & fullType) != 0U;
85 }
86
93 inline constexpr auto operator+(typeUID type) const noexcept -> Ptype
94 {
95 return Ptype{fullType | type};
96 }
97
104 inline constexpr auto operator+=(typeUID type) noexcept -> Ptype&
105 {
106 fullType = (fullType | type);
107 return *this;
108 }
109
116 inline constexpr auto operator+(Ptype type) const noexcept -> Ptype
117 {
118 return Ptype{fullType | type.fullType};
119 }
120
127 inline constexpr auto operator+=(Ptype type) noexcept -> Ptype&
128 {
129 fullType = (fullType | type.fullType);
130 return *this;
131 }
132
139 inline constexpr auto operator-(typeUID type) const noexcept -> Ptype
140 {
141 return Ptype{fullType & ~type};
142 }
143
150 inline constexpr auto operator-=(typeUID type) noexcept -> Ptype&
151 {
152 fullType = (fullType & ~type);
153 return *this;
154 }
155
162 inline constexpr auto operator-(Ptype type) const noexcept -> Ptype
163 {
164 return Ptype{fullType & ~type.fullType};
165 }
166
173 inline constexpr auto operator-=(Ptype type) noexcept -> Ptype&
174 {
175 fullType = (fullType & ~type.fullType);
176 return *this;
177 }
178
186 inline constexpr auto operator==(Ptype type) const noexcept -> bool
187 {
188 return fullType == type.fullType;
189 }
190
198 inline constexpr auto operator!=(Ptype type) const noexcept -> bool
199 {
200 return fullType != type.fullType;
201 }
202};
203} // namespace VIPRA::Behaviors
constexpr auto operator-(Ptype type) const noexcept -> Ptype
Returns the difference of the two ptypes.
Definition pedestrian_types.hpp:162
constexpr auto operator-=(Ptype type) noexcept -> Ptype &
Sets the ptype as the difference of the two types.
Definition pedestrian_types.hpp:173
constexpr auto operator+=(Ptype type) noexcept -> Ptype &
Adds the given ptype.
Definition pedestrian_types.hpp:127
constexpr auto operator+=(typeUID type) noexcept -> Ptype &
Adds a type to the ptype.
Definition pedestrian_types.hpp:104
constexpr auto operator-(typeUID type) const noexcept -> Ptype
Returns a ptype without the given type.
Definition pedestrian_types.hpp:139
constexpr auto operator==(Ptype type) const noexcept -> bool
Checks if two ptypes are the same.
Definition pedestrian_types.hpp:186
constexpr auto operator+(typeUID type) const noexcept -> Ptype
Returns they union of the ptype and the type provided.
Definition pedestrian_types.hpp:93
constexpr auto is_type(typeUID type) const noexcept -> bool
Checks if the Ptype has the given type.
Definition pedestrian_types.hpp:72
constexpr auto has_type(typeUID type) const noexcept -> bool
Checks if the Ptype has the given type.
Definition pedestrian_types.hpp:82
constexpr auto operator+(Ptype type) const noexcept -> Ptype
Returns the union of the two ptypes.
Definition pedestrian_types.hpp:116
constexpr auto operator-=(typeUID type) noexcept -> Ptype &
Removes the type from the ptype.
Definition pedestrian_types.hpp:150
constexpr auto type_count() const -> VIPRA::size
Returns the number of different types, excluding the base type (0)
Definition pedestrian_types.hpp:38
void for_each_type(std::function< void(typeUID)> const &func) const
Loops through each individual type, starting from 1, calling func with the type. example(1,...
Definition pedestrian_types.hpp:55
constexpr auto operator!=(Ptype type) const noexcept -> bool
Checks if two ptypes are different.
Definition pedestrian_types.hpp:198