refactor: renamed functions

to_hex -> toHex
to_string -> toString
Dieser Commit ist enthalten in:
Reinder Feenstra 2020-08-26 18:46:34 +02:00
Ursprung aea4767211
Commit 7c0450f0e3
15 geänderte Dateien mit 45 neuen und 45 gelöschten Zeilen

Datei anzeigen

@ -61,7 +61,7 @@ std::ostream& operator<<(std::ostream& out, const Console::Level& value)
return out; return out;
} }
std::string to_string(const Console::Level& value) std::string toString(const Console::Level& value)
{ {
switch(value) switch(value)
{ {

Datei anzeigen

@ -88,6 +88,6 @@ class Console : public Object, public Table
TableModelPtr getModel() final; TableModelPtr getModel() final;
}; };
std::string to_string(const Console::Level& value); std::string toString(const Console::Level& value);
#endif #endif

Datei anzeigen

@ -66,7 +66,7 @@ std::string ConsoleTableModel::getText(uint32_t column, uint32_t row) const
return s; return s;
} }
case columnLevel: case columnLevel:
return to_string(log.level); return toString(log.level);
case columnId: case columnId:
return log.id; return log.id;

Datei anzeigen

@ -28,7 +28,7 @@
#include "../decoder/decoderchangeflags.hpp" #include "../decoder/decoderchangeflags.hpp"
#include "../protocol/xpressnet/messages.hpp" #include "../protocol/xpressnet/messages.hpp"
#include "../protocol/z21/messages.hpp" #include "../protocol/z21/messages.hpp"
#include "../../utils/to_hex.hpp" #include "../../utils/tohex.hpp"
@ -330,7 +330,7 @@ void RocoZ21::receive()
hwType = "Z21 start (starter set variant from 2016)"; hwType = "Z21 start (starter set variant from 2016)";
break; break;
default: default:
hwType = "0x" + to_hex(reply->hardwareType()); hwType = "0x" + toHex(reply->hardwareType());
break; break;
} }
@ -400,7 +400,7 @@ void RocoZ21::receive()
break; break;
default: default:
EventLoop::call([this, xheader](){ logDebug("unknown xheader 0x" + to_hex(xheader)); }); EventLoop::call([this, xheader](){ logDebug("unknown xheader 0x" + toHex(xheader)); });
break; break;
} }
break; break;
@ -464,7 +464,7 @@ void RocoZ21::receive()
{ {
std::string message = "unknown loconet message: "; std::string message = "unknown loconet message: ";
for(int i = 4; i < cmd->dataLen; i++) for(int i = 4; i < cmd->dataLen; i++)
message += to_hex(reinterpret_cast<const uint8_t*>(cmd)[i]); message += toHex(reinterpret_cast<const uint8_t*>(cmd)[i]);
EventLoop::call([this, message](){ logDebug(id, message); }); EventLoop::call([this, message](){ logDebug(id, message); });
} }
break; break;
@ -476,12 +476,12 @@ void RocoZ21::receive()
default: default:
//if(debugEnabled) //if(debugEnabled)
{ {
std::string log = "unknown message: dataLen=0x" + to_hex(message->dataLen()) + ", header=0x" + to_hex(message->header()); std::string log = "unknown message: dataLen=0x" + toHex(message->dataLen()) + ", header=0x" + toHex(message->header());
if(message->dataLen() > 4) if(message->dataLen() > 4)
{ {
log += ", data="; log += ", data=";
for(int i = sizeof(Z21::Message); i < message->dataLen(); i++) for(int i = sizeof(Z21::Message); i < message->dataLen(); i++)
log += to_hex(reinterpret_cast<const uint8_t*>(message)[i]); log += toHex(reinterpret_cast<const uint8_t*>(message)[i]);
} }
EventLoop::call([this, log](){ logDebug(log); }); EventLoop::call([this, log](){ logDebug(log); });
} }

Datei anzeigen

