Skip to content

Commit 33b1267

Browse files
added streaming operator<< for enum classes
1 parent 7f5a172 commit 33b1267

File tree

7 files changed

+22
-13
lines changed

7 files changed

+22
-13
lines changed

Simulator/Edges/AllEdges.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ void AllEdges::writeEdge(ostream &output, BGSIZE iEdg) const
116116
output << sourceVertexIndex_[iEdg] << ends;
117117
output << destVertexIndex_[iEdg] << ends;
118118
output << W_[iEdg] << ends;
119-
output << static_cast<int>(type_[iEdg]) << ends;
119+
output << type_[iEdg] << ends;
120120
output << (inUse_[iEdg] == 1 ? "true" : "false") << ends;
121121
}
122122

Simulator/Edges/Neuro/AllDSSynapses_d.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -310,7 +310,7 @@ void AllDSSynapses::printGPUEdgesProps(void *allEdgesDeviceProps) const
310310
cout << "GPU W[" << i << "] = " << WPrint[i];
311311
cout << " GPU sourNeuron: " << sourceNeuronIndexPrint[i];
312312
cout << " GPU desNeuron: " << destNeuronIndexPrint[i];
313-
cout << " GPU type: " << static_cast<int>(typePrint[i]);
313+
cout << " GPU type: " << typePrint[i];
314314
cout << " GPU psr: " << psrPrint[i];
315315
cout << " GPU in_use:" << (inUsePrint[i] == 1 ? "true" : "false");
316316

Simulator/Edges/Neuro/AllDynamicSTDPSynapses_d.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -349,7 +349,7 @@ void AllDynamicSTDPSynapses::printGPUEdgesProps(void *allEdgesDeviceProps) const
349349
cout << "GPU W[" << i << "] = " << WPrint[i];
350350
cout << " GPU sourNeuron: " << sourceNeuronIndexPrint[i];
351351
cout << " GPU desNeuron: " << destNeuronIndexPrint[i];
352-
cout << " GPU type: " << static_cast<int>(typePrint[i]);
352+
cout << " GPU type: " << typePrint[i];
353353
cout << " GPU psr: " << psrPrint[i];
354354
cout << " GPU in_use:" << (inUsePrint[i] == 1 ? "true" : "false");
355355

Simulator/Utils/Global.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ string neuronTypeToString(vertexType t)
6262
case vertexType::EXC:
6363
return "EXC";
6464
default:
65-
cerr << "ERROR->neuronTypeToString() failed, unknown type: " << static_cast<int>(t) << endl;
65+
cerr << "ERROR->neuronTypeToString() failed, unknown type: " << t << endl;
6666
assert(false);
6767
return nullptr; // Must return a value -- this will probably cascade to another failure
6868
}

Simulator/Utils/Global.h

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,11 @@ enum class vertexType {
111111
// UNDEF
112112
VTYPE_UNDEF = 0
113113
};
114+
// Custom streaming operator<< for the enum class vertexType
115+
inline std::ostream& operator<<(std::ostream& os, vertexType vT) {
116+
os << static_cast<int>(vT);
117+
return os;
118+
}
114119

115120
// Edge types.
116121
// NEURO:
@@ -140,7 +145,11 @@ enum class edgeType {
140145
// UNDEF
141146
ETYPE_UNDEF = -1
142147
};
143-
148+
// Custom streaming operator<< for the enum class edgeType
149+
inline std::ostream& operator<<(std::ostream& os, edgeType eT) {
150+
os << static_cast<int>(eT);
151+
return os;
152+
}
144153
// The default membrane capacitance.
145154
#define DEFAULT_Cm (3e-8)
146155
// The default membrane resistance.

Simulator/Utils/InputManager.h

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -267,29 +267,29 @@ template <typename T> class InputManager {
267267
bool getProperty(T &event, string propName, EventMemberPtr &eventMbrPtr,
268268
const boost::property_tree::ptree &pTree)
269269
{
270-
switch (eventMbrPtr.which()) {
270+
switch (static_cast<PropertyType>(eventMbrPtr.which())) {
271271
// variant.which() returns a value between 0 and number of types - 1
272-
case static_cast<int>(PropertyType::INTEGER): {
272+
case PropertyType::INTEGER: {
273273
int T::*propPtr = get<int T::*>(eventMbrPtr);
274274
event.*propPtr = pTree.get<int>(propName);
275275
} break;
276-
case static_cast<int>(PropertyType::LONG): {
276+
case PropertyType::LONG: {
277277
long T::*propPtr = get<long T::*>(eventMbrPtr);
278278
event.*propPtr = pTree.get<long>(propName);
279279
} break;
280-
case static_cast<int>(PropertyType::UINT64): {
280+
case PropertyType::UINT64: {
281281
uint64_t T::*propPtr = get<uint64_t T::*>(eventMbrPtr);
282282
event.*propPtr = pTree.get<uint64_t>(propName);
283283
} break;
284-
case static_cast<int>(PropertyType::FLOAT): {
284+
case PropertyType::FLOAT: {
285285
float T::*propPtr = get<float T::*>(eventMbrPtr);
286286
event.*propPtr = pTree.get<float>(propName);
287287
} break;
288-
case static_cast<int>(PropertyType::DOUBLE): {
288+
case PropertyType::DOUBLE: {
289289
double T::*propPtr = get<double T::*>(eventMbrPtr);
290290
event.*propPtr = pTree.get<double>(propName);
291291
} break;
292-
case static_cast<int>(PropertyType::STRING): {
292+
case PropertyType::STRING: {
293293
string T::*propPtr = get<string T::*>(eventMbrPtr);
294294
event.*propPtr = pTree.get<string>(propName);
295295
} break;

Simulator/Vertices/Neuro/AllIFNeurons.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ void AllIFNeurons::createNeuron(int i, Layout &layout)
142142

143143
default:
144144
LOG4CPLUS_DEBUG(vertexLogger_,
145-
"ERROR: unknown neuron type: " << static_cast<int>(layout.vertexTypeMap_[i]) << "@" << i);
145+
"ERROR: unknown neuron type: " << layout.vertexTypeMap_[i] << "@" << i);
146146
assert(false);
147147
break;
148148
}

0 commit comments

Comments
 (0)