Base: Replace if else with switch statement
This commit is contained in:
@@ -579,23 +579,19 @@ public:
|
||||
*/
|
||||
bool isActive(Base::LogStyle category) const
|
||||
{
|
||||
if (category == Base::LogStyle::Log) {
|
||||
return bLog;
|
||||
}
|
||||
if (category == Base::LogStyle::Warning) {
|
||||
return bWrn;
|
||||
}
|
||||
if (category == Base::LogStyle::Error) {
|
||||
return bErr;
|
||||
}
|
||||
if (category == Base::LogStyle::Message) {
|
||||
return bMsg;
|
||||
}
|
||||
if (category == Base::LogStyle::Critical) {
|
||||
return bCritical;
|
||||
}
|
||||
if (category == Base::LogStyle::Notification) {
|
||||
return bNotification;
|
||||
switch (category) {
|
||||
case Base::LogStyle::Log:
|
||||
return bLog;
|
||||
case Base::LogStyle::Warning:
|
||||
return bWrn;
|
||||
case Base::LogStyle::Error:
|
||||
return bErr;
|
||||
case Base::LogStyle::Message:
|
||||
return bMsg;
|
||||
case Base::LogStyle::Critical:
|
||||
return bCritical;
|
||||
case Base::LogStyle::Notification:
|
||||
return bNotification;
|
||||
}
|
||||
|
||||
return false;
|
||||
|
||||
@@ -76,32 +76,34 @@ std::string Persistence::encodeAttribute(const std::string& str)
|
||||
{
|
||||
std::string tmp;
|
||||
for (char it : str) {
|
||||
if (it == '<') {
|
||||
tmp += "<";
|
||||
}
|
||||
else if (it == '\"') {
|
||||
tmp += """;
|
||||
}
|
||||
else if (it == '\'') {
|
||||
tmp += "'";
|
||||
}
|
||||
else if (it == '&') {
|
||||
tmp += "&";
|
||||
}
|
||||
else if (it == '>') {
|
||||
tmp += ">";
|
||||
}
|
||||
else if (it == '\r') {
|
||||
tmp += " ";
|
||||
}
|
||||
else if (it == '\n') {
|
||||
tmp += " ";
|
||||
}
|
||||
else if (it == '\t') {
|
||||
tmp += "	";
|
||||
}
|
||||
else {
|
||||
tmp += it;
|
||||
switch (it) {
|
||||
case '<':
|
||||
tmp += "<";
|
||||
break;
|
||||
case '\"':
|
||||
tmp += """;
|
||||
break;
|
||||
case '\'':
|
||||
tmp += "'";
|
||||
break;
|
||||
case '&':
|
||||
tmp += "&";
|
||||
break;
|
||||
case '>':
|
||||
tmp += ">";
|
||||
break;
|
||||
case '\r':
|
||||
tmp += " ";
|
||||
break;
|
||||
case '\n':
|
||||
tmp += " ";
|
||||
break;
|
||||
case '\t':
|
||||
tmp += "	";
|
||||
break;
|
||||
default:
|
||||
tmp += it;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -541,35 +541,31 @@ PyObject* QuantityPy::richCompare(PyObject* v, PyObject* w, int op)
|
||||
const Quantity* u2 = static_cast<QuantityPy*>(w)->getQuantityPtr();
|
||||
|
||||
PyObject* res = nullptr;
|
||||
if (op == Py_NE) {
|
||||
res = (!(*u1 == *u2)) ? Py_True : Py_False;
|
||||
Py_INCREF(res);
|
||||
return res;
|
||||
}
|
||||
else if (op == Py_LT) {
|
||||
res = (*u1 < *u2) ? Py_True : Py_False;
|
||||
Py_INCREF(res);
|
||||
return res;
|
||||
}
|
||||
else if (op == Py_LE) {
|
||||
res = (*u1 < *u2) || (*u1 == *u2) ? Py_True : Py_False;
|
||||
Py_INCREF(res);
|
||||
return res;
|
||||
}
|
||||
else if (op == Py_GT) {
|
||||
res = (!(*u1 < *u2)) && (!(*u1 == *u2)) ? Py_True : Py_False;
|
||||
Py_INCREF(res);
|
||||
return res;
|
||||
}
|
||||
else if (op == Py_GE) {
|
||||
res = (!(*u1 < *u2)) ? Py_True : Py_False;
|
||||
Py_INCREF(res);
|
||||
return res;
|
||||
}
|
||||
else if (op == Py_EQ) {
|
||||
res = (*u1 == *u2) ? Py_True : Py_False;
|
||||
Py_INCREF(res);
|
||||
return res;
|
||||
switch (op) {
|
||||
case Py_NE:
|
||||
res = (!(*u1 == *u2)) ? Py_True : Py_False;
|
||||
Py_INCREF(res);
|
||||
return res;
|
||||
case Py_LT:
|
||||
res = (*u1 < *u2) ? Py_True : Py_False;
|
||||
Py_INCREF(res);
|
||||
return res;
|
||||
case Py_LE:
|
||||
res = (*u1 < *u2) || (*u1 == *u2) ? Py_True : Py_False;
|
||||
Py_INCREF(res);
|
||||
return res;
|
||||
case Py_GT:
|
||||
res = (!(*u1 < *u2)) && (!(*u1 == *u2)) ? Py_True : Py_False;
|
||||
Py_INCREF(res);
|
||||
return res;
|
||||
case Py_GE:
|
||||
res = (!(*u1 < *u2)) ? Py_True : Py_False;
|
||||
Py_INCREF(res);
|
||||
return res;
|
||||
case Py_EQ:
|
||||
res = (*u1 == *u2) ? Py_True : Py_False;
|
||||
Py_INCREF(res);
|
||||
return res;
|
||||
}
|
||||
}
|
||||
else if (PyNumber_Check(v) && PyNumber_Check(w)) {
|
||||
@@ -577,35 +573,31 @@ PyObject* QuantityPy::richCompare(PyObject* v, PyObject* w, int op)
|
||||
double u1 = PyFloat_AsDouble(v);
|
||||
double u2 = PyFloat_AsDouble(w);
|
||||
PyObject* res = nullptr;
|
||||
if (op == Py_NE) {
|
||||
res = (u1 != u2) ? Py_True : Py_False;
|
||||
Py_INCREF(res);
|
||||
return res;
|
||||
}
|
||||
else if (op == Py_LT) {
|
||||
res = (u1 < u2) ? Py_True : Py_False;
|
||||
Py_INCREF(res);
|
||||
return res;
|
||||
}
|
||||
else if (op == Py_LE) {
|
||||
res = (u1 <= u2) ? Py_True : Py_False;
|
||||
Py_INCREF(res);
|
||||
return res;
|
||||
}
|
||||
else if (op == Py_GT) {
|
||||
res = (u1 > u2) ? Py_True : Py_False;
|
||||
Py_INCREF(res);
|
||||
return res;
|
||||
}
|
||||
else if (op == Py_GE) {
|
||||
res = (u1 >= u2) ? Py_True : Py_False;
|
||||
Py_INCREF(res);
|
||||
return res;
|
||||
}
|
||||
else if (op == Py_EQ) {
|
||||
res = (u1 == u2) ? Py_True : Py_False;
|
||||
Py_INCREF(res);
|
||||
return res;
|
||||
switch (op) {
|
||||
case Py_NE:
|
||||
res = (u1 != u2) ? Py_True : Py_False;
|
||||
Py_INCREF(res);
|
||||
return res;
|
||||
case Py_LT:
|
||||
res = (u1 < u2) ? Py_True : Py_False;
|
||||
Py_INCREF(res);
|
||||
return res;
|
||||
case Py_LE:
|
||||
res = (u1 <= u2) ? Py_True : Py_False;
|
||||
Py_INCREF(res);
|
||||
return res;
|
||||
case Py_GT:
|
||||
res = (u1 > u2) ? Py_True : Py_False;
|
||||
Py_INCREF(res);
|
||||
return res;
|
||||
case Py_GE:
|
||||
res = (u1 >= u2) ? Py_True : Py_False;
|
||||
Py_INCREF(res);
|
||||
return res;
|
||||
case Py_EQ:
|
||||
res = (u1 == u2) ? Py_True : Py_False;
|
||||
Py_INCREF(res);
|
||||
return res;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -264,17 +264,19 @@ std::string Base::Tools::escapeEncodeString(const std::string& s)
|
||||
std::string result;
|
||||
size_t len = s.size();
|
||||
for (size_t i = 0; i < len; ++i) {
|
||||
if (s.at(i) == '\\') {
|
||||
result += "\\\\";
|
||||
}
|
||||
else if (s.at(i) == '\"') {
|
||||
result += "\\\"";
|
||||
}
|
||||
else if (s.at(i) == '\'') {
|
||||
result += "\\\'";
|
||||
}
|
||||
else {
|
||||
result += s.at(i);
|
||||
switch (s.at(i)) {
|
||||
case '\\':
|
||||
result += "\\\\";
|
||||
break;
|
||||
case '\"':
|
||||
result += "\\\"";
|
||||
break;
|
||||
case '\'':
|
||||
result += "\\\'";
|
||||
break;
|
||||
default:
|
||||
result += s.at(i);
|
||||
break;
|
||||
}
|
||||
}
|
||||
return result;
|
||||
@@ -305,14 +307,16 @@ std::string Base::Tools::escapeEncodeFilename(const std::string& s)
|
||||
std::string result;
|
||||
size_t len = s.size();
|
||||
for (size_t i = 0; i < len; ++i) {
|
||||
if (s.at(i) == '\"') {
|
||||
result += "\\\"";
|
||||
}
|
||||
else if (s.at(i) == '\'') {
|
||||
result += "\\\'";
|
||||
}
|
||||
else {
|
||||
result += s.at(i);
|
||||
switch (s.at(i)) {
|
||||
case '\"':
|
||||
result += "\\\"";
|
||||
break;
|
||||
case '\'':
|
||||
result += "\\\'";
|
||||
break;
|
||||
default:
|
||||
result += s.at(i);
|
||||
break;
|
||||
}
|
||||
}
|
||||
return result;
|
||||
|
||||
@@ -250,7 +250,7 @@ PyObject* VectorPy::mapping_subscript(PyObject* self, PyObject* item)
|
||||
return PyTuple_New(0);
|
||||
}
|
||||
if (start == 0 && step == 1 && slicelength == sequence_length(self)
|
||||
&& PyObject_TypeCheck(self, &(VectorPy::Type))) {
|
||||
&& PyObject_TypeCheck(self, &(VectorPy::Type))) {
|
||||
Base::Vector3d v = static_cast<VectorPy*>(self)->value();
|
||||
Py::Tuple xyz(3);
|
||||
xyz.setItem(0, Py::Float(v.x));
|
||||
|
||||
Reference in New Issue
Block a user