@ -26,10 +26,10 @@
#include "../commandstation/commandstation.hpp" #include "../commandstation/commandstation.hpp"
#include "../decoder/decoder.hpp" #include "../decoder/decoder.hpp"
#include "../protocol/z21/messages.hpp" #include "../protocol/z21/messages.hpp"
#include "../../utils/to_hex.hpp" #include "../../utils/tohex.hpp"
#include "../../core/attributes.hpp" #include "../../core/attributes.hpp"
static std::string to_string(const boost::asio::ip::udp::endpoint& endpoint) static std::string toString(const boost::asio::ip::udp::endpoint& endpoint)
{ {
std::stringstream ss; std::stringstream ss;
ss << endpoint; ss << endpoint;
@ -146,7 +146,7 @@ void WLANmaus::receive()
if(m_debugLog) if(m_debugLog)
EventLoop::call( EventLoop::call(
[this, log=to_string(m_receiveEndpoint) + " rx: " + Z21::to_string(*message)]() [this, log=toString(m_receiveEndpoint) + " rx: " + Z21::toString(*message)]()
{ {
logDebug(log); logDebug(log);
}); });
@ -389,7 +389,7 @@ void WLANmaus::receive()
[this, broadcastFlags=static_cast<const Z21::LanSetBroadcastFlags*>(message)->broadcastFlags(), endpoint=m_receiveEndpoint]() [this, broadcastFlags=static_cast<const Z21::LanSetBroadcastFlags*>(message)->broadcastFlags(), endpoint=m_receiveEndpoint]()
{ {
if(debugLog) if(debugLog)
logDebug(to_string(endpoint) + " LAN_SET_BROADCASTFLAGS 0x" + to_hex(broadcastFlags)); logDebug(toString(endpoint) + " LAN_SET_BROADCASTFLAGS 0x" + toHex(broadcastFlags));
m_clients[endpoint].broadcastFlags = broadcastFlags; m_clients[endpoint].broadcastFlags = broadcastFlags;
}); });
@ -405,7 +405,7 @@ void WLANmaus::receive()
[this, endpoint=m_receiveEndpoint]() [this, endpoint=m_receiveEndpoint]()
{ {
if(debugLog) if(debugLog)
logDebug(to_string(endpoint) + " LAN_SYSTEMSTATE_GETDATA"); logDebug(toString(endpoint) + " LAN_SYSTEMSTATE_GETDATA");
Z21::LanSystemStateDataChanged response; Z21::LanSystemStateDataChanged response;
@ -428,7 +428,7 @@ void WLANmaus::receive()
[this, endpoint=m_receiveEndpoint]() [this, endpoint=m_receiveEndpoint]()
{ {
if(debugLog) if(debugLog)
logDebug(to_string(endpoint) + " LAN_LOGOFF"); logDebug(toString(endpoint) + " LAN_LOGOFF");
m_clients.erase(endpoint); m_clients.erase(endpoint);
}); });
} }
@ -443,12 +443,12 @@ void WLANmaus::receive()
/*if(unknownMessage && debugLog) /*if(unknownMessage && debugLog)
{ {
std::string log = "unknown message: dataLen=0x" + to_hex(message->dataLen()) + ", header=0x" + to_hex(message->header()); std::string log = "unknown message: dataLen=0x" + toHex(message->dataLen()) + ", header=0x" + toHex(message->header());
if(message->dataLen() > 4) if(message->dataLen() > 4)
{ {
log += ", data="; log += ", data=";
for(int i = sizeof(Z21::Message); i < message->dataLen(); i++) for(int i = sizeof(Z21::Message); i < message->dataLen(); i++)
log += to_hex(reinterpret_cast<const uint8_t*>(message)[i]); log += toHex(reinterpret_cast<const uint8_t*>(message)[i]);
} }
EventLoop::call([this, log](){ logDebug(log); }); EventLoop::call([this, log](){ logDebug(log); });
}*/ }*/
@ -467,7 +467,7 @@ void WLANmaus::receive()
void WLANmaus::sendTo(const Z21::Message& message, const boost::asio::ip::udp::endpoint& endpoint) void WLANmaus::sendTo(const Z21::Message& message, const boost::asio::ip::udp::endpoint& endpoint)
{ {
if(debugLog) if(debugLog)
logDebug(to_string(endpoint) + " tx: " + Z21::to_string(message)); logDebug(toString(endpoint) + " tx: " + Z21::toString(message));
// TODO: add to queue, send async // TODO: add to queue, send async

Datei anzeigen

@ -79,7 +79,7 @@ LocoNet::LocoNet(Object& _parent, const std::string& parentPropertyName, std::fu
bool LocoNet::send(const Message& message) bool LocoNet::send(const Message& message)
{ {
if(m_debugLog) if(m_debugLog)
logDebug("tx: " + to_string(message)); logDebug("tx: " + toString(message));
assert(isValid(message)); assert(isValid(message));
return m_send(message); return m_send(message);
} }
@ -113,7 +113,7 @@ void LocoNet::receive(const Message& message)
assert(isValid(message)); assert(isValid(message));
if(m_debugLog) if(m_debugLog)
EventLoop::call([this, log="rx: " + to_string(message)](){ logDebug(log); }); EventLoop::call([this, log="rx: " + toString(message)](){ logDebug(log); });
switch(message.opCode) switch(message.opCode)
{ {

Datei anzeigen

@ -21,7 +21,7 @@
*/ */
#include "messages.hpp" #include "messages.hpp"
#include "../../../utils/to_hex.hpp" #include "../../../utils/tohex.hpp"
namespace LocoNet { namespace LocoNet {
@ -56,13 +56,13 @@ bool isValid(const Message& message)
return true; return true;
} }
std::string to_string(const Message& message, bool raw) std::string toString(const Message& message, bool raw)
{ {
std::string s; std::string s;
if(std::string_view sv = to_string(message.opCode); !sv.empty()) if(std::string_view sv = toString(message.opCode); !sv.empty())
s = sv; s = sv;
else else
s = to_hex(message.opCode); s = toHex(message.opCode);
switch(message.opCode) switch(message.opCode)
{ {
@ -217,7 +217,7 @@ std::string to_string(const Message& message, bool raw)
{ {
if(i != 0) if(i != 0)
s.append(" "); s.append(" ");
s.append(to_hex(bytes[i])); s.append(toHex(bytes[i]));
} }
s.append("]"); s.append("]");
} }

Datei anzeigen

@ -41,7 +41,7 @@ uint8_t calcChecksum(const Message& msmessageg);
void updateChecksum(Message& message); void updateChecksum(Message& message);
bool isChecksumValid(const Message& message); bool isChecksumValid(const Message& message);
bool isValid(const Message& message); bool isValid(const Message& message);
std::string to_string(const Message& message, bool raw = false); std::string toString(const Message& message, bool raw = false);
constexpr uint8_t SLOT_LOCO_MIN = 1; constexpr uint8_t SLOT_LOCO_MIN = 1;
constexpr uint8_t SLOT_LOCO_MAX = 119; constexpr uint8_t SLOT_LOCO_MAX = 119;

Datei anzeigen

@ -73,7 +73,7 @@ enum OpCode : uint8_t
OPC_WR_SL_DATA = 0xEF, OPC_WR_SL_DATA = 0xEF,
}; };
constexpr std::string_view to_string(OpCode value) constexpr std::string_view toString(OpCode value)
{ {
switch(value) switch(value)
{ {

Datei anzeigen

@ -21,7 +21,7 @@
*/ */
#include "messages.hpp" #include "messages.hpp"
#include "../../../utils/to_hex.hpp" #include "../../../utils/tohex.hpp"
namespace XpressNet { namespace XpressNet {
@ -40,7 +40,7 @@ bool isChecksumValid(const Message& msg)
return calcChecksum(msg) == *(reinterpret_cast<const uint8_t*>(&msg) + msg.dataSize() + 1); return calcChecksum(msg) == *(reinterpret_cast<const uint8_t*>(&msg) + msg.dataSize() + 1);
} }
std::string to_string(const Message& message, bool raw) std::string toString(const Message& message, bool raw)
{ {
std::string s; std::string s;
@ -59,7 +59,7 @@ std::string to_string(const Message& message, bool raw)
{ {
if(i != 0) if(i != 0)
s.append(" "); s.append(" ");
s.append(to_hex(bytes[i])); s.append(toHex(bytes[i]));
} }
s.append("]"); s.append("]");
} }

Datei anzeigen

@ -35,7 +35,7 @@ struct Message;
uint8_t calcChecksum(const Message& msg); uint8_t calcChecksum(const Message& msg);
bool isChecksumValid(const Message& msg); bool isChecksumValid(const Message& msg);
std::string to_string(const Message& message, bool raw = false); std::string toString(const Message& message, bool raw = false);
struct Message struct Message
{ {

Datei anzeigen

@ -106,7 +106,7 @@ void XpressNet::receive(const Message& message)
assert(isChecksumValid(message)); assert(isChecksumValid(message));
if(m_debugLog) if(m_debugLog)
EventLoop::call([this, log="rx: " + to_string(message)](){ logDebug(log); }); EventLoop::call([this, log="rx: " + toString(message)](){ logDebug(log); });
if(m_commandStation) if(m_commandStation)
{ {

Datei anzeigen

@ -22,11 +22,11 @@
#include "messages.hpp" #include "messages.hpp"
#include "../../decoder/decoder.hpp" #include "../../decoder/decoder.hpp"
#include "../../../utils/to_hex.hpp" #include "../../../utils/tohex.hpp"
namespace Z21 { namespace Z21 {
static std::string_view to_string(Header header) static std::string_view toString(Header header)
{ {
switch(header) switch(header)
{ {
@ -44,13 +44,13 @@ static std::string_view to_string(Header header)
return {}; return {};
} }
std::string to_string(const Message& message, bool raw) std::string toString(const Message& message, bool raw)
{ {
std::string s; std::string s;
if(std::string_view sv = to_string(message.header()); !sv.empty()) if(std::string_view sv = toString(message.header()); !sv.empty())
s = sv; s = sv;
else else
s = to_hex(message.header()); s = toHex(message.header());
switch(message.header()) switch(message.header())
{ {
@ -92,14 +92,14 @@ std::string to_string(const Message& message, bool raw)
if(message.dataLen() == sizeof(Z21::LanGetBroadcastFlags)) if(message.dataLen() == sizeof(Z21::LanGetBroadcastFlags))
s = "LAN_GET_BROADCASTFLAGS"; s = "LAN_GET_BROADCASTFLAGS";
//else if(message.dataLen() == sizeof(Z21::LanGetBroadcastFlagsReply)) //else if(message.dataLen() == sizeof(Z21::LanGetBroadcastFlagsReply))
// s = "LAN_GET_BROADCASTFLAGS flags=0x" + to_hex(static_cast<const LanGetBroadcastFlagsReply&>(message).broadcastFlags())); // s = "LAN_GET_BROADCASTFLAGS flags=0x" + toHex(static_cast<const LanGetBroadcastFlagsReply&>(message).broadcastFlags()));
else else
raw = true; raw = true;
break; break;
case Z21::LAN_SET_BROADCASTFLAGS: case Z21::LAN_SET_BROADCASTFLAGS:
if(message.dataLen() == sizeof(Z21::LanSetBroadcastFlags)) if(message.dataLen() == sizeof(Z21::LanSetBroadcastFlags))
s = "LAN_SET_BROADCASTFLAGS flags=0x" + to_hex(static_cast<const LanSetBroadcastFlags&>(message).broadcastFlags()); s = "LAN_SET_BROADCASTFLAGS flags=0x" + toHex(static_cast<const LanSetBroadcastFlags&>(message).broadcastFlags());
else else
raw = true; raw = true;
break; break;
@ -117,7 +117,7 @@ std::string to_string(const Message& message, bool raw)
{ {
if(i != sizeof(Message)) if(i != sizeof(Message))
s.append(" "); s.append(" ");
s.append(to_hex(bytes[i])); s.append(toHex(bytes[i]));
} }
s.append("]"); s.append("]");
} }

Datei anzeigen

@ -37,7 +37,7 @@ namespace Z21 {
struct Message; struct Message;
std::string to_string(const Message& message, bool raw = false); std::string toString(const Message& message, bool raw = false);
enum Header : uint16_t enum Header : uint16_t
{ {

Datei anzeigen

@ -1,5 +1,5 @@
/** /**
* server/src/utils/to_hex.hpp * server/src/utils/tohex.hpp
* *
* This file is part of the traintastic source code. * This file is part of the traintastic source code.
* *
@ -20,13 +20,13 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/ */
#ifndef TRAINTASTIC_SERVER_UTILS_TO_HEX_HPP #ifndef TRAINTASTIC_SERVER_UTILS_TOHEX_HPP
#define TRAINTASTIC_SERVER_UTILS_TO_HEX_HPP #define TRAINTASTIC_SERVER_UTILS_TOHEX_HPP
#include <string> #include <string>
template<typename T> template<typename T>
std::string to_hex(T value, size_t length = sizeof(T) * 2) std::string toHex(T value, size_t length = sizeof(T) * 2)
{ {
static const char* digits = "0123456789ABCDEF"; static const char* digits = "0123456789ABCDEF";
std::string s(length, '0'); std::string s(length, '0');