Use C++ casting instead of C casting according to Google style guidelines "readability/casting"

This commit is contained in:
Micke Prag 2012-06-08 16:28:34 +02:00
parent 2fc9d470dd
commit 5d2e3f33c8
12 changed files with 28 additions and 28 deletions

View file

@ -50,7 +50,7 @@ std::wstring TelldusCore::charToWstring(const char *value) {
strcpy(inString, value);
// 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));
#ifdef _FREEBSD
@ -64,7 +64,7 @@ std::wstring TelldusCore::charToWstring(const char *value) {
iconv(convDesc, &inPointer, &utf8Length, &outPointer, &outbytesLeft);
iconv_close(convDesc);
std::wstring retval( (wchar_t *)outString );
std::wstring retval( reinterpret_cast<wchar_t *>(outString) );
// Cleanup
delete[] inString;
@ -191,7 +191,7 @@ std::string TelldusCore::wideToString(const std::wstring &input) {
size_t outbytesLeft = wideSize+sizeof(char); // NOLINT(runtime/sizeof)
// 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));
// 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. */
char *p, *np;
if ((p = (char*)malloc(size)) == NULL) {
if ((p = reinterpret_cast<char*>(malloc(size))) == NULL) {
return "";
}
@ -255,7 +255,7 @@ std::string TelldusCore::sformatf(const char *format, va_list ap) {
} else { /* glibc 2.0 */
size *= 2; /* twice the old size */
}
if ((np = (char *)realloc (p, size)) == NULL) {
if ((np = reinterpret_cast<char *>(realloc (p, size))) == NULL) {
free(p);
return "";
} else {

View file

@ -58,7 +58,7 @@ inline void debuglog(const int intMessage, const std::string strMessage) {
#elif !defined(_MACOSX) && !defined(__FreeBSD__)
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);
#else
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) {
#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
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());
return returnVal;
#endif

View file

@ -265,7 +265,7 @@ std::wstring ControllerManager::getControllers() const {
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) {
msg.addArgument(it->first);

View file

@ -318,7 +318,7 @@ int DeviceManager::setDeviceProtocol(int deviceId, const std::wstring &protocol)
int DeviceManager::getNumberOfDevices() {
TelldusCore::MutexLocker deviceListLocker(&d->lock);
return (int)d->devices.size();
return static_cast<int>(d->devices.size());
}
int DeviceManager::addDevice() {
@ -582,7 +582,7 @@ std::wstring DeviceManager::getSensors() const {
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) {
TelldusCore::MutexLocker sensorLocker(*it);
@ -621,7 +621,7 @@ std::wstring DeviceManager::getSensorValue(const std::wstring &protocol, const s
std::string value = sensor->value(dataType);
if (value.length() > 0) {
msg.addArgument(TelldusCore::charToWstring(value.c_str()));
msg.addArgument((int)sensor->timestamp());
msg.addArgument(static_cast<int>(sensor->timestamp()));
}
return msg;
}
@ -714,7 +714,7 @@ void DeviceManager::setSensorValueAndSignal( const std::string &dataType, int da
eventData->sensorId = sensor->id();
eventData->dataType = dataTypeId;
eventData->value = TelldusCore::charToWstring(sensor->value(dataTypeId).c_str());
eventData->timestamp = (int)timestamp;
eventData->timestamp = static_cast<int>(timestamp);
d->deviceUpdateEvent->signal(eventData);
}

View file

@ -162,16 +162,16 @@ void Log::message(Log::LogLevel logLevel, const char *format, va_list ap) const
switch (logLevel) {
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;
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;
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;
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;
}
#endif

View file

@ -38,7 +38,7 @@ std::string ProtocolFineoffset::decodeData(const ControllerMessage &dataMsg) {
retString << "class:sensor;protocol:fineoffset;id:" << id << ";model:";
if (humidity <= 100) {
retString << "temperaturehumidity;humidity:" << (int)humidity << ";";
retString << "temperaturehumidity;humidity:" << static_cast<int>(humidity) << ";";
} else if (humidity == 0xFF) {
retString << "temperature;";
} else {

View file

@ -18,7 +18,7 @@ std::string ProtocolMandolyn::decodeData(const ControllerMessage &dataMsg) {
bool parity = value & 0x1;
value >>= 1;
double temp = (double)(value & 0x7FFF) - (double)6400;
double temp = static_cast<double>(value & 0x7FFF) - static_cast<double>(6400);
temp = temp/128.0;
value >>= 15;
@ -38,7 +38,7 @@ std::string ProtocolMandolyn::decodeData(const ControllerMessage &dataMsg) {
<< house*10+channel
<< ";model:temperaturehumidity;"
<< "temp:" << std::fixed << std::setprecision(1) << temp
<< ";humidity:" << (int)humidity << ";";
<< ";humidity:" << static_cast<int>(humidity) << ";";
return retString.str();
}

View file

@ -167,7 +167,7 @@ std::string ProtocolNexa::getStringSelflearningForCode(int intHouse, int intCode
std::string ProtocolNexa::decodeData(const ControllerMessage& dataMsg) {
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")) {
// selflearning
@ -247,7 +247,7 @@ std::string ProtocolNexa::decodeDataCodeSwitch(uint32_t allData) {
}
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) {
retString << ";unit:" << unit << ";method:turnoff;";

View file

@ -63,7 +63,7 @@ std::string ProtocolOregon::decodeEA4C(const std::string &data) {
}
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 << ";";
return retString.str();
@ -114,7 +114,7 @@ std::string ProtocolOregon::decode1A2D(const std::string &data) {
}
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 << ";";
return retString.str();

View file

@ -30,7 +30,7 @@ std::string ProtocolWaveman::decodeData(const ControllerMessage& dataMsg) {
unsigned int unit = 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 >>= 8;
@ -59,7 +59,7 @@ std::string ProtocolWaveman::decodeData(const ControllerMessage& dataMsg) {
}
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) {
retString << ";unit:" << unit << ";method:turnoff;";

View file

@ -167,7 +167,7 @@ std::string ProtocolX10::decodeData(const ControllerMessage& dataMsg) {
std::stringstream retString;
retString << "class:command;protocol:x10;model:codeswitch;";
retString << "house:" << (char)('A' + intHouse);
retString << "house:" << static_cast<char>('A' + intHouse);
retString << ";unit:" << unit+1;
retString << ";method:";
if(method == 0) {

View file

@ -201,7 +201,7 @@ int TellStick::send( const std::string &strMessage ) {
if(ret < 0) {
c = false;
} 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;