Removed some std::ostringstream.

To be continued.

git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@5104 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
thunder2 2012-04-15 14:37:44 +00:00
parent 83bd45caa4
commit 470951d664
10 changed files with 136 additions and 191 deletions

View file

@ -1,6 +1,7 @@
#include "extaddrfinder.h"
#include "pqi/pqinetwork.h"
#include "util/rsstring.h"
#ifndef WIN32
#include <netdb.h>
@ -8,7 +9,6 @@
#include <string.h>
#include <string>
#include <sstream>
#include <iostream>
#include <set>
#include <vector>
@ -43,9 +43,9 @@ static std::string scan_ip(const std::string& text)
if(a < 256 && b<256 && c<256 && d<256)
{
std::ostringstream o ;
o << a << "." << b << "." << c << "." << d ;
return o.str();
std::string s ;
rs_sprintf(s, "%u.%u.%u.%u", a, b, c, d) ;
return s;
}
}
return "" ;

View file

@ -30,17 +30,16 @@
#include <unistd.h>
#include "util/rsdir.h"
#include "util/rsstring.h"
#include "pqi/pqinotify.h"
#include "retroshare/rstypes.h"
#include "rsthreads.h"
#include <string>
#include <iostream>
#include <algorithm>
#include <stdio.h>
#include <dirent.h>
#include <openssl/sha.h>
#include <iomanip>
#include <sstream>
#include <fstream>
#include <stdexcept>
@ -665,13 +664,13 @@ bool Sha1CheckSum::operator==(const Sha1CheckSum& s) const
std::string Sha1CheckSum::toStdString() const
{
std::ostringstream tmpout;
std::string tmpout;
for(int i = 0; i < 5; i++)
for(int j = 0; j < 4; j++)
tmpout << std::setw(2) << std::setfill('0') << std::hex << ((fourbytes[i] >> (8*j)) & 0xff ) ;
return tmpout.str() ;
rs_sprintf_append(tmpout, "%02x", ((fourbytes[i] >> (8*j)) & 0xff ));
return tmpout;
}
Sha1CheckSum::Sha1CheckSum(const uint8_t *buf)
@ -767,7 +766,7 @@ bool RsDirUtil::createBackup (const std::string& sFilename, unsigned int nCount)
// search last backup
int nLast;
for (nLast = nCount; nLast >= 1; nLast--) {
std::ostringstream sStream;
std::ostringstream sStream; // please do not use std::ostringstream
sStream << sFilename << nLast << ".bak";
if (GetFileAttributesA (sStream.str ().c_str ()) != -1) {
@ -777,7 +776,7 @@ bool RsDirUtil::createBackup (const std::string& sFilename, unsigned int nCount)
// delete max backup
if (nLast == nCount) {
std::ostringstream sStream;
std::ostringstream sStream; // please do not use std::ostringstream
sStream << sFilename << nCount << ".bak";
if (DeleteFileA (sStream.str ().c_str ()) == FALSE) {
getPqiNotify()->AddSysMessage (0, RS_SYS_WARNING, "File delete error", "Error while deleting file " + sStream.str ());
@ -788,9 +787,9 @@ bool RsDirUtil::createBackup (const std::string& sFilename, unsigned int nCount)
// rename backups
for (int nIndex = nLast; nIndex >= 1; nIndex--) {
std::ostringstream sStream;
std::ostringstream sStream; // please do not use std::ostringstream
sStream << sFilename << nIndex << ".bak";
std::ostringstream sStream1;
std::ostringstream sStream1; // please do not use std::ostringstream
sStream1 << sFilename << nIndex + 1 << ".bak";
if (renameFile (sStream.str (), sStream1.str ()) == false) {
@ -800,7 +799,7 @@ bool RsDirUtil::createBackup (const std::string& sFilename, unsigned int nCount)
}
// copy backup
std::ostringstream sStream;
std::ostringstream sStream; // please do not use std::ostringstream
sStream << sFilename << 1 << ".bak";
if (CopyFileA (sFilename.c_str (), sStream.str ().c_str (), FALSE) == FALSE) {
getPqiNotify()->AddSysMessage (0, RS_SYS_WARNING, "File rename error", "Error while renaming file " + sFilename + " to " + sStream.str ());
@ -1201,7 +1200,7 @@ bool RsDirUtil::getWideFileHash(std::wstring filepath,
SHA1_Final(&sha_buf[0], sha_ctx);
std::ostringstream tmpout;
std::ostringstream tmpout; // please do not use std::ostringstream
for(int i = 0; i < SHA_DIGEST_LENGTH; i++)
{
tmpout << std::setw(2) << std::setfill('0') << std::hex << (unsigned int) (sha_buf[i]);

View file

@ -25,8 +25,7 @@
#include "util/rsnet.h"
#include "util/rsthreads.h"
#include <string.h>
#include <sstream>
#include "util/rsstring.h"
#ifdef WINDOWS_SYS
#else
@ -141,12 +140,8 @@ std::ostream &operator<<(std::ostream &out, const struct sockaddr_in &addr)
std::string rs_inet_ntoa(struct in_addr in)
{
std::ostringstream str;
std::string str;
uint8_t *bytes = (uint8_t *) &(in.s_addr);
str << (int) bytes[0] << ".";
str << (int) bytes[1] << ".";
str << (int) bytes[2] << ".";
str << (int) bytes[3];
return str.str();
rs_sprintf(str, "%u.%u.%u.%u", (int) bytes[0], (int) bytes[1], (int) bytes[2], (int) bytes[3]);
return str;
}

View file

@ -25,34 +25,40 @@
*/
#include "util/rsprint.h"
#include "util/rsstring.h"
#include <iomanip>
#include <sstream>
#include <openssl/sha.h>
#include <sys/time.h>
std::string RsUtil::BinToHex(std::string bin)
#ifdef WINDOWS_SYS
#include <time.h>
#include <sys/timeb.h>
#endif
std::string RsUtil::BinToHex(const std::string &bin)
{
return BinToHex(bin.c_str(), bin.length());
}
std::string RsUtil::BinToHex(const char *arr, const uint32_t len)
{
std::ostringstream out;
std::string out;
for(uint32_t j = 0; j < len; j++)
{
out << std::hex << std::setw(2) << std::setfill('0') << (int32_t) (((const uint8_t *) arr)[j]);
}
return out.str();
for(uint32_t j = 0; j < len; j++)
{
rs_sprintf_append(out, "%02x", (int32_t) (((const uint8_t *) arr)[j]));
}
return out;
}
std::string RsUtil::HashId(std::string id, bool reverse)
std::string RsUtil::HashId(const std::string &id, bool reverse)
{
std::string hash;
std::string tohash;
if (reverse)
{
std::string::reverse_iterator rit;
std::string::const_reverse_iterator rit;
for(rit = id.rbegin(); rit != id.rend(); rit++)
{
tohash += (*rit);
@ -81,43 +87,24 @@ std::string RsUtil::HashId(std::string id, bool reverse)
return hash;
}
#ifdef WINDOWS_SYS
#include <time.h>
#include <sys/timeb.h>
#endif
#include <sys/time.h>
#include <sstream>
#include <iomanip>
static double getCurrentTS();
//static double getCurrentTS()
//{
//#ifndef WINDOWS_SYS
// struct timeval cts_tmp;
// gettimeofday(&cts_tmp, NULL);
// double cts = (cts_tmp.tv_sec) + ((double) cts_tmp.tv_usec) / 1000000.0;
//#else
// struct _timeb timebuf;
// _ftime( &timebuf);
// double cts = (timebuf.time) + ((double) timebuf.millitm) / 1000.0;
//#endif
// return cts;
//}
// Little fn to get current timestamp in an independent manner.
std::string RsUtil::AccurateTimeString()
{
std::ostringstream out;
out << std::setprecision(15) << getCurrentTS();
return out.str();
}
static double getCurrentTS()
{
#ifndef WINDOWS_SYS
struct timeval cts_tmp;
gettimeofday(&cts_tmp, NULL);
double cts = (cts_tmp.tv_sec) + ((double) cts_tmp.tv_usec) / 1000000.0;
#else
struct _timeb timebuf;
_ftime( &timebuf);
double cts = (timebuf.time) + ((double) timebuf.millitm) / 1000.0;
#endif
return cts;
}
//std::string RsUtil::AccurateTimeString()
//{
// std::ostringstream out; // please do not use std::stringstream
// out << std::setprecision(15) << getCurrentTS();
// return out.str();
//}

View file

@ -33,11 +33,11 @@
namespace RsUtil {
std::string BinToHex(std::string bin);
std::string BinToHex(const std::string &bin);
std::string BinToHex(const char *arr, const uint32_t len);
std::string HashId(std::string id, bool reverse = false);
std::string HashId(const std::string &id, bool reverse = false);
std::string AccurateTimeString();
//std::string AccurateTimeString();
}