Skip to content

Commit 4bca456

Browse files
authored
Merge pull request #44 from neogeek/hotfix/changed-enums
[hotfix] Changed enum to include a ToString method.
2 parents 2042e4d + 3e47cfa commit 4bca456

File tree

4 files changed

+112
-35
lines changed

4 files changed

+112
-35
lines changed
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,40 @@
11
#pragma once
22

3+
#include <string>
4+
35
namespace RhythmGameUtilities
46
{
57

68
enum Difficulty
79
{
810

11+
// Easy Difficulty
912
Easy,
1013

14+
// Medium Difficulty
1115
Medium,
1216

17+
// Hard Difficulty
1318
Hard,
1419

20+
// Expert Difficulty
1521
Expert
1622

1723
};
1824

25+
std::string ToString(Difficulty difficulty)
26+
{
27+
switch (difficulty)
28+
{
29+
case Easy:
30+
return "Easy";
31+
case Medium:
32+
return "Medium";
33+
case Hard:
34+
return "Hard";
35+
case Expert:
36+
return "Expert";
37+
}
38+
}
39+
1940
} // namespace RhythmGameUtilities

includes/RhythmGameUtilities/Enums/NamedSection.h

Lines changed: 20 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -5,25 +5,29 @@
55
namespace RhythmGameUtilities
66
{
77

8-
namespace NamedSection
8+
enum NamedSection
99
{
10-
typedef std::string Type;
10+
/// Song information
11+
Song,
1112

12-
/// <summary>
13-
/// Song information
14-
/// </summary>
15-
Type Song = "Song";
13+
/// Track information used for syncing with music and notes like BPM
14+
SyncTrack,
1615

17-
/// <summary>
18-
/// Track information used for syncing with music and notes like BPM
19-
/// </summary>
20-
Type SyncTrack = "SyncTrack";
16+
/// Track events
17+
Events
18+
};
2119

22-
/// <summary>
23-
/// Track events
24-
/// </summary>
25-
Type Events = "Events";
26-
27-
}; // namespace NamedSection
20+
std::string ToString(NamedSection namedSection)
21+
{
22+
switch (namedSection)
23+
{
24+
case Song:
25+
return "Song";
26+
case SyncTrack:
27+
return "SyncTrack";
28+
case Events:
29+
return "Events";
30+
}
31+
}
2832

2933
} // namespace RhythmGameUtilities

includes/RhythmGameUtilities/Enums/TypeCode.h

Lines changed: 25 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -5,30 +5,36 @@
55
namespace RhythmGameUtilities
66
{
77

8-
namespace TypeCode
8+
enum TypeCode
99
{
10-
typedef std::string Type;
1110

12-
/// <summary>
13-
/// BPM Marker
14-
/// </summary>
15-
Type BPM = "B";
11+
/// BPM Marker
12+
BPM,
1613

17-
/// <summary>
18-
/// Time Signature Marker
19-
/// </summary>
20-
Type TimeSignature = "TS";
14+
/// Time Signature Marker
15+
TimeSignature,
2116

22-
/// <summary>
23-
/// Note Marker
24-
/// </summary>
25-
Type Note = "N";
17+
/// Note Marker
18+
Note,
2619

27-
/// <summary>
28-
/// Event Marker
29-
/// </summary>
30-
Type Event = "E";
20+
/// Event Marker
21+
Event
3122

32-
} // namespace TypeCode
23+
};
24+
25+
std::string ToString(TypeCode typeCode)
26+
{
27+
switch (typeCode)
28+
{
29+
case BPM:
30+
return "B";
31+
case TimeSignature:
32+
return "TS";
33+
case Note:
34+
return "N";
35+
case Event:
36+
return "E";
37+
}
38+
}
3339

3440
} // namespace RhythmGameUtilities

tests/RhythmGameUtilities/Enum.cpp

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
#include <cassert>
2+
#include <iostream>
3+
4+
#include "RhythmGameUtilities/Enums/Difficulty.h"
5+
#include "RhythmGameUtilities/Enums/NamedSection.h"
6+
#include "RhythmGameUtilities/Enums/TypeCode.h"
7+
8+
using namespace RhythmGameUtilities;
9+
10+
void testDifficulty()
11+
{
12+
assert(ToString(Difficulty::Easy) == "Easy");
13+
assert(ToString(Difficulty::Medium) == "Medium");
14+
assert(ToString(Difficulty::Hard) == "Hard");
15+
assert(ToString(Difficulty::Expert) == "Expert");
16+
17+
std::cout << ".";
18+
}
19+
20+
void testNamedSection()
21+
{
22+
assert(ToString(NamedSection::Song) == "Song");
23+
assert(ToString(NamedSection::SyncTrack) == "SyncTrack");
24+
assert(ToString(NamedSection::Events) == "Events");
25+
26+
std::cout << ".";
27+
}
28+
29+
void testTypeCode()
30+
{
31+
assert(ToString(TypeCode::BPM) == "B");
32+
assert(ToString(TypeCode::TimeSignature) == "TS");
33+
assert(ToString(TypeCode::Note) == "N");
34+
assert(ToString(TypeCode::Event) == "E");
35+
36+
std::cout << ".";
37+
}
38+
39+
int main()
40+
{
41+
testDifficulty();
42+
testNamedSection();
43+
testTypeCode();
44+
45+
return 0;
46+
}

0 commit comments

Comments
 (0)