Skip to content

Commit e3b0d1e

Browse files
Merge pull request #778 from UWB-Biocomputing/AndrewDevelopment
[ISSUE-732] Enum Classes
2 parents 2915062 + d483a4c commit e3b0d1e

37 files changed

+232
-206
lines changed

CMakeLists.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ cmake_minimum_required(VERSION 3.12)
1212
#
1313
#"YES" / GPU choice only available if CUDA library is installed and the GPU is CUDA capable.
1414
############################################################################################
15-
1615
if(NOT ENABLE_CUDA)
1716
set(ENABLE_CUDA NO)
1817
endif()

Simulator/Connections/Connections.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ Connections::Connections()
3838

3939
// Register loadParameters function with Operation Manager
4040
function<void()> loadParamsFunc = bind(&Connections::loadParameters, this);
41-
opsManager.registerOperation(Operations::op::loadParameters, loadParamsFunc);
41+
opsManager.registerOperation(Operations::loadParameters, loadParamsFunc);
4242

4343
// Register registerGraphProperties as Operations registerGraphProperties
4444
function<void()> regGraphPropsFunc = bind(&Connections::registerGraphProperties, this);

Simulator/Connections/NG911/Connections911.cpp

Lines changed: 25 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -97,11 +97,11 @@ BGSIZE Connections911::getEdgeToClosestResponder(const Call &call, BGSIZE vertex
9797

9898
vertexType requiredType;
9999
if (call.type == "Law")
100-
requiredType = LAW;
100+
requiredType = vertexType::LAW;
101101
else if (call.type == "EMS")
102-
requiredType = EMS;
102+
requiredType = vertexType::EMS;
103103
else if (call.type == "Fire")
104-
requiredType = FIRE;
104+
requiredType = vertexType::FIRE;
105105

106106
// loop over the outgoing edges looking for the responder with the shortest
107107
// Euclidean distance to the call's location.
@@ -145,7 +145,7 @@ bool Connections911::erasePSAP(AllVertices &vertices, Layout &layout)
145145

146146
// Find all psaps
147147
for (int i = 0; i < numVertices; i++) {
148-
if (layout.vertexTypeMap_[i] == PSAP) {
148+
if (layout.vertexTypeMap_[i] == vertexType::PSAP) {
149149
psaps.push_back(i);
150150
}
151151
}
@@ -189,13 +189,14 @@ bool Connections911::erasePSAP(AllVertices &vertices, Layout &layout)
189189
edges_->eraseEdge(destVertex, iEdg);
190190

191191
// Identify all psap-less callers
192-
if (layout.vertexTypeMap_[srcVertex] == CALR) {
192+
if (layout.vertexTypeMap_[srcVertex] == vertexType::CALR) {
193193
callersToReroute.push_back(srcVertex);
194194
}
195195

196196
// Identify all psap-less responders
197-
if (layout.vertexTypeMap_[destVertex] == LAW || layout.vertexTypeMap_[destVertex] == FIRE
198-
|| layout.vertexTypeMap_[destVertex] == EMS) {
197+
if (layout.vertexTypeMap_[destVertex] == vertexType::LAW
198+
|| layout.vertexTypeMap_[destVertex] == vertexType::FIRE
199+
|| layout.vertexTypeMap_[destVertex] == vertexType::EMS) {
199200
respsToReroute.push_back(destVertex);
200201
}
201202
}
@@ -204,7 +205,7 @@ bool Connections911::erasePSAP(AllVertices &vertices, Layout &layout)
204205
if (changesMade) {
205206
// This is here so that we don't delete the vertex if we can't find any edges
206207
verticesErased.push_back(randPSAP);
207-
layout.vertexTypeMap_[randPSAP] = VTYPE_UNDEF;
208+
layout.vertexTypeMap_[randPSAP] = vertexType::VTYPE_UNDEF;
208209
}
209210

210211
// Failsafe
@@ -229,14 +230,14 @@ bool Connections911::erasePSAP(AllVertices &vertices, Layout &layout)
229230
}
230231

231232
// Insert Caller to PSAP edge
232-
BGSIZE iEdg
233-
= edges_->addEdge(CP, srcVertex, closestPSAP, Simulator::getInstance().getDeltaT());
233+
BGSIZE iEdg = edges_->addEdge(edgeType::CP, srcVertex, closestPSAP,
234+
Simulator::getInstance().getDeltaT());
234235

235236
// Record added edge
236237
ChangedEdge addedEdge;
237238
addedEdge.srcV = srcVertex;
238239
addedEdge.destV = closestPSAP;
239-
addedEdge.eType = CP;
240+
addedEdge.eType = edgeType::CP;
240241
edgesAdded.push_back(addedEdge);
241242
}
242243

@@ -257,14 +258,14 @@ bool Connections911::erasePSAP(AllVertices &vertices, Layout &layout)
257258
}
258259

