Use C++ casting instead of C casting according to Google style guidelines "readability/casting"
This commit is contained in:
parent
2fc9d470dd
commit
5d2e3f33c8
12 changed files with 28 additions and 28 deletions
|
@ -50,7 +50,7 @@ std::wstring TelldusCore::charToWstring(const char *value) {
|
||||||
strcpy(inString, value);
|
strcpy(inString, value);
|
||||||
|
|
||||||
// Create buffer for output
|
// Create buffer for output
|
||||||
char *outString = (char*)new wchar_t[utf8Length+1];
|
char *outString = reinterpret_cast<char*>(new wchar_t[utf8Length+1]);
|
||||||
memset(outString, 0, sizeof(wchar_t)*(utf8Length+1));
|
memset(outString, 0, sizeof(wchar_t)*(utf8Length+1));
|
||||||
|
|
||||||
#ifdef _FREEBSD
|
#ifdef _FREEBSD
|
||||||
|
@ -64,7 +64,7 @@ std::wstring TelldusCore::charToWstring(const char *value) {
|
||||||
iconv(convDesc, &inPointer, &utf8Length, &outPointer, &outbytesLeft);
|
iconv(convDesc, &inPointer, &utf8Length, &outPointer, &outbytesLeft);
|
||||||
iconv_close(convDesc);
|
iconv_close(convDesc);
|
||||||
|
|
||||||
std::wstring retval( (wchar_t *)outString );
|
std::wstring retval( reinterpret_cast<wchar_t *>(outString) );
|
||||||
|
|
||||||
// Cleanup
|
// Cleanup
|
||||||
delete[] inString;
|
delete[] inString;
|
||||||
|
@ -191,7 +191,7 @@ std::string TelldusCore::wideToString(const std::wstring &input) {
|
||||||
size_t outbytesLeft = wideSize+sizeof(char); // NOLINT(runtime/sizeof)
|
size_t outbytesLeft = wideSize+sizeof(char); // NOLINT(runtime/sizeof)
|
||||||
|
|
||||||
// Copy the instring
|
// Copy the instring
|
||||||
char *inString = (char*)new wchar_t[input.length()+1];
|
char *inString = reinterpret_cast<char*>(new wchar_t[input.length()+1]);
|
||||||
memcpy(inString, input.c_str(), wideSize+sizeof(wchar_t));
|
memcpy(inString, input.c_str(), wideSize+sizeof(wchar_t));
|
||||||
|
|
||||||
// Create buffer for output
|
// Create buffer for output
|
||||||
|
@ -233,7 +233,7 @@ std::string TelldusCore::sformatf(const char *format, va_list ap) {
|
||||||
int size = 100; /* Guess we need no more than 100 bytes. */
|
int size = 100; /* Guess we need no more than 100 bytes. */
|
||||||
char *p, *np;
|
char *p, *np;
|
||||||
|
|
||||||
if ((p = (char*)malloc(size)) == NULL) {
|
if ((p = reinterpret_cast<char*>(malloc(size))) == NULL) {
|
||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -255,7 +255,7 @@ std::string TelldusCore::sformatf(const char *format, va_list ap) {
|
||||||
} else { /* glibc 2.0 */
|
} else { /* glibc 2.0 */
|
||||||
size *= 2; /* twice the old size */
|
size *= 2; /* twice the old size */
|
||||||
}
|
}
|
||||||
if ((np = (char *)realloc (p, size)) == NULL) {
|
if ((np = reinterpret_cast<char *>(realloc (p, size))) == NULL) {
|
||||||
free(p);
|
free(p);
|
||||||
return "";
|
return "";
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -58,7 +58,7 @@ inline void debuglog(const int intMessage, const std::string strMessage) {
|
||||||
|
|
||||||
#elif !defined(_MACOSX) && !defined(__FreeBSD__)
|
#elif !defined(_MACOSX) && !defined(__FreeBSD__)
|
||||||
pthread_t thread = pthread_self();
|
pthread_t thread = pthread_self();
|
||||||
printf("[%i] %i - %s\n", (int)thread, intMessage, strMessage.c_str());
|
printf("[%i] %i - %s\n", static_cast<int>(thread), intMessage, strMessage.c_str());
|
||||||
fflush(stdout);
|
fflush(stdout);
|
||||||
#else
|
#else
|
||||||
printf("%i - %s\n", intMessage, strMessage.c_str());
|
printf("%i - %s\n", intMessage, strMessage.c_str());
|
||||||
|
@ -67,10 +67,10 @@ inline void debuglog(const int intMessage, const std::string strMessage) {
|
||||||
|
|
||||||
inline char *wrapStdString( const std::string &string) {
|
inline char *wrapStdString( const std::string &string) {
|
||||||
#ifdef _WINDOWS
|
#ifdef _WINDOWS
|
||||||
return (char *)SysAllocStringByteLen(string.c_str(), (unsigned int)string.size());
|
return reinterpret_cast<char *>(SysAllocStringByteLen(string.c_str(), (unsigned int)string.size()));
|
||||||
#else
|
#else
|
||||||
char *returnVal;
|
char *returnVal;
|
||||||
returnVal = (char *)malloc(sizeof(*returnVal) * (string.size()+1));
|
returnVal = reinterpret_cast<char *>(malloc(sizeof(*returnVal) * (string.size()+1)));
|
||||||
strcpy(returnVal, string.c_str());
|
strcpy(returnVal, string.c_str());
|
||||||
return returnVal;
|
return returnVal;
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -265,7 +265,7 @@ std::wstring ControllerManager::getControllers() const {
|
||||||
|
|
||||||
TelldusCore::Message msg;
|
TelldusCore::Message msg;
|
||||||
|
|
||||||
msg.addArgument((int)d->controllers.size());
|
msg.addArgument(static_cast<int>(d->controllers.size()));
|
||||||
|
|
||||||
for(ControllerMap::iterator it = d->controllers.begin(); it != d->controllers.end(); ++it) {
|
for(ControllerMap::iterator it = d->controllers.begin(); it != d->controllers.end(); ++it) {
|
||||||
msg.addArgument(it->first);
|
msg.addArgument(it->first);
|
||||||
|
|
|
@ -318,7 +318,7 @@ int DeviceManager::setDeviceProtocol(int deviceId, const std::wstring &protocol)
|
||||||
|
|
||||||
int DeviceManager::getNumberOfDevices() {
|
int DeviceManager::getNumberOfDevices() {
|
||||||
TelldusCore::MutexLocker deviceListLocker(&d->lock);
|
TelldusCore::MutexLocker deviceListLocker(&d->lock);
|
||||||
return (int)d->devices.size();
|
return static_cast<int>(d->devices.size());
|
||||||
}
|
}
|
||||||
|
|
||||||
int DeviceManager::addDevice() {
|
int DeviceManager::addDevice() {
|
||||||
|
@ -582,7 +582,7 @@ std::wstring DeviceManager::getSensors() const {
|
||||||
|
|
||||||
TelldusCore::Message msg;
|
TelldusCore::Message msg;
|
||||||
|
|
||||||
msg.addArgument((int)d->sensorList.size());
|
msg.addArgument(static_cast<int>(d->sensorList.size()));
|
||||||
|
|
||||||
for (std::list<Sensor *>::iterator it = d->sensorList.begin(); it != d->sensorList.end(); ++it) {
|
for (std::list<Sensor *>::iterator it = d->sensorList.begin(); it != d->sensorList.end(); ++it) {
|
||||||
TelldusCore::MutexLocker sensorLocker(*it);
|
TelldusCore::MutexLocker sensorLocker(*it);
|
||||||
|
@ -621,7 +621,7 @@ std::wstring DeviceManager::getSensorValue(const std::wstring &protocol, const s
|
||||||
std::string value = sensor->value(dataType);
|
std::string value = sensor->value(dataType);
|
||||||
if (value.length() > 0) {
|
if (value.length() > 0) {
|
||||||
msg.addArgument(TelldusCore::charToWstring(value.c_str()));
|
msg.addArgument(TelldusCore::charToWstring(value.c_str()));
|
||||||
msg.addArgument((int)sensor->timestamp());
|
msg.addArgument(static_cast<int>(sensor->timestamp()));
|
||||||
}
|
}
|
||||||
return msg;
|
return msg;
|
||||||
}
|
}
|
||||||
|
@ -714,7 +714,7 @@ void DeviceManager::setSensorValueAndSignal( const std::string &dataType, int da
|
||||||
eventData->sensorId = sensor->id();
|
eventData->sensorId = sensor->id();
|
||||||
eventData->dataType = dataTypeId;
|
eventData->dataType = dataTypeId;
|
||||||
eventData->value = TelldusCore::charToWstring(sensor->value(dataTypeId).c_str());
|
eventData->value = TelldusCore::charToWstring(sensor->value(dataTypeId).c_str());
|
||||||
eventData->timestamp = (int)timestamp;
|
eventData->timestamp = static_cast<int>(timestamp);
|
||||||
d->deviceUpdateEvent->signal(eventData);
|
d->deviceUpdateEvent->signal(eventData);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -162,16 +162,16 @@ void Log::message(Log::LogLevel logLevel, const char *format, va_list ap) const
|
||||||
|
|
||||||
switch (logLevel) {
|
switch (logLevel) {
|
||||||
case Debug:
|
case Debug:
|
||||||
ReportEvent(d->eventSource, EVENTLOG_SUCCESS, NULL, LOG_DEBUG, NULL, 1, 0, (LPCWSTR*)pInsertStrings, NULL);
|
ReportEvent(d->eventSource, EVENTLOG_SUCCESS, NULL, LOG_DEBUG, NULL, 1, 0, reinterpret_cast<LPCWSTR*>(pInsertStrings), NULL);
|
||||||
break;
|
break;
|
||||||
case Notice:
|
case Notice:
|
||||||
ReportEvent(d->eventSource, EVENTLOG_INFORMATION_TYPE, NULL, LOG_NOTICE, NULL, 1, 0, (LPCWSTR*)pInsertStrings, NULL);
|
ReportEvent(d->eventSource, EVENTLOG_INFORMATION_TYPE, NULL, LOG_NOTICE, NULL, 1, 0, reinterpret_cast<LPCWSTR*>(pInsertStrings), NULL);
|
||||||
break;
|
break;
|
||||||
case Warning:
|
case Warning:
|
||||||
ReportEvent(d->eventSource, EVENTLOG_WARNING_TYPE, NULL, LOG_WARNING, NULL, 1, 0, (LPCWSTR*)pInsertStrings, NULL);
|
ReportEvent(d->eventSource, EVENTLOG_WARNING_TYPE, NULL, LOG_WARNING, NULL, 1, 0, reinterpret_cast<LPCWSTR*>(pInsertStrings), NULL);
|
||||||
break;
|
break;
|
||||||
case Error:
|
case Error:
|
||||||
ReportEvent(d->eventSource, EVENTLOG_ERROR_TYPE, NULL, LOG_ERR, NULL, 1, 0, (LPCWSTR*)pInsertStrings, NULL);
|
ReportEvent(d->eventSource, EVENTLOG_ERROR_TYPE, NULL, LOG_ERR, NULL, 1, 0, reinterpret_cast<LPCWSTR*>(pInsertStrings), NULL);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -38,7 +38,7 @@ std::string ProtocolFineoffset::decodeData(const ControllerMessage &dataMsg) {
|
||||||
retString << "class:sensor;protocol:fineoffset;id:" << id << ";model:";
|
retString << "class:sensor;protocol:fineoffset;id:" << id << ";model:";
|
||||||
|
|
||||||
if (humidity <= 100) {
|
if (humidity <= 100) {
|
||||||
retString << "temperaturehumidity;humidity:" << (int)humidity << ";";
|
retString << "temperaturehumidity;humidity:" << static_cast<int>(humidity) << ";";
|
||||||
} else if (humidity == 0xFF) {
|
} else if (humidity == 0xFF) {
|
||||||
retString << "temperature;";
|
retString << "temperature;";
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -18,7 +18,7 @@ std::string ProtocolMandolyn::decodeData(const ControllerMessage &dataMsg) {
|
||||||
bool parity = value & 0x1;
|
bool parity = value & 0x1;
|
||||||
value >>= 1;
|
value >>= 1;
|
||||||
|
|
||||||
double temp = (double)(value & 0x7FFF) - (double)6400;
|
double temp = static_cast<double>(value & 0x7FFF) - static_cast<double>(6400);
|
||||||
temp = temp/128.0;
|
temp = temp/128.0;
|
||||||
value >>= 15;
|
value >>= 15;
|
||||||
|
|
||||||
|
@ -38,7 +38,7 @@ std::string ProtocolMandolyn::decodeData(const ControllerMessage &dataMsg) {
|
||||||
<< house*10+channel
|
<< house*10+channel
|
||||||
<< ";model:temperaturehumidity;"
|
<< ";model:temperaturehumidity;"
|
||||||
<< "temp:" << std::fixed << std::setprecision(1) << temp
|
<< "temp:" << std::fixed << std::setprecision(1) << temp
|
||||||
<< ";humidity:" << (int)humidity << ";";
|
<< ";humidity:" << static_cast<int>(humidity) << ";";
|
||||||
|
|
||||||
return retString.str();
|
return retString.str();
|
||||||
}
|
}
|
||||||
|
|
|
@ -167,7 +167,7 @@ std::string ProtocolNexa::getStringSelflearningForCode(int intHouse, int intCode
|
||||||
std::string ProtocolNexa::decodeData(const ControllerMessage& dataMsg) {
|
std::string ProtocolNexa::decodeData(const ControllerMessage& dataMsg) {
|
||||||
uint32_t allData = 0;
|
uint32_t allData = 0;
|
||||||
|
|
||||||
sscanf(dataMsg.getParameter("data").c_str(), "%lx", (long*)&allData); // NOLINT(runtime/int)
|
sscanf(dataMsg.getParameter("data").c_str(), "%lx", reinterpret_cast<long*>(&allData)); // NOLINT(runtime/int)
|
||||||
|
|
||||||
if(TelldusCore::comparei(dataMsg.model(), L"selflearning")) {
|
if(TelldusCore::comparei(dataMsg.model(), L"selflearning")) {
|
||||||
// selflearning
|
// selflearning
|
||||||
|
@ -247,7 +247,7 @@ std::string ProtocolNexa::decodeDataCodeSwitch(uint32_t allData) {
|
||||||
}
|
}
|
||||||
|
|
||||||
std::stringstream retString;
|
std::stringstream retString;
|
||||||
retString << "class:command;protocol:arctech;model:codeswitch;house:" << char(house);
|
retString << "class:command;protocol:arctech;model:codeswitch;house:" << static_cast<char>(house);
|
||||||
|
|
||||||
if(method == 6) {
|
if(method == 6) {
|
||||||
retString << ";unit:" << unit << ";method:turnoff;";
|
retString << ";unit:" << unit << ";method:turnoff;";
|
||||||
|
|
|
@ -63,7 +63,7 @@ std::string ProtocolOregon::decodeEA4C(const std::string &data) {
|
||||||
}
|
}
|
||||||
|
|
||||||
std::stringstream retString;
|
std::stringstream retString;
|
||||||
retString << "class:sensor;protocol:oregon;model:EA4C;id:" << (int)address
|
retString << "class:sensor;protocol:oregon;model:EA4C;id:" << static_cast<int>(address)
|
||||||
<< ";temp:" << std::fixed << std::setprecision(1) << temperature << ";";
|
<< ";temp:" << std::fixed << std::setprecision(1) << temperature << ";";
|
||||||
|
|
||||||
return retString.str();
|
return retString.str();
|
||||||
|
@ -114,7 +114,7 @@ std::string ProtocolOregon::decode1A2D(const std::string &data) {
|
||||||
}
|
}
|
||||||
|
|
||||||
std::stringstream retString;
|
std::stringstream retString;
|
||||||
retString << "class:sensor;protocol:oregon;model:1A2D;id:" << (int)address
|
retString << "class:sensor;protocol:oregon;model:1A2D;id:" << static_cast<int>(address)
|
||||||
<< ";temp:" << std::fixed << std::setprecision(1) << temperature << ";";
|
<< ";temp:" << std::fixed << std::setprecision(1) << temperature << ";";
|
||||||
|
|
||||||
return retString.str();
|
return retString.str();
|
||||||
|
|
|
@ -30,7 +30,7 @@ std::string ProtocolWaveman::decodeData(const ControllerMessage& dataMsg) {
|
||||||
unsigned int unit = 0;
|
unsigned int unit = 0;
|
||||||
unsigned int method = 0;
|
unsigned int method = 0;
|
||||||
|
|
||||||
sscanf(dataMsg.getParameter("data").c_str(), "%lx", (long*)&allData); // NOLINT(runtime/int)
|
sscanf(dataMsg.getParameter("data").c_str(), "%lx", reinterpret_cast<long*>(&allData)); // NOLINT(runtime/int)
|
||||||
|
|
||||||
method = allData & 0xF00;
|
method = allData & 0xF00;
|
||||||
method >>= 8;
|
method >>= 8;
|
||||||
|
@ -59,7 +59,7 @@ std::string ProtocolWaveman::decodeData(const ControllerMessage& dataMsg) {
|
||||||
}
|
}
|
||||||
|
|
||||||
std::stringstream retString;
|
std::stringstream retString;
|
||||||
retString << "class:command;protocol:waveman;model:codeswitch;house:" << char(house);
|
retString << "class:command;protocol:waveman;model:codeswitch;house:" << static_cast<char>(house);
|
||||||
|
|
||||||
if(method == 0) {
|
if(method == 0) {
|
||||||
retString << ";unit:" << unit << ";method:turnoff;";
|
retString << ";unit:" << unit << ";method:turnoff;";
|
||||||
|
|
|
@ -167,7 +167,7 @@ std::string ProtocolX10::decodeData(const ControllerMessage& dataMsg) {
|
||||||
|
|
||||||
std::stringstream retString;
|
std::stringstream retString;
|
||||||
retString << "class:command;protocol:x10;model:codeswitch;";
|
retString << "class:command;protocol:x10;model:codeswitch;";
|
||||||
retString << "house:" << (char)('A' + intHouse);
|
retString << "house:" << static_cast<char>('A' + intHouse);
|
||||||
retString << ";unit:" << unit+1;
|
retString << ";unit:" << unit+1;
|
||||||
retString << ";method:";
|
retString << ";method:";
|
||||||
if(method == 0) {
|
if(method == 0) {
|
||||||
|
|
|
@ -201,7 +201,7 @@ int TellStick::send( const std::string &strMessage ) {
|
||||||
if(ret < 0) {
|
if(ret < 0) {
|
||||||
c = false;
|
c = false;
|
||||||
} else if(ret != strMessage.length()) {
|
} else if(ret != strMessage.length()) {
|
||||||
Log::debug("Weird send length? retval %i instead of %d\n", ret, (int)strMessage.length());
|
Log::debug("Weird send length? retval %i instead of %d\n", ret, static_cast<int>(strMessage.length()));
|
||||||
}
|
}
|
||||||
|
|
||||||
delete[] tempMessage;
|
delete[] tempMessage;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue