Skip to content

Commit 5be1f4f

Browse files
feat: apply bitflags enum macro to all bitflags enums
1 parent ec6f07c commit 5be1f4f

File tree

8 files changed

+55
-42
lines changed

8 files changed

+55
-42
lines changed

include/mdlpp/structs/Generic.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
#include <string>
44

55
#include <sourcepp/math/Vector.h>
6+
#include <sourcepp/Macros.h>
67

78
namespace mdlpp {
89

@@ -36,5 +37,6 @@ struct Movement {
3637
sourcepp::math::Vec3f movement;
3738
sourcepp::math::Vec3f relativePosition;
3839
};
40+
SOURCEPP_BITWISE_ENUM(Movement::Flags)
3941

4042
} // namespace mdlpp

include/mdlpp/structs/MDL.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ struct Bone {
4444

4545
//int32_t _unused0[8];
4646
};
47+
SOURCEPP_BITWISE_ENUM(Bone::Flags)
4748

4849
struct BoneController {
4950
int32_t bone;
@@ -111,6 +112,7 @@ struct AnimDesc {
111112
//int32_t zeroFrameIndex;
112113
//float zeroFrameStallTime;
113114
};
115+
SOURCEPP_BITWISE_ENUM(AnimDesc::Flags)
114116
115117
struct SequenceDesc {
116118
enum Flags : int32_t {
@@ -181,6 +183,7 @@ struct SequenceDesc {
181183
182184
//int32_t _unused0[7];
183185
};
186+
SOURCEPP_BITWISE_ENUM(SequenceDesc::Flags)
184187
*/
185188

186189
struct Material {
@@ -197,6 +200,7 @@ struct Material {
197200
//int32_t used; // No idea what this is
198201
//int32_t _unused0[13];
199202
};
203+
SOURCEPP_BITWISE_ENUM(Material::Flags)
200204

201205
struct Mesh {
202206
int32_t material;
@@ -410,5 +414,6 @@ struct MDL {
410414

411415
//int32_t _unused3;
412416
};
417+
SOURCEPP_BITWISE_ENUM(MDL::Flags)
413418

414419
} // namespace mdlpp::MDL

include/mdlpp/structs/VTX.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ struct Strip {
4141
//int32_t numTopologyIndices;
4242
//int32_t topologyOffset;
4343
};
44+
SOURCEPP_BITWISE_ENUM(Strip::Flags)
4445

4546
struct StripGroup {
4647
enum Flags : uint8_t {
@@ -69,6 +70,7 @@ struct StripGroup {
6970
//int32_t numTopologyIndices;
7071
//int32_t topologyOffset;
7172
};
73+
SOURCEPP_BITWISE_ENUM(StripGroup::Flags)
7274

7375
struct Mesh {
7476
enum Flags : uint8_t {
@@ -83,6 +85,7 @@ struct Mesh {
8385

8486
Flags flags;
8587
};
88+
SOURCEPP_BITWISE_ENUM(Mesh::Flags)
8689

8790
struct ModelLOD {
8891
//int32_t meshCount;

include/sourcepp/BitwiseEnumClass.h

Lines changed: 0 additions & 39 deletions
This file was deleted.

include/sourcepp/Macros.h

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,47 @@
11
#pragma once
22

3+
#include <type_traits>
4+
5+
// Helpers
36
#define SOURCEPP_CONCAT_INNER(a, b) a##b
47
#define SOURCEPP_CONCAT(a, b) SOURCEPP_CONCAT_INNER(a, b)
58

69
/// Adds the current line number to the given base
710
#define SOURCEPP_UNIQUE_NAME(base) SOURCEPP_CONCAT(base, __LINE__)
11+
12+
/// Defines bitwise operators for an enum or enum class
13+
#define SOURCEPP_BITWISE_ENUM(Enum) \
14+
inline constexpr Enum operator|(Enum lhs, Enum rhs) { \
15+
return static_cast<Enum>( \
16+
static_cast<std::underlying_type_t<Enum>>(lhs) | \
17+
static_cast<std::underlying_type_t<Enum>>(rhs)); \
18+
} \
19+
inline constexpr Enum operator&(Enum lhs, Enum rhs) { \
20+
return static_cast<Enum>( \
21+
static_cast<std::underlying_type_t<Enum>>(lhs) & \
22+
static_cast<std::underlying_type_t<Enum>>(rhs)); \
23+
} \
24+
inline constexpr Enum operator^(Enum lhs, Enum rhs) { \
25+
return static_cast<Enum>( \
26+
static_cast<std::underlying_type_t<Enum>>(lhs) ^ \
27+
static_cast<std::underlying_type_t<Enum>>(rhs)); \
28+
} \
29+
inline constexpr Enum operator~(Enum e) { \
30+
return static_cast<Enum>( \
31+
~static_cast<std::underlying_type_t<Enum>>(e)); \
32+
} \
33+
inline Enum& operator|=(Enum& lhs, Enum rhs) { \
34+
return lhs = static_cast<Enum>( \
35+
static_cast<std::underlying_type_t<Enum>>(lhs) | \
36+
static_cast<std::underlying_type_t<Enum>>(rhs)); \
37+
} \
38+
inline Enum& operator&=(Enum& lhs, Enum rhs) { \
39+
return lhs = static_cast<Enum>( \
40+
static_cast<std::underlying_type_t<Enum>>(lhs) & \
41+
static_cast<std::underlying_type_t<Enum>>(rhs)); \
42+
} \
43+
inline Enum& operator^=(Enum& lhs, Enum rhs) { \
44+
return lhs = static_cast<Enum>( \
45+
static_cast<std::underlying_type_t<Enum>>(lhs) ^ \
46+
static_cast<std::underlying_type_t<Enum>>(rhs)); \
47+
}

include/vpkpp/Attribute.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#pragma once
22

3-
#include <sourcepp/BitwiseEnumClass.h>
3+
#include <sourcepp/Macros.h>
44

55
namespace vpkpp {
66

@@ -12,6 +12,6 @@ enum class Attribute {
1212
PCK_MD5 = 1 << 3,
1313
VPK_PRELOADED_DATA = 1 << 4,
1414
};
15-
SOURCEPP_SETUP_BITWISE_ENUM_CLASS(Attribute)
15+
SOURCEPP_BITWISE_ENUM(Attribute)
1616

1717
} // namespace vpkpp

include/vtfpp/vtfpp.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212

1313
#include <sourcepp/math/Vector.h>
1414
#include <sourcepp/parser/Binary.h>
15+
#include <sourcepp/Macros.h>
1516

1617
#include "ImageFormats.h"
1718

@@ -74,6 +75,7 @@ struct Resource {
7475
return std::get<std::span<uint32_t>>(this->convertData())[((mipCount - 1 - mip) * frameCount * faceCount + frame * faceCount + face) + 2];
7576
}
7677
};
78+
SOURCEPP_BITWISE_ENUM(Resource::Flags)
7779

7880
class VTF {
7981
public:
@@ -220,5 +222,6 @@ class VTF {
220222
// False for v7.5 and lower (not actually a field in the header, just simplifies the check)
221223
bool hasAuxCompression = false;
222224
};
225+
SOURCEPP_BITWISE_ENUM(VTF::Flags)
223226

224227
} // namespace vtfpp

src/sourcepp/_sourcepp.cmake

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ list(APPEND ${PROJECT_NAME}_HEADERS
1111
"${CMAKE_CURRENT_SOURCE_DIR}/include/sourcepp/math/Vector.h"
1212
"${CMAKE_CURRENT_SOURCE_DIR}/include/sourcepp/parser/Binary.h"
1313
"${CMAKE_CURRENT_SOURCE_DIR}/include/sourcepp/parser/Text.h"
14-
"${CMAKE_CURRENT_SOURCE_DIR}/include/sourcepp/BitwiseEnumClass.h"
1514
"${CMAKE_CURRENT_SOURCE_DIR}/include/sourcepp/FS.h"
1615
"${CMAKE_CURRENT_SOURCE_DIR}/include/sourcepp/Macros.h"
1716
"${CMAKE_CURRENT_SOURCE_DIR}/include/sourcepp/String.h")

0 commit comments

Comments
 (0)