259260
// Insert PSAP to Responder edge
260-
BGSIZE iEdg
261-
= edges_->addEdge(PR, closestPSAP, destVertex, Simulator::getInstance().getDeltaT());
261+
BGSIZE iEdg = edges_->addEdge(edgeType::PR, closestPSAP, destVertex,
262+
Simulator::getInstance().getDeltaT());
262263

263264
// Record added edge
264265
ChangedEdge addedEdge;
265266
addedEdge.srcV = closestPSAP;
266267
addedEdge.destV = destVertex;
267-
addedEdge.eType = PR;
268+
addedEdge.eType = edgeType::PR;
268269
edgesAdded.push_back(addedEdge);
269270
}
270271

@@ -281,8 +282,9 @@ bool Connections911::eraseRESP(AllVertices &vertices, Layout &layout)
281282

282283
// Find all resps
283284
for (int i = 0; i < numVertices; i++) {
284-
if (layout.vertexTypeMap_[i] == LAW || layout.vertexTypeMap_[i] == FIRE
285-
|| layout.vertexTypeMap_[i] == EMS) {
285+
if (layout.vertexTypeMap_[i] == vertexType::LAW
286+
|| layout.vertexTypeMap_[i] == vertexType::FIRE
287+
|| layout.vertexTypeMap_[i] == vertexType::EMS) {
286288
resps.push_back(i);
287289
}
288290
}
@@ -325,7 +327,7 @@ bool Connections911::eraseRESP(AllVertices &vertices, Layout &layout)
325327
if (changesMade) {
326328
// This is here so that we don't delete the vertex if we can't find any edges
327329
verticesErased.push_back(randRESP);
328-
layout.vertexTypeMap_[randRESP] = VTYPE_UNDEF;
330+
layout.vertexTypeMap_[randRESP] = vertexType::VTYPE_UNDEF;
329331
}
330332

331333
return changesMade;
@@ -339,22 +341,22 @@ string Connections911::ChangedEdge::toString()
339341
string type_s;
340342

341343
switch (eType) {
342-
case CP:
344+
case edgeType::CP:
343345
type_s = "CP";
344346
break;
345-
case PR:
347+
case edgeType::PR:
346348
type_s = "PR";
347349
break;
348-
case PP:
350+
case edgeType::PP:
349351
type_s = "PP";
350352
break;
351-
case PC:
353+
case edgeType::PC:
352354
type_s = "PC";
353355
break;
354-
case RP:
356+
case edgeType::RP:
355357
type_s = "RP";
356358
break;
357-
case RC:
359+
case edgeType::RC:
358360
type_s = "RC";
359361
break;
360362
default:

Simulator/Core/FunctionNodes/GenericFunctionNode.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,15 @@
1414
#include <functional>
1515

1616
/// Constructor, Function Signature: void ()
17-
GenericFunctionNode::GenericFunctionNode(const Operations::op &operation,
17+
GenericFunctionNode::GenericFunctionNode(const Operations &operation,
1818
const std::function<void()> &func)
1919
{
2020
operationType_ = operation;
2121
function_ = func;
2222
}
2323

2424
/// Invokes the stored function if the sent operation type matches the operation type the function is stored as.
25-
bool GenericFunctionNode::invokeFunction(const Operations::op &operation) const
25+
bool GenericFunctionNode::invokeFunction(const Operations &operation) const
2626
{
2727
if (operation == operationType_) {
2828
__invoke(function_);

Simulator/Core/FunctionNodes/GenericFunctionNode.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,13 @@ using namespace std;
1717
class GenericFunctionNode : public IFunctionNode {
1818
public:
1919
/// Constructor, Function Signature: void ()
20-
GenericFunctionNode(const Operations::op &operationType, const std::function<void()> &function);
20+
GenericFunctionNode(const Operations &operationType, const std::function<void()> &function);
2121

2222
/// Destructor
2323
~GenericFunctionNode() = default;
2424

2525
/// Invokes the stored function if the sent operation type matches the operation type the function is stored as.
26-
bool invokeFunction(const Operations::op &operation) const override;
26+
bool invokeFunction(const Operations &operation) const override;
2727

2828
private:
2929
std::function<void()> function_; ///< Stored function.

Simulator/Core/FunctionNodes/IFunctionNode.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,9 @@ class IFunctionNode {
1919
virtual ~IFunctionNode() = default;
2020

2121
/// Invokes the stored function if the sent operation type matches the operation type the function is stored as.
22-
virtual bool invokeFunction(const Operations::op &operation) const = 0;
22+
virtual bool invokeFunction(const Operations &operation) const = 0;
2323

2424
protected:
2525
/// The operation type of the stored function.
26-
Operations::op operationType_;
26+
Operations operationType_;
2727
};

Simulator/Core/OperationManager.cpp

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ OperationManager &OperationManager::getInstance()
2727
/// Called by lower level classes constructors on creation to register their operations with their operation type.
2828
/// This method can be overloaded to handle different function signatures.
2929
/// Handles function signature: void ()
30-
void OperationManager::registerOperation(const Operations::op &operation,
30+
void OperationManager::registerOperation(const Operations &operation,
3131
const function<void()> &function)
3232
{
3333
try {
@@ -41,7 +41,7 @@ void OperationManager::registerOperation(const Operations::op &operation,
4141
}
4242

4343
/// Takes in a operation type and invokes all registered functions that are classified as that operation type.
44-
void OperationManager::executeOperation(const Operations::op &operation) const
44+
void OperationManager::executeOperation(const Operations &operation) const
4545
{
4646
LOG4CPLUS_INFO(logger_, "Executing operation " + operationToString(operation));
4747
if (functionList_.size() > 0) {
@@ -52,24 +52,24 @@ void OperationManager::executeOperation(const Operations::op &operation) const
5252
}
5353

5454
/// Takes in the operation enum and returns the enum as a string. Used for debugging purposes.
55-
string OperationManager::operationToString(const Operations::op &operation) const
55+
string OperationManager::operationToString(const Operations &operation) const
5656
{
5757
switch (operation) {
58-
case Operations::op::printParameters:
58+
case Operations::printParameters:
5959
return "printParameters";
60-
case Operations::op::loadParameters:
60+
case Operations::loadParameters:
6161
return "loadParameters";
62-
case Operations::op::serialize:
62+
case Operations::serialize:
6363
return "serialize";
64-
case Operations::op::deserialize:
64+
case Operations::deserialize:
6565
return "deserialize";
66-
case Operations::op::deallocateGPUMemory:
66+
case Operations::deallocateGPUMemory:
6767
return "deallocateGPUMemory";
68-
case Operations::op::restoreToDefault:
68+
case Operations::restoreToDefault:
6969
return "restoreToDefault";
70-
case Operations::op::copyToGPU:
70+
case Operations::copyToGPU:
7171
return "copyToGPU";
72-
case Operations::op::copyFromGPU:
72+
case Operations::copyFromGPU:
7373
return "copyFromGPU";
7474
default:
7575
return "Operation isn't in OperationManager::operationToString()";

Simulator/Core/OperationManager.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,13 +33,13 @@ class OperationManager {
3333
/// Called by lower level classes constructors on creation to register their operations with their operation type.
3434
/// This method can be overloaded to handle different function signatures.
3535
/// Handles function signature: void ()
36-
void registerOperation(const Operations::op &operation, const function<void()> &function);
36+
void registerOperation(const Operations &operation, const function<void()> &function);
3737

3838
/// Takes in a operation type and invokes all registered functions that are classified as that operation type.
39-
void executeOperation(const Operations::op &operation) const;
39+
void executeOperation(const Operations &operation) const;
4040

4141
/// Takes in the operation enum and returns the enum as a string. Used for debugging purposes.
42-
string operationToString(const Operations::op &operation) const;
42+
string operationToString(const Operations &operation) const;
4343

4444
/// Delete copy and move methods to avoid copy instances of the singleton
4545
OperationManager(const OperationManager &operationManager) = delete;

Simulator/Core/Operations.h

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -9,19 +9,16 @@
99

1010
#pragma once
1111

12-
class Operations {
13-
public:
12+
enum class Operations {
1413
/// Available operations the OperationManager can register and execute.
15-
enum op {
16-
printParameters,
17-
loadParameters,
18-
registerGraphProperties,
19-
setup,
20-
serialize,
21-
deserialize,
22-
deallocateGPUMemory, // Make sure deallocate memory isn't called until all GPU memory is copied back.
23-
restoreToDefault, // Not sure what this refers to.
24-
copyToGPU,
25-
copyFromGPU
26-
};
14+
printParameters,
15+
loadParameters,
16+
registerGraphProperties,
17+
setup,
18+
serialize,
19+
deserialize,
20+
deallocateGPUMemory, // Make sure deallocate memory isn't called until all GPU memory is copied back.
21+
restoreToDefault, // Not sure what this refers to.
22+
copyToGPU,
23+
copyFromGPU
2724
};

Simulator/Edges/AllEdges.cpp

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ AllEdges::AllEdges() : totalEdgeCount_(0), maxEdgesPerVertex_(0), countVertices_
1616
// OperationManager. This will register the appropriate overridden method
1717
// for the actual (sub)class of the object being created.
1818
function<void()> loadParametersFunc = std::bind(&AllEdges::loadParameters, this);
19-
OperationManager::getInstance().registerOperation(Operations::op::loadParameters,
19+
OperationManager::getInstance().registerOperation(Operations::loadParameters,
2020
loadParametersFunc);
2121

2222
// Register printParameters function as a printParameters operation in the
@@ -76,7 +76,7 @@ void AllEdges::setupEdges(int numVertices, int maxEdges)
7676

7777
if (maxTotalEdges != 0) {
7878
W_.assign(maxTotalEdges, 0);
79-
type_.assign(maxTotalEdges, ETYPE_UNDEF);
79+
type_.assign(maxTotalEdges, edgeType::ETYPE_UNDEF);
8080
inUse_.assign(maxTotalEdges, false);
8181
edgeCounts_.assign(numVertices, 0);
8282
destVertexIndex_.assign(maxTotalEdges, 0);
@@ -128,25 +128,25 @@ edgeType AllEdges::edgeOrdinalToType(int typeOrdinal)
128128
{
129129
switch (typeOrdinal) {
130130
case 0:
131-
return II;
131+
return edgeType::II;
132132
case 1:
133-
return IE;
133+
return edgeType::IE;
134134
case 2:
135-
return EI;
135+
return edgeType::EI;
136136
case 3:
137-
return EE;
137+
return edgeType::EE;
138138
case 4:
139-
return CP;
139+
return edgeType::CP;
140140
case 5:
141-
return PR;
141+
return edgeType::PR;
142142
case 6:
143-
return PC;
143+
return edgeType::PC;
144144
case 7:
145-
return PP;
145+
return edgeType::PP;
146146
case 8:
147-
return RP;
147+
return edgeType::RP;
148148
default:
149-
return ETYPE_UNDEF;
149+
return edgeType::ETYPE_UNDEF;
150150
}
151151
}
152152

0 commit comments

Comments
 (0)