Replace std::stringstream with llvm::raw_svector_ostream (#345)

A few locations were changed to use std::ostringstream.
This commit is contained in:
Tyler Veness
2017-05-15 23:10:40 -07:00
committed by Peter Johnson
parent 7006672b06
commit b433d98c02
39 changed files with 242 additions and 174 deletions

View File

@@ -7,13 +7,14 @@
#include <assert.h>
#include <jni.h>
#include "HAL/cpp/Log.h"
#include "edu_wpi_first_wpilibj_can_CANJNI.h"
#include "FRC_NetworkCommunication/CANSessionMux.h"
#include "HAL/CAN.h"
#include "HAL/cpp/Log.h"
#include "HALUtil.h"
#include "edu_wpi_first_wpilibj_can_CANJNI.h"
#include "llvm/SmallString.h"
#include "llvm/raw_ostream.h"
using namespace frc;
@@ -44,14 +45,15 @@ Java_edu_wpi_first_wpilibj_can_CANJNI_FRCNetCommCANSessionMuxSendMessage(
(uint8_t *)(data ? env->GetDirectBufferAddress(data) : 0);
uint8_t dataSize = (uint8_t)(data ? env->GetDirectBufferCapacity(data) : 0);
CANJNI_LOG(logDEBUG) << "Message ID " << std::hex << messageID;
CANJNI_LOG(logDEBUG) << "Message ID ";
CANJNI_LOG(logDEBUG).write_hex(messageID);
if (logDEBUG <= canJNILogLevel) {
if (dataBuffer) {
std::ostringstream str;
str << std::setfill('0') << std::hex;
llvm::SmallString<128> buf;
llvm::raw_svector_ostream str(buf);
for (int32_t i = 0; i < dataSize; i++) {
str << std::setw(2) << (int)dataBuffer[i] << ' ';
str.write_hex(dataBuffer[i]) << ' ';
}
Log().Get(logDEBUG) << "Data: " << str.str();
@@ -93,13 +95,20 @@ Java_edu_wpi_first_wpilibj_can_CANJNI_FRCNetCommCANSessionMuxReceiveMessage(
FRC_NetworkCommunication_CANSessionMux_receiveMessage(
messageIDPtr, messageIDMask, buffer, &dataSize, timeStampPtr, &status);
CANJNI_LOG(logDEBUG) << "Message ID " << std::hex << *messageIDPtr;
CANJNI_LOG(logDEBUG) << "Message ID ";
CANJNI_LOG(logDEBUG).write_hex(*messageIDPtr);
if (logDEBUG <= canJNILogLevel) {
std::ostringstream str;
str << std::setfill('0') << std::hex;
llvm::SmallString<128> buf;
llvm::raw_svector_ostream str(buf);
for (int32_t i = 0; i < dataSize; i++) {
str << std::setw(2) << (int)buffer[i] << ' ';
// Pad one-digit data with a zero
if (buffer[i] <= 16) {
str << '0';
}
str.write_hex(buffer[i]) << ' ';
}
Log().Get(logDEBUG) << "Data: " << str.str();