Skip to content

Commit 5829ad7

Browse files
committed
Refactored most enums to enum class types.
1 parent 78db605 commit 5829ad7

100 files changed

Lines changed: 984 additions & 908 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

src/base/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
set(PR_Src
22
PR_Config.h.in
3+
Enum.h
34
Logger.cpp
45
Logger.h
56
PrettyPrint.h

src/base/Enum.h

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
#pragma once
2+
3+
#include "PR_Config.h"
4+
5+
#include <type_traits>
6+
7+
namespace PR {
8+
template <typename E>
9+
using enable_enum_t = typename std::enable_if<std::is_enum<E>::value,
10+
typename std::underlying_type<E>::type>::type;
11+
12+
template <typename E>
13+
constexpr inline enable_enum_t<E> underlying_value(E e) noexcept
14+
{
15+
return static_cast<typename std::underlying_type<E>::type>(e);
16+
}
17+
18+
template <typename E, typename T>
19+
constexpr inline typename std::enable_if<std::is_enum<E>::value && std::is_integral<T>::value, E>::type
20+
to_enum(T value) noexcept
21+
{
22+
return static_cast<E>(value);
23+
}
24+
25+
template <typename E>
26+
struct PR_LIB_BASE FlagContainer {
27+
using type = typename std::underlying_type<E>::type;
28+
type value = 0;
29+
30+
inline constexpr FlagContainer() = default;
31+
inline FlagContainer(const FlagContainer&) = default;
32+
inline FlagContainer& operator=(const FlagContainer&) = default;
33+
inline FlagContainer(FlagContainer&&) = default;
34+
inline FlagContainer& operator=(FlagContainer&&) = default;
35+
inline constexpr FlagContainer(const E& v)
36+
: value(underlying_value(v))
37+
{
38+
}
39+
template <typename T>
40+
inline constexpr FlagContainer(const T& v, typename std::enable_if<std::is_integral<T>::value>* = 0)
41+
: value(v)
42+
{
43+
}
44+
inline operator type() const { return value; }
45+
inline FlagContainer& operator|=(const FlagContainer& other)
46+
{
47+
value |= other.value;
48+
return *this;
49+
}
50+
inline FlagContainer& operator&=(const FlagContainer& other)
51+
{
52+
value &= other.value;
53+
return *this;
54+
}
55+
};
56+
57+
template <typename E>
58+
inline FlagContainer<E> operator&(const FlagContainer<E>& a, const E& b) { return a.value & PR::underlying_value(b); }
59+
template <typename E>
60+
inline FlagContainer<E> operator&(const E& a, const FlagContainer<E>& b) { return PR::underlying_value(a) & b.value; }
61+
template <typename E>
62+
inline FlagContainer<E> operator|(const FlagContainer<E>& a, const E& b) { return a.value | PR::underlying_value(b); }
63+
template <typename E>
64+
inline FlagContainer<E> operator|(const E& a, const FlagContainer<E>& b) { return PR::underlying_value(a) | b.value; }
65+
66+
} // namespace PR
67+
68+
#define PR_MAKE_FLAGS(single_type, cont_type) \
69+
using cont_type = typename PR::FlagContainer<single_type>; \
70+
inline cont_type operator|(const single_type& a, const single_type& b) { return cont_type(a) | b; }

src/client/TevObserver.cpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -316,23 +316,23 @@ void TevObserver::updateImageProtocol()
316316
PR_OPT_LOOP
317317
for (size_t iy = 0; iy < h; ++iy) {
318318
for (size_t ix = 0; ix < w; ++ix) {
319-
const auto p = Point2i(sx + ix, sy + iy);
320-
const auto fdb = fdb_channel->getFragment(p, 0);
319+
const auto p = Point2i(sx + ix, sy + iy);
320+
const OutputFeedbackFlags fdb = fdb_channel->getFragment(p, 0);
321321

322322
float r = 0;
323-
if (fdb & OF_NaN)
323+
if (fdb & OutputFeedback::NaN)
324324
r = 1.0f;
325-
else if (fdb & OF_Infinite)
325+
else if (fdb & OutputFeedback::Infinite)
326326
r = 0.5f;
327-
else if (fdb & OF_Negative)
327+
else if (fdb & OutputFeedback::Negative)
328328
r = 0.25f;
329329

330330
float g = 0;
331-
if (fdb & OF_MissingMaterial)
331+
if (fdb & OutputFeedback::MissingMaterial)
332332
g = 1.0f;
333333

334334
float b = 0;
335-
if (fdb & OF_MissingEmission)
335+
if (fdb & OutputFeedback::MissingEmission)
336336
b = 1.0f;
337337

338338
mConnection->Data[UPDATE_TILE_SIZE * UPDATE_TILE_SIZE * (0 + delta) + iy * w + ix] = r;

src/core/entity/IEntity.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
namespace PR {
55
IEntity::IEntity(uint32 emission_id, const std::string& name, const Transformf& transform)
66
: ITransformable(name, transform)
7-
, mVisibilityFlags(EVF_All)
7+
, mVisibilityFlags((uint8)EntityVisibility::All)
88
, mEmissionID(emission_id)
99
{
1010
}
@@ -20,10 +20,10 @@ std::string IEntity::dumpInformation() const
2020
<< " <IEntity>: " << std::endl
2121
<< " HasEmission: " << (hasEmission() ? "true" : "false") << std::endl
2222
<< " IsCollidable: " << (isCollidable() ? "true" : "false") << std::endl
23-
<< " IsCameraVisible: " << ((visibilityFlags() & EVF_Camera) ? "true" : "false") << std::endl
24-
<< " IsLightVisible: " << ((visibilityFlags() & EVF_Light) ? "true" : "false") << std::endl
25-
<< " IsBounceVisible: " << ((visibilityFlags() & EVF_Bounce) ? "true" : "false") << std::endl
26-
<< " IsShadowVisible: " << ((visibilityFlags() & EVF_Shadow) ? "true" : "false") << std::endl
23+
<< " IsCameraVisible: " << ((visibilityFlags() & EntityVisibility::Camera) ? "true" : "false") << std::endl
24+
<< " IsLightVisible: " << ((visibilityFlags() & EntityVisibility::Light) ? "true" : "false") << std::endl
25+
<< " IsBounceVisible: " << ((visibilityFlags() & EntityVisibility::Bounce) ? "true" : "false") << std::endl
26+
<< " IsShadowVisible: " << ((visibilityFlags() & EntityVisibility::Shadow) ? "true" : "false") << std::endl
2727
<< " CollisionCost: " << collisionCost() << std::endl
2828
<< " LocalSurfaceArea: " << localSurfaceArea() << std::endl
2929
<< " BBVolume: " << worldBoundingBox().volume() << std::endl;

src/core/entity/IEntity.h

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

3+
#include "Enum.h"
34
#include "ITransformable.h"
45
#include "geometry/BoundingBox.h"
56

67
namespace PR {
7-
enum EntityVisibilityFlag : uint8 {
8-
EVF_Camera = 0x1,
9-
EVF_Light = 0x2,
10-
EVF_Bounce = 0x4,
11-
EVF_Shadow = 0x8,
12-
EVF_All = EVF_Camera | EVF_Light | EVF_Bounce | EVF_Shadow
8+
enum class EntityVisibility : uint8 {
9+
Camera = (uint8)RayFlag::Camera,
10+
Light = (uint8)RayFlag::Light,
11+
Bounce = (uint8)RayFlag::Bounce,
12+
Shadow = (uint8)RayFlag::Shadow,
13+
All = Camera | Light | Bounce | Shadow
1314
};
15+
PR_MAKE_FLAGS(EntityVisibility, EntityVisibilityFlags)
1416

1517
struct GeometryPoint;
1618
struct GeometryRepr;
@@ -54,8 +56,8 @@ class PR_LIB_CORE IEntity : public ITransformable {
5456

5557
bool isRenderable() const override;
5658

57-
inline uint8 visibilityFlags() const;
58-
inline void setVisibilityFlags(uint8 flags);
59+
inline EntityVisibilityFlags visibilityFlags() const;
60+
inline void setVisibilityFlags(EntityVisibilityFlags flags);
5961

6062
// Optional Interface
6163
virtual bool isCollidable() const;
@@ -100,7 +102,7 @@ class PR_LIB_CORE IEntity : public ITransformable {
100102
inline uint32 emissionID() const { return mEmissionID; }
101103

102104
private:
103-
uint8 mVisibilityFlags;
105+
EntityVisibilityFlags mVisibilityFlags;
104106
const uint32 mEmissionID;
105107
};
106108
} // namespace PR

src/core/entity/IEntity.inl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,6 @@ inline BoundingBox IEntity::worldBoundingBox() const
1212
return bb;
1313
}
1414

15-
inline uint8 IEntity::visibilityFlags() const { return mVisibilityFlags; }
16-
inline void IEntity::setVisibilityFlags(uint8 flags) { mVisibilityFlags = flags; }
15+
inline EntityVisibilityFlags IEntity::visibilityFlags() const { return mVisibilityFlags; }
16+
inline void IEntity::setVisibilityFlags(EntityVisibilityFlags flags) { mVisibilityFlags = flags; }
1717
} // namespace PR

src/core/entity/ITransformable.cpp

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
namespace PR {
88
ITransformable::ITransformable(const std::string& name, const Transformf& transform)
99
: mName(name)
10-
, mFlags(0)
1110
, mTransform(transform)
1211
, mInvTransformCache(mTransform.inverse())
1312
, mNormalMatrixCache(mTransform.linear().inverse().transpose())
@@ -34,9 +33,7 @@ std::string ITransformable::dumpInformation() const
3433
stream << "<ITransformable> [" << mName << "]: " << std::endl
3534
<< " Position: " << PR_FMT_MAT(pos) << std::endl
3635
<< " Scale: " << PR_FMT_MAT(scav) << std::endl
37-
<< " Rotation: " << PR_FMT_MAT(quat) << std::endl
38-
<< " Flag&Debug: " << ((mFlags & EF_Debug) != 0 ? "true" : "false") << std::endl
39-
<< " Flag&LocalArea: " << ((mFlags & EF_LocalArea) != 0 ? "true" : "false") << std::endl;
36+
<< " Rotation: " << PR_FMT_MAT(quat) << std::endl;
4037

4138
return stream.str();
4239
}

src/core/entity/ITransformable.h

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,6 @@
55
#include <string>
66

77
namespace PR {
8-
enum EntityFlags {
9-
EF_Debug = 0x1,
10-
EF_LocalArea = 0x2,
11-
};
12-
138
#define ENTITY_CLASS \
149
EIGEN_MAKE_ALIGNED_OPERATOR_NEW
1510

@@ -26,9 +21,6 @@ class PR_LIB_CORE ITransformable {
2621
virtual std::string type() const;
2722
virtual bool isRenderable() const;
2823

29-
inline void setFlags(uint8 f);
30-
inline uint8 flags() const;
31-
3224
inline const Transformf& transform() const;
3325
inline const Transformf& invTransform() const;
3426
inline float volumeScalefactor() const;
@@ -41,7 +33,6 @@ class PR_LIB_CORE ITransformable {
4133

4234
private:
4335
const std::string mName;
44-
uint8 mFlags;
4536

4637
const Transformf mTransform;
4738
const Transformf mInvTransformCache;

src/core/entity/ITransformable.inl

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -15,16 +15,6 @@ inline bool ITransformable::isRenderable() const
1515
return false;
1616
}
1717

18-
inline void ITransformable::setFlags(uint8 f)
19-
{
20-
mFlags = f;
21-
}
22-
23-
inline uint8 ITransformable::flags() const
24-
{
25-
return mFlags;
26-
}
27-
2818
inline const Transformf& ITransformable::transform() const
2919
{
3020
return mTransform;

src/core/geometry/BoundingBox.cpp

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -74,31 +74,31 @@ BoundingBox::FaceSide BoundingBox::getIntersectionSide(const Vector3f& intersect
7474
const Vector3f minDist = (intersection - lowerBound()).cwiseAbs();
7575
const Vector3f maxDist = (intersection - upperBound()).cwiseAbs();
7676

77-
BoundingBox::FaceSide side = FS_Left;
78-
float f = minDist(0);
77+
FaceSide side = FaceSide::Left;
78+
float f = minDist(0);
7979

8080
if (maxDist(0) < f) {
81-
side = FS_Right;
81+
side = FaceSide::Right;
8282
f = maxDist(0);
8383
}
8484

8585
if (minDist(1) < f) {
86-
side = FS_Bottom;
86+
side = FaceSide::Bottom;
8787
f = minDist(1);
8888
}
8989

9090
if (maxDist(1) < f) {
91-
side = FS_Top;
91+
side = FaceSide::Top;
9292
f = maxDist(1);
9393
}
9494

9595
if (minDist(2) < f) {
96-
side = FS_Front;
96+
side = FaceSide::Front;
9797
f = minDist(2);
9898
}
9999

100100
if (maxDist(2) < f) {
101-
side = FS_Back;
101+
side = FaceSide::Back;
102102
}
103103

104104
return side;
@@ -110,27 +110,27 @@ Plane BoundingBox::getFace(FaceSide side) const
110110

111111
switch (side) {
112112
default:
113-
case FS_Front:
113+
case FaceSide::Front:
114114
return Plane(lowerBound(),
115115
Vector3f(diff(0), 0, 0),
116116
Vector3f(0, diff(1), 0));
117-
case FS_Back:
117+
case FaceSide::Back:
118118
return Plane(Vector3f(upperBound()(0), lowerBound()(1), upperBound()(2)),
119119
Vector3f(-diff(0), 0, 0),
120120
Vector3f(0, diff(1), 0));
121-
case FS_Left:
121+
case FaceSide::Left:
122122
return Plane(Vector3f(lowerBound()(0), lowerBound()(1), upperBound()(2)),
123123
Vector3f(0, 0, -diff(2)),
124124
Vector3f(0, diff(1), 0));
125-
case FS_Right:
125+
case FaceSide::Right:
126126
return Plane(Vector3f(upperBound()(0), lowerBound()(1), lowerBound()(2)),
127127
Vector3f(0, 0, diff(2)),
128128
Vector3f(0, diff(1), 0));
129-
case FS_Top:
129+
case FaceSide::Top:
130130
return Plane(Vector3f(lowerBound()(0), upperBound()(1), lowerBound()(2)),
131131
Vector3f(diff(0), 0, 0),
132132
Vector3f(0, 0, diff(2)));
133-
case FS_Bottom:
133+
case FaceSide::Bottom:
134134
return Plane(Vector3f(upperBound()(0), lowerBound()(1), lowerBound()(2)),
135135
Vector3f(-diff(0), 0, 0),
136136
Vector3f(0, 0, diff(2)));

0 commit comments

Comments
 (0)