Gabe Black has uploaded this change for review. (
https://gem5-review.googlesource.com/c/public/gem5/+/39536 )
Change subject: base: Stop "using namespace std".
......................................................................
base: Stop "using namespace std".
As the std namespace expands, it becomes more and more likely that
blanketly importing all its symbols will cause a collision. Also, when
it was imported, the std:: was used or left off arbitrarily, sometimes
inconsistently even in the same function signature.
Change-Id: Ie30cbab154b00c60433908a206c229230d2b109f
---
M src/base/bitunion.test.cc
M src/base/cprintf.cc
M src/base/cprintf.hh
M src/base/fiber.cc
M src/base/hostinfo.cc
M src/base/inet.cc
M src/base/inifile.cc
M src/base/inifile.test.cc
M src/base/loader/symtab.cc
M src/base/match.cc
M src/base/output.cc
M src/base/pollevent.cc
M src/base/refcnt.test.cc
M src/base/remote_gdb.cc
M src/base/socket.cc
M src/base/statistics.cc
M src/base/stats/text.cc
M src/base/str.cc
M src/base/time.cc
M src/base/vnc/vncinput.cc
M src/base/vnc/vncserver.cc
21 files changed, 203 insertions(+), 230 deletions(-)
diff --git a/src/base/bitunion.test.cc b/src/base/bitunion.test.cc
index 77897f5..5a80a57 100644
--- a/src/base/bitunion.test.cc
+++ b/src/base/bitunion.test.cc
@@ -34,9 +34,8 @@
#include "base/bitunion.hh"
#include "base/cprintf.hh"
-using namespace std;
-
-namespace {
+namespace
+{
BitUnion64(SixtyFour)
Bitfield<39, 32> byte5;
diff --git a/src/base/cprintf.cc b/src/base/cprintf.cc
index 572fc40..580a77c 100644
--- a/src/base/cprintf.cc
+++ b/src/base/cprintf.cc
@@ -34,6 +34,7 @@
#include <sstream>
#include "base/compiler.hh"
+#include "base/logging.hh"
namespace cp
{
@@ -79,13 +80,13 @@
break;
case '\n':
- stream << endl;
+ stream << std::endl;
++ptr;
break;
case '\r':
++ptr;
if (*ptr != '\n')
- stream << endl;
+ stream << std::endl;
break;
default:
@@ -106,7 +107,7 @@
int number = 0;
stream.fill(' ');
- stream.flags((ios::fmtflags)0);
+ stream.flags((std::ios::fmtflags)0);
while (!done) {
++ptr;
@@ -134,7 +135,7 @@
case 'p':
fmt.format = Format::Integer;
fmt.base = Format::Hex;
- fmt.alternate_form = true;
+ fmt.alternateForm = true;
done = true;
break;
@@ -262,9 +263,9 @@
// specified a . but not a float, set width
fmt.width = fmt.precision;
// precision requries digits for width, must fill with 0
- fmt.fill_zero = true;
+ fmt.fillZero = true;
} else if ((fmt.format == Format::Floating) && !have_precision
&&
- fmt.fill_zero) {
+ fmt.fillZero) {
// ambiguous case, matching printf
fmt.precision = fmt.width;
}
@@ -290,13 +291,13 @@
break;
case '\n':
- stream << endl;
+ stream << std::endl;
++ptr;
break;
case '\r':
++ptr;
if (*ptr != '\n')
- stream << endl;
+ stream << std::endl;
break;
default:
diff --git a/src/base/cprintf.hh b/src/base/cprintf.hh
index 51531f4..39d9261 100644
--- a/src/base/cprintf.hh
+++ b/src/base/cprintf.hh
@@ -48,7 +48,7 @@
const char *ptr;
bool cont;
- std::ios::fmtflags saved_flags;
+ std::ios::fmtflags savedFlags;
char savedFill;
int savedPrecision;
int savedWidth;
diff --git a/src/base/fiber.cc b/src/base/fiber.cc
index fe1bad0..e414bd2 100644
--- a/src/base/fiber.cc
+++ b/src/base/fiber.cc
@@ -48,8 +48,6 @@
#include "base/logging.hh"
-using namespace std;
-
namespace
{
diff --git a/src/base/hostinfo.cc b/src/base/hostinfo.cc
index be3d46f..e835a10 100644
--- a/src/base/hostinfo.cc
+++ b/src/base/hostinfo.cc
@@ -49,9 +49,7 @@
#include "base/str.hh"
#include "base/types.hh"
-using namespace std;
-
-string
+std::string
__get_hostname()
{
char host[256];
@@ -60,10 +58,10 @@
return host;
}
-string &
+std::string &
hostname()
{
- static string hostname = __get_hostname();
+ static std::string hostname = __get_hostname();
return hostname;
}
diff --git a/src/base/inet.cc b/src/base/inet.cc
index 6be4e26..1d556c5 100644
--- a/src/base/inet.cc
+++ b/src/base/inet.cc
@@ -50,12 +50,12 @@
#include "base/logging.hh"
#include "base/types.hh"
-using namespace std;
-namespace Net {
+namespace Net
+{
EthAddr::EthAddr()
{
- memset(data, 0, ETH_ADDR_LEN);
+ std::memset(data, 0, ETH_ADDR_LEN);
}
EthAddr::EthAddr(const uint8_t ea[ETH_ADDR_LEN])
@@ -97,13 +97,13 @@
int bytes[ETH_ADDR_LEN == 6 ? ETH_ADDR_LEN : -1];
if (sscanf(addr.c_str(), "%x:%x:%x:%x:%x:%x", &bytes[0], &bytes[1],
&bytes[2], &bytes[3], &bytes[4], &bytes[5]) !=
ETH_ADDR_LEN) {
- memset(data, 0xff, ETH_ADDR_LEN);
+ std::memset(data, 0xff, ETH_ADDR_LEN);
return;
}
for (int i = 0; i < ETH_ADDR_LEN; ++i) {
if (bytes[i] & ~0xff) {
- memset(data, 0xff, ETH_ADDR_LEN);
+ std::memset(data, 0xff, ETH_ADDR_LEN);
return;
}
@@ -111,10 +111,10 @@
}
}
-string
+std::string
EthAddr::string() const
{
- stringstream stream;
+ std::stringstream stream;
stream << *this;
return stream.str();
}
@@ -122,21 +122,21 @@
bool
operator==(const EthAddr &left, const EthAddr &right)
{
- return !memcmp(left.bytes(), right.bytes(), ETH_ADDR_LEN);
+ return !std::memcmp(left.bytes(), right.bytes(), ETH_ADDR_LEN);
}
-ostream &
-operator<<(ostream &stream, const EthAddr &ea)
+ std::ostream &
+operator<<(std::ostream &stream, const EthAddr &ea)
{
const uint8_t *a = ea.addr();
ccprintf(stream, "%x:%x:%x:%x:%x:%x", a[0], a[1], a[2], a[3], a[4],
a[5]);
return stream;
}
-string
+std::string
IpAddress::string() const
{
- stringstream stream;
+ std::stringstream stream;
stream << *this;
return stream.str();
}
@@ -147,8 +147,8 @@
return left.ip() == right.ip();
}
-ostream &
-operator<<(ostream &stream, const IpAddress &ia)
+std::ostream &
+operator<<(std::ostream &stream, const IpAddress &ia)
{
uint32_t ip = ia.ip();
ccprintf(stream, "%x.%x.%x.%x",
@@ -157,10 +157,10 @@
return stream;
}
-string
+std::string
IpNetmask::string() const
{
- stringstream stream;
+ std::stringstream stream;
stream << *this;
return stream.str();
}
@@ -172,17 +172,17 @@
(left.netmask() == right.netmask());
}
-ostream &
-operator<<(ostream &stream, const IpNetmask &in)
+std::ostream &
+operator<<(std::ostream &stream, const IpNetmask &in)
{
ccprintf(stream, "%s/%d", (const IpAddress &)in, in.netmask());
return stream;
}
-string
+std::string
IpWithPort::string() const
{
- stringstream stream;
+ std::stringstream stream;
stream << *this;
return stream.str();
}
@@ -193,8 +193,8 @@
return (left.ip() == right.ip()) && (left.port() == right.port());
}
-ostream &
-operator<<(ostream &stream, const IpWithPort &iwp)
+std::ostream &
+operator<<(std::ostream &stream, const IpWithPort &iwp)
{
ccprintf(stream, "%s:%d", (const IpAddress &)iwp, iwp.port());
return stream;
@@ -255,7 +255,7 @@
}
bool
-IpHdr::options(vector<const IpOpt *> &vec) const
+IpHdr::options(std::vector<const IpOpt *> &vec) const
{
vec.clear();
@@ -352,7 +352,7 @@
}
bool
-TcpHdr::options(vector<const TcpOpt *> &vec) const
+TcpHdr::options(std::vector<const TcpOpt *> &vec) const
{
vec.clear();
diff --git a/src/base/inifile.cc b/src/base/inifile.cc
index 1fbebb4..64fff0a 100644
--- a/src/base/inifile.cc
+++ b/src/base/inifile.cc
@@ -36,8 +36,6 @@
#include "base/str.hh"
-using namespace std;
-
IniFile::IniFile()
{}
@@ -53,9 +51,9 @@
}
bool
-IniFile::load(const string &file)
+IniFile::load(const std::string &file)
{
- ifstream f(file.c_str());
+ std::ifstream f(file.c_str());
if (!f.is_open())
return false;
@@ -64,7 +62,7 @@
}
-const string &
+const std::string &
IniFile::Entry::getValue() const
{
referenced = true;
@@ -97,18 +95,18 @@
bool
IniFile::Section::add(const std::string &assignment)
{
- string::size_type offset = assignment.find('=');
- if (offset == string::npos) {
+ std::string::size_type offset = assignment.find('=');
+ if (offset == std::string::npos) {
// no '=' found
- cerr << "Can't parse .ini line " << assignment << endl;
+ std::cerr << "Can't parse .ini line " << assignment << std::endl;
return false;
}
// if "+=" rather than just "=" then append value
bool append = (assignment[offset-1] == '+');
- string entryName = assignment.substr(0, append ? offset-1 : offset);
- string value = assignment.substr(offset + 1);
+ std::string entryName = assignment.substr(0, append ? offset-1 :
offset);
+ std::string value = assignment.substr(offset + 1);
eat_white(entryName);
eat_white(value);
@@ -130,7 +128,7 @@
IniFile::Section *
-IniFile::addSection(const string §ionName)
+IniFile::addSection(const std::string §ionName)
{
SectionTable::iterator i = table.find(sectionName);
@@ -147,7 +145,7 @@
IniFile::Section *
-IniFile::findSection(const string §ionName) const
+IniFile::findSection(const std::string §ionName) const
{
SectionTable::const_iterator i = table.find(sectionName);
@@ -158,15 +156,15 @@
// Take string of the form "<section>:<parameter>=<value>" and add to
// database. Return true if successful, false if parse error.
bool
-IniFile::add(const string &str)
+IniFile::add(const std::string &str)
{
// find ':'
- string::size_type offset = str.find(':');
- if (offset == string::npos) // no ':' found
+ std::string::size_type offset = str.find(':');
+ if (offset == std::string::npos) // no ':' found
return false;
- string sectionName = str.substr(0, offset);
- string rest = str.substr(offset + 1);
+ std::string sectionName = str.substr(0, offset);
+ std::string rest = str.substr(offset + 1);
eat_white(sectionName);
Section *s = addSection(sectionName);
@@ -175,17 +173,17 @@
}
bool
-IniFile::load(istream &f)
+IniFile::load(std::istream &f)
{
Section *section = NULL;
while (!f.eof()) {
- f >> ws; // Eat whitespace
+ f >> std::ws; // Eat whitespace
if (f.eof()) {
break;
}
- string line;
+ std::string line;
getline(f, line);
if (line.size() == 0)
continue;
@@ -194,7 +192,7 @@
int last = line.size() - 1;
if (line[0] == '[' && line[last] == ']') {
- string sectionName = line.substr(1, last - 1);
+ std::string sectionName = line.substr(1, last - 1);
eat_white(sectionName);
section = addSection(sectionName);
continue;
@@ -211,8 +209,8 @@
}
bool
-IniFile::find(const string §ionName, const string &entryName,
- string &value) const
+IniFile::find(const std::string §ionName, const std::string &entryName,
+ std::string &value) const
{
Section *section = findSection(sectionName);
if (section == NULL)
@@ -228,7 +226,8 @@
}
bool
-IniFile::entryExists(const string §ionName, const string &entryName)
const
+IniFile::entryExists(const std::string §ionName,
+ const std::string &entryName) const
{
Section *section = findSection(sectionName);
@@ -239,18 +238,18 @@
}
bool
-IniFile::sectionExists(const string §ionName) const
+IniFile::sectionExists(const std::string §ionName) const
{
return findSection(sectionName) != NULL;
}
bool
-IniFile::Section::printUnreferenced(const string §ionName)
+IniFile::Section::printUnreferenced(const std::string §ionName)
{
bool unref = false;
bool search_unref_entries = false;
- vector<string> unref_ok_entries;
+ std::vector<std::string> unref_ok_entries;
Entry *entry = findEntry("unref_entries_ok");
if (entry != NULL) {
@@ -262,7 +261,7 @@
for (EntryTable::iterator ei = table.begin();
ei != table.end(); ++ei) {
- const string &entryName = ei->first;
+ const std::string &entryName = ei->first;
entry = ei->second;
if (entryName == "unref_section_ok" ||
@@ -279,8 +278,8 @@
continue;
}
- cerr << "Parameter " << sectionName << ":" << entryName
- << " not referenced." << endl;
+ std::cerr << "Parameter " << sectionName << ":" << entryName
+ << " not referenced." << std::endl;
unref = true;
}
}
@@ -290,7 +289,7 @@
void
-IniFile::getSectionNames(vector<string> &list) const
+IniFile::getSectionNames(std::vector<std::string> &list) const
{
for (SectionTable::const_iterator i = table.begin();
i != table.end(); ++i)
@@ -306,13 +305,13 @@
for (SectionTable::iterator i = table.begin();
i != table.end(); ++i) {
- const string §ionName = i->first;
+ const std::string §ionName = i->first;
Section *section = i->second;
if (!section->isReferenced()) {
if (section->findEntry("unref_section_ok") == NULL) {
- cerr << "Section " << sectionName << " not referenced."
- << endl;
+ std::cerr << "Section " << sectionName << " not
referenced."
+ << std::endl;
unref = true;
}
}
@@ -328,12 +327,12 @@
void
-IniFile::Section::dump(const string §ionName)
+IniFile::Section::dump(const std::string §ionName)
{
for (EntryTable::iterator ei = table.begin();
ei != table.end(); ++ei) {
- cout << sectionName << ": " << (*ei).first << " => "
- << (*ei).second->getValue() << "\n";
+ std::cout << sectionName << ": " << (*ei).first << " => "
+ << (*ei).second->getValue() << "\n";
}
}
diff --git a/src/base/inifile.test.cc b/src/base/inifile.test.cc
index 0d1600e..73d7ab7 100644
--- a/src/base/inifile.test.cc
+++ b/src/base/inifile.test.cc
@@ -38,8 +38,6 @@
#include "base/inifile.hh"
-using namespace std;
-
namespace {
std::istringstream iniFile(R"ini_file(
diff --git a/src/base/loader/symtab.cc b/src/base/loader/symtab.cc
index eaada22..2a23661 100644
--- a/src/base/loader/symtab.cc
+++ b/src/base/loader/symtab.cc
@@ -39,8 +39,6 @@
#include "base/types.hh"
#include "sim/serialize.hh"
-using namespace std;
-
namespace Loader
{
@@ -93,10 +91,10 @@
}
bool
-SymbolTable::load(const string &filename)
+SymbolTable::load(const std::string &filename)
{
- string buffer;
- ifstream file(filename.c_str());
+ std::string buffer;
+ std::ifstream file(filename.c_str());
if (!file)
fatal("file error: Can't open symbol table file %s\n", filename);
@@ -106,16 +104,16 @@
if (buffer.empty())
continue;
- string::size_type idx = buffer.find(',');
- if (idx == string::npos)
+ std::string::size_type idx = buffer.find(',');
+ if (idx == std::string::npos)
return false;
- string address = buffer.substr(0, idx);
+ std::string address = buffer.substr(0, idx);
eat_white(address);
if (address.empty())
return false;
- string name = buffer.substr(idx + 1);
+ std::string name = buffer.substr(idx + 1);
eat_white(name);
if (name.empty())
return false;
@@ -133,7 +131,7 @@
}
void
-SymbolTable::serialize(const string &base, CheckpointOut &cp) const
+SymbolTable::serialize(const std::string &base, CheckpointOut &cp) const
{
paramOut(cp, base + ".size", symbols.size());
@@ -147,7 +145,7 @@
}
void
-SymbolTable::unserialize(const string &base, CheckpointIn &cp,
+SymbolTable::unserialize(const std::string &base, CheckpointIn &cp,
Symbol::Binding default_binding)
{
clear();
diff --git a/src/base/match.cc b/src/base/match.cc
index bddadbd..8fff25d 100644
--- a/src/base/match.cc
+++ b/src/base/match.cc
@@ -31,13 +31,11 @@
#include "base/str.hh"
-using namespace std;
-
ObjectMatch::ObjectMatch()
{
}
-ObjectMatch::ObjectMatch(const string &expr)
+ObjectMatch::ObjectMatch(const std::string &expr)
{
setExpression(expr);
}
@@ -49,20 +47,20 @@
}
void
-ObjectMatch::setExpression(const string &expr)
+ObjectMatch::setExpression(const std::string &expr)
{
tokens.resize(1);
tokenize(tokens[0], expr, '.');
}
void
-ObjectMatch::setExpression(const vector<string> &expr)
+ObjectMatch::setExpression(const std::vector<std::string> &expr)
{
if (expr.empty()) {
tokens.resize(0);
} else {
tokens.resize(expr.size());
- for (vector<string>::size_type i = 0; i < expr.size(); ++i)
+ for (std::vector<std::string>::size_type i = 0; i < expr.size();
++i)
tokenize(tokens[i], expr[i], '.');
}
}
@@ -72,15 +70,15 @@
* expression code
*/
bool
-ObjectMatch::domatch(const string &name) const
+ObjectMatch::domatch(const std::string &name) const
{
- vector<string> name_tokens;
+ std::vector<std::string> name_tokens;
tokenize(name_tokens, name, '.');
int ntsize = name_tokens.size();
int num_expr = tokens.size();
for (int i = 0; i < num_expr; ++i) {
- const vector<string> &token = tokens[i];
+ const std::vector<std::string> &token = tokens[i];
int jstop = token.size();
bool match = true;
@@ -88,7 +86,7 @@
if (j >= ntsize)
break;
- const string &var = token[j];
+ const std::string &var = token[j];
if (var != "*" && var != name_tokens[j]) {
match = false;
break;
diff --git a/src/base/output.cc b/src/base/output.cc
index 5703a37..aeafb9d 100644
--- a/src/base/output.cc
+++ b/src/base/output.cc
@@ -56,8 +56,6 @@
#include "base/logging.hh"
-using namespace std;
-
OutputDirectory simout;
@@ -108,8 +106,8 @@
}
}
-OutputStream OutputDirectory::stdout("stdout", &cout);
-OutputStream OutputDirectory::stderr("stderr", &cerr);
+OutputStream OutputDirectory::stdout("stdout", &std::cout);
+OutputStream OutputDirectory::stderr("stderr", &std::cerr);
/**
* @file This file manages creating / deleting output files for the
simulator.
@@ -131,7 +129,7 @@
}
OutputStream *
-OutputDirectory::checkForStdio(const string &name)
+OutputDirectory::checkForStdio(const std::string &name)
{
if (name == "cerr" || name == "stderr")
return &stderr;
@@ -160,9 +158,9 @@
}
void
-OutputDirectory::setDirectory(const string &d)
+OutputDirectory::setDirectory(const std::string &d)
{
- const string old_dir(dir);
+ const std::string old_dir(dir);
dir = d;
@@ -190,7 +188,7 @@
}
-const string &
+const std::string &
OutputDirectory::directory() const
{
if (dir.empty())
@@ -199,21 +197,21 @@
return dir;
}
-string
-OutputDirectory::resolve(const string &name) const
+std::string
+OutputDirectory::resolve(const std::string &name) const
{
return !isAbsolute(name) ? dir + name : name;
}
OutputStream *
-OutputDirectory::create(const string &name, bool binary, bool no_gz)
+OutputDirectory::create(const std::string &name, bool binary, bool no_gz)
{
OutputStream *file = checkForStdio(name);
if (file)
return file;
- const ios_base::openmode mode(
- ios::trunc | (binary ? ios::binary : (ios::openmode)0));
+ const std::ios_base::openmode mode(
+ std::ios::trunc | (binary ? std::ios::binary :
(std::ios::openmode)0));
const bool recreateable(!isAbsolute(name));
return open(name, mode, recreateable, no_gz);
@@ -221,7 +219,7 @@
OutputStream *
OutputDirectory::open(const std::string &name,
- ios_base::openmode mode,
+ std::ios_base::openmode mode,
bool recreateable,
bool no_gz)
{
@@ -234,7 +232,7 @@
mode |= std::ios::out;
os = new OutputFile<gzofstream>(*this, name, mode, recreateable);
} else {
- os = new OutputFile<ofstream>(*this, name, mode, recreateable);
+ os = new OutputFile<std::ofstream>(*this, name, mode,
recreateable);
}
files[name] = os;
@@ -243,7 +241,7 @@
}
OutputStream *
-OutputDirectory::find(const string &name) const
+OutputDirectory::find(const std::string &name) const
{
OutputStream *file = checkForStdio(name);
if (file)
@@ -268,7 +266,7 @@
}
bool
-OutputDirectory::isFile(const string &name) const
+OutputDirectory::isFile(const std::string &name) const
{
// definitely a file if in our data structure
if (find(name) != NULL) return true;
@@ -279,10 +277,10 @@
}
OutputDirectory *
-OutputDirectory::createSubdirectory(const string &name)
+OutputDirectory::createSubdirectory(const std::string &name)
{
- const string new_dir = resolve(name);
- if (new_dir.find(directory()) == string::npos)
+ const std::string new_dir = resolve(name);
+ if (new_dir.find(directory()) == std::string::npos)
fatal("Attempting to create subdirectory not in m5 output dir\n");
OutputDirectory *dir(new OutputDirectory(new_dir));
@@ -292,11 +290,11 @@
}
void
-OutputDirectory::remove(const string &name, bool recursive)
+OutputDirectory::remove(const std::string &name, bool recursive)
{
- const string fname = resolve(name);
+ const std::string fname = resolve(name);
- if (fname.find(directory()) == string::npos)
+ if (fname.find(directory()) == std::string::npos)
fatal("Attempting to remove file/dir not in output dir\n");
if (isFile(fname)) {
diff --git a/src/base/pollevent.cc b/src/base/pollevent.cc
index 2b63c6b..7691ba6 100644
--- a/src/base/pollevent.cc
+++ b/src/base/pollevent.cc
@@ -50,8 +50,6 @@
#include "sim/eventq.hh"
#include "sim/serialize.hh"
-using namespace std;
-
PollQueue pollQueue;
/////////////////////////////////////////////////////
diff --git a/src/base/refcnt.test.cc b/src/base/refcnt.test.cc
index a477e4b..aa9ac6f 100644
--- a/src/base/refcnt.test.cc
+++ b/src/base/refcnt.test.cc
@@ -35,16 +35,16 @@
#include "base/refcnt.hh"
-using namespace std;
-
-namespace {
+namespace
+{
class TestRC;
-typedef list<TestRC *> LiveList;
+typedef std::list<TestRC *> LiveList;
LiveList liveList;
int
-liveListSize(){
+liveListSize()
+{
return liveList.size();
}
diff --git a/src/base/remote_gdb.cc b/src/base/remote_gdb.cc
index 0660827..5b5097c 100644
--- a/src/base/remote_gdb.cc
+++ b/src/base/remote_gdb.cc
@@ -151,7 +151,6 @@
#include "sim/full_system.hh"
#include "sim/system.hh"
-using namespace std;
using namespace TheISA;
static const char GDBStart = '$';
@@ -159,7 +158,7 @@
static const char GDBGoodP = '+';
static const char GDBBadP = '-';
-vector<BaseRemoteGDB *> debuggers;
+std::vector<BaseRemoteGDB *> debuggers;
class HardBreakpoint : public PCEvent
{
@@ -189,7 +188,8 @@
}
};
-namespace {
+namespace
+{
// Exception to throw when the connection to the client is broken.
struct BadClient
@@ -202,7 +202,7 @@
// Exception to throw when an error needs to be reported to the client.
struct CmdError
{
- string error;
+ std::string error;
CmdError(std::string _error) : error(_error)
{}
};
@@ -328,7 +328,7 @@
delete dataEvent;
}
-string
+std::string
BaseRemoteGDB::name()
{
return sys->name() + ".remote_gdb";
@@ -350,7 +350,7 @@
connectEvent = new ConnectEvent(this, listener.getfd(), POLLIN);
pollQueue.schedule(connectEvent);
- ccprintf(cerr, "%d: %s: listening for remote gdb on port %d\n",
+ ccprintf(std::cerr, "%d: %s: listening for remote gdb on port %d\n",
curTick(), name(), _port);
}
@@ -940,8 +940,8 @@
bool
BaseRemoteGDB::cmd_query_var(GdbCommand::Context &ctx)
{
- string s(ctx.data, ctx.len - 1);
- string xfer_read_prefix = "Xfer:features:read:";
+ std::string s(ctx.data, ctx.len - 1);
+ std::string xfer_read_prefix = "Xfer:features:read:";
if (s.rfind("Supported:", 0) == 0) {
std::ostringstream oss;
// This reply field mandatory. We can receive arbitrarily
diff --git a/src/base/socket.cc b/src/base/socket.cc
index fce54aa..abe5ddf 100644
--- a/src/base/socket.cc
+++ b/src/base/socket.cc
@@ -43,8 +43,6 @@
#include "base/types.hh"
#include "sim/byteswap.hh"
-using namespace std;
-
bool ListenSocket::listeningDisabled = false;
bool ListenSocket::anyListening = false;
@@ -121,7 +119,7 @@
htobe<in_addr_t>(bindToLoopback ? INADDR_LOOPBACK : INADDR_ANY);
sockaddr.sin_port = htons(port);
// finally clear sin_zero
- memset(&sockaddr.sin_zero, 0, sizeof(sockaddr.sin_zero));
+ std::memset(&sockaddr.sin_zero, 0, sizeof(sockaddr.sin_zero));
int ret = ::bind(fd, (struct sockaddr *)&sockaddr, sizeof (sockaddr));
if (ret != 0) {
if (ret == -1 && errno != EADDRINUSE)
diff --git a/src/base/statistics.cc b/src/base/statistics.cc
index 5c77ee0..16d34f0 100644
--- a/src/base/statistics.cc
+++ b/src/base/statistics.cc
@@ -56,17 +56,16 @@
#include "base/trace.hh"
#include "sim/root.hh"
-using namespace std;
-
-namespace Stats {
+namespace Stats
+{
std::string Info::separatorString = "::";
// We wrap these in a function to make sure they're built in time.
-list<Info *> &
+std::list<Info *> &
statsList()
{
- static list<Info *> the_list;
+ static std::list<Info *> the_list;
return the_list;
}
@@ -94,9 +93,9 @@
statsList().push_back(info);
#ifndef NDEBUG
- pair<MapType::iterator, bool> result =
+ std::pair<MapType::iterator, bool> result =
#endif
- statsMap().insert(make_pair(this, info));
+ statsMap().insert(std::make_pair(this, info));
assert(result.second && "this should never fail");
assert(statsMap().find(this) != statsMap().end());
}
@@ -169,19 +168,19 @@
}
bool
-validateStatName(const string &name)
+validateStatName(const std::string &name)
{
if (name.empty())
return false;
- vector<string> vec;
+ std::vector<std::string> vec;
tokenize(vec, name, '.');
- vector<string>::const_iterator item = vec.begin();
+ std::vector<std::string>::const_iterator item = vec.begin();
while (item != vec.end()) {
if (item->empty())
return false;
- string::const_iterator c = item->begin();
+ std::string::const_iterator c = item->begin();
// The first character is different
if (!isalpha(*c) && *c != '_')
@@ -200,13 +199,13 @@
}
void
-Info::setName(const string &name)
+Info::setName(const std::string &name)
{
setName(nullptr, name);
}
void
-Info::setName(const Group *parent, const string &name)
+Info::setName(const Group *parent, const std::string &name)
{
if (!validateStatName(name))
panic("invalid stat name '%s'", name);
@@ -229,16 +228,16 @@
bool
Info::less(Info *stat1, Info *stat2)
{
- const string &name1 = stat1->name;
- const string &name2 = stat2->name;
+ const std::string &name1 = stat1->name;
+ const std::string &name2 = stat2->name;
- vector<string> v1;
- vector<string> v2;
+ std::vector<std::string> v1;
+ std::vector<std::string> v2;
tokenize(v1, name1, '.');
tokenize(v2, name2, '.');
- size_type last = min(v1.size(), v2.size()) - 1;
+ size_type last = std::min(v1.size(), v2.size()) - 1;
for (off_type i = 0; i < last; ++i)
if (v1[i] != v2[i])
return v1[i] < v2[i];
@@ -502,7 +501,7 @@
return true;
}
-string
+std::string
Formula::str() const
{
return root ? root->str() : "";
diff --git a/src/base/stats/text.cc b/src/base/stats/text.cc
index fa342a2..79bd0f0 100644
--- a/src/base/stats/text.cc
+++ b/src/base/stats/text.cc
@@ -66,8 +66,6 @@
#include "base/stats/info.hh"
#include "base/str.hh"
-using namespace std;
-
#ifndef NAN
float __nan();
/** Define Not a number. */
@@ -137,7 +135,7 @@
panic("stream already set!");
mystream = true;
- stream = new ofstream(file.c_str(), ios::trunc);
+ stream = new std::ofstream(file.c_str(), std::ios::trunc);
if (!valid())
fatal("Unable to open statistics file for writing\n");
}
@@ -199,10 +197,10 @@
return false;
}
-string
+std::string
ValueToString(Result value, int precision)
{
- stringstream val;
+ std::stringstream val;
if (!std::isnan(value)) {
if (precision != -1)
@@ -210,8 +208,8 @@
else if (value == rint(value))
val.precision(0);
- val.unsetf(ios::showpoint);
- val.setf(ios::fixed);
+ val.unsetf(std::ios::showpoint);
+ val.setf(std::ios::fixed);
val << value;
} else {
val << "nan";
@@ -223,8 +221,8 @@
struct ScalarPrint
{
Result value;
- string name;
- string desc;
+ std::string name;
+ std::string desc;
Flags flags;
bool descriptions;
bool spaces;
@@ -250,7 +248,7 @@
}
}
void update(Result val, Result total);
- void operator()(ostream &stream, bool oneLine = false) const;
+ void operator()(std::ostream &stream, bool oneLine = false) const;
};
void
@@ -264,13 +262,13 @@
}
void
-ScalarPrint::operator()(ostream &stream, bool oneLine) const
+ScalarPrint::operator()(std::ostream &stream, bool oneLine) const
{
if ((flags.isSet(nozero) && (!oneLine) && value == 0.0) ||
(flags.isSet(nonan) && std::isnan(value)))
return;
- stringstream pdfstr, cdfstr;
+ std::stringstream pdfstr, cdfstr;
if (!std::isnan(pdf))
ccprintf(pdfstr, "%.2f%%", pdf * 100.0);
@@ -293,17 +291,17 @@
if (!desc.empty())
ccprintf(stream, " # %s", desc);
}
- stream << endl;
+ stream << std::endl;
}
}
struct VectorPrint
{
- string name;
- string separatorString;
- string desc;
- vector<string> subnames;
- vector<string> subdescs;
+ std::string name;
+ std::string separatorString;
+ std::string desc;
+ std::vector<std::string> subnames;
+ std::vector<std::string> subdescs;
Flags flags;
bool descriptions;
bool spaces;
@@ -321,7 +319,7 @@
nameSpaces = 0;
}
}
- void operator()(ostream &stream) const;
+ void operator()(std::ostream &stream) const;
};
void
@@ -336,7 +334,7 @@
}
}
- string base = name + separatorString;
+ std::string base = name + separatorString;
ScalarPrint print(spaces);
print.name = name;
@@ -382,7 +380,7 @@
if (!desc.empty())
ccprintf(stream, " # %s", desc);
}
- stream << endl;
+ stream << std::endl;
}
}
@@ -398,9 +396,9 @@
struct DistPrint
{
- string name;
- string separatorString;
- string desc;
+ std::string name;
+ std::string separatorString;
+ std::string desc;
Flags flags;
bool descriptions;
bool spaces;
@@ -412,7 +410,7 @@
DistPrint(const Text *text, const DistInfo &info);
DistPrint(const Text *text, const VectorDistInfo &info, int i);
void init(const Text *text, const Info &info);
- void operator()(ostream &stream) const;
+ void operator()(std::ostream &stream) const;
};
DistPrint::DistPrint(const Text *text, const DistInfo &info)
@@ -452,10 +450,10 @@
}
void
-DistPrint::operator()(ostream &stream) const
+DistPrint::operator()(std::ostream &stream) const
{
if (flags.isSet(nozero) && data.samples == 0) return;
- string base = name + separatorString;
+ std::string base = name + separatorString;
ScalarPrint print(spaces);
print.precision = precision;
@@ -530,11 +528,11 @@
}
for (off_type i = 0; i < size; ++i) {
- stringstream namestr;
+ std::stringstream namestr;
namestr << base;
Counter low = i * data.bucket_size + data.min;
- Counter high = ::min(low + data.bucket_size - 1.0, data.max);
+ Counter high = std::min(low + data.bucket_size - 1.0, data.max);
namestr << low;
if (low < high)
namestr << "-" << high;
@@ -549,7 +547,7 @@
if (!desc.empty())
ccprintf(stream, " # %s", desc);
}
- stream << endl;
+ stream << std::endl;
}
if (data.type == Dist && data.overflow != NAN) {
@@ -691,7 +689,7 @@
}
// Create a subname for printing the total
- vector<string> total_subname;
+ std::vector<std::string> total_subname;
total_subname.push_back("total");
if (info.flags.isSet(::Stats::total) && (info.x > 1)) {
@@ -738,9 +736,9 @@
*/
struct SparseHistPrint
{
- string name;
- string separatorString;
- string desc;
+ std::string name;
+ std::string separatorString;
+ std::string desc;
Flags flags;
bool descriptions;
bool spaces;
@@ -750,7 +748,7 @@
SparseHistPrint(const Text *text, const SparseHistInfo &info);
void init(const Text *text, const Info &info);
- void operator()(ostream &stream) const;
+ void operator()(std::ostream &stream) const;
};
/* Call initialization function */
@@ -775,9 +773,9 @@
/* Grab data from map and write to output stream */
void
-SparseHistPrint::operator()(ostream &stream) const
+SparseHistPrint::operator()(std::ostream &stream) const
{
- string base = name + separatorString;
+ std::string base = name + separatorString;
ScalarPrint print(spaces);
print.precision = precision;
@@ -793,7 +791,7 @@
MCounter::const_iterator it;
for (it = data.cmap.begin(); it != data.cmap.end(); it++) {
- stringstream namestr;
+ std::stringstream namestr;
namestr << base;
namestr <<(*it).first;
@@ -814,7 +812,7 @@
}
Output *
-initText(const string &filename, bool desc, bool spaces)
+initText(const std::string &filename, bool desc, bool spaces)
{
static Text text;
static bool connected = false;
diff --git a/src/base/str.cc b/src/base/str.cc
index 96a5148..bc404c9 100644
--- a/src/base/str.cc
+++ b/src/base/str.cc
@@ -31,13 +31,11 @@
#include <string>
#include <vector>
-using namespace std;
-
bool
-split_first(const string &s, string &lhs, string &rhs, char c)
+split_first(const std::string &s, std::string &lhs, std::string &rhs, char
c)
{
- string::size_type offset = s.find(c);
- if (offset == string::npos) {
+ std::string::size_type offset = s.find(c);
+ if (offset == std::string::npos) {
lhs = s;
rhs = "";
return false;
@@ -49,10 +47,10 @@
}
bool
-split_last(const string &s, string &lhs, string &rhs, char c)
+split_last(const std::string &s, std::string &lhs, std::string &rhs, char
c)
{
- string::size_type offset = s.rfind(c);
- if (offset == string::npos) {
+ std::string::size_type offset = s.rfind(c);
+ if (offset == std::string::npos) {
lhs = s;
rhs = "";
return false;
@@ -64,10 +62,11 @@
}
void
-tokenize(vector<string>& v, const string &s, char token, bool ignore)
+tokenize(std::vector<std::string>& v, const std::string &s, char token,
+ bool ignore)
{
- string::size_type first = 0;
- string::size_type last = s.find_first_of(token);
+ std::string::size_type first = 0;
+ std::string::size_type last = s.find_first_of(token);
if (s.empty())
return;
@@ -76,20 +75,20 @@
while (last == first)
last = s.find_first_of(token, ++first);
- if (last == string::npos) {
+ if (last == std::string::npos) {
if (first != s.size())
v.push_back(s.substr(first));
return;
}
}
- while (last != string::npos) {
+ while (last != std::string::npos) {
v.push_back(s.substr(first, last - first));
if (ignore) {
first = s.find_first_not_of(token, last + 1);
- if (first == string::npos)
+ if (first == std::string::npos)
return;
} else
first = last + 1;
diff --git a/src/base/time.cc b/src/base/time.cc
index 6be7517..92d69c0 100644
--- a/src/base/time.cc
+++ b/src/base/time.cc
@@ -38,8 +38,6 @@
#include "sim/core.hh"
#include "sim/serialize.hh"
-using namespace std;
-
void
Time::_set(bool monotonic)
{
@@ -68,8 +66,8 @@
static_cast<uint64_t>(nsec() * SimClock::Float::ns);
}
-string
-Time::date(const string &format) const
+std::string
+Time::date(const std::string &format) const
{
time_t sec = this->sec();
char buf[256];
@@ -89,7 +87,7 @@
return buf;
}
-string
+std::string
Time::time() const
{
double time = double(*this);
@@ -98,7 +96,7 @@
double mins = fmod(all_mins, 60.0);
double hours = floor(all_mins / 60.0);
- stringstream str;
+ std::stringstream str;
if (hours > 0.0) {
if (hours < 10.0)
diff --git a/src/base/vnc/vncinput.cc b/src/base/vnc/vncinput.cc
index a4bedaf..b07e0ca 100644
--- a/src/base/vnc/vncinput.cc
+++ b/src/base/vnc/vncinput.cc
@@ -49,8 +49,6 @@
#include "base/trace.hh"
#include "debug/VNC.hh"
-using namespace std;
-
VncInput::VncInput(const Params &p)
: SimObject(p), keyboard(NULL), mouse(NULL),
fb(&FrameBuffer::dummy),
@@ -62,7 +60,7 @@
if (captureEnabled) {
// remove existing frame output directory if it exists, then
create a
// clean empty directory
- const string FRAME_OUTPUT_SUBDIR = "frames_" + name();
+ const std::string FRAME_OUTPUT_SUBDIR = "frames_" + name();
simout.remove(FRAME_OUTPUT_SUBDIR, true);
captureOutputDirectory = simout.createSubdirectory(
FRAME_OUTPUT_SUBDIR);
@@ -124,7 +122,7 @@
snprintf(frameFilenameBuffer, 64, "fb.%06d.%lld.%s.gz",
captureCurrentFrame, static_cast<long long int>(curTick()),
captureImage->getImgExtension());
- const string frameFilename(frameFilenameBuffer);
+ const std::string frameFilename(frameFilenameBuffer);
// create the compressed framebuffer file
OutputStream *fb_out(captureOutputDirectory->create(frameFilename,
true));
diff --git a/src/base/vnc/vncserver.cc b/src/base/vnc/vncserver.cc
index 983a343..a2d4105 100644
--- a/src/base/vnc/vncserver.cc
+++ b/src/base/vnc/vncserver.cc
@@ -69,8 +69,6 @@
#include "sim/byteswap.hh"
#include "sim/core.hh"
-using namespace std;
-
const PixelConverter VncServer::pixelConverter(
4, // 4 bytes / pixel
16, 8, 0, // R in [23, 16], G in [15, 8], B in [7, 0]
@@ -171,7 +169,7 @@
port++;
}
- ccprintf(cerr, "%s: Listening for connections on port %d\n",
+ ccprintf(std::cerr, "%s: Listening for connections on port %d\n",
name(), port);
listenEvent = new ListenEvent(this, listener.getfd(), POLLIN);
@@ -470,7 +468,7 @@
memset(msg.px.padding, 0, 3);
msg.namelen = 2;
msg.namelen = htobe(msg.namelen);
- memcpy(msg.name, "M5", 2);
+ std::memcpy(msg.name, "M5", 2);
if (!write(&msg))
return;
--
To view, visit https://gem5-review.googlesource.com/c/public/gem5/+/39536
To unsubscribe, or for help writing mail filters, visit
https://gem5-review.googlesource.com/settings
Gerrit-Project: public/gem5
Gerrit-Branch: develop
Gerrit-Change-Id: Ie30cbab154b00c60433908a206c229230d2b109f
Gerrit-Change-Number: 39536
Gerrit-PatchSet: 1
Gerrit-Owner: Gabe Black <[email protected]>
Gerrit-MessageType: newchange
_______________________________________________
gem5-dev mailing list -- [email protected]
To unsubscribe send an email to [email protected]
%(web_page_url)slistinfo%(cgiext)s/%(_internal_name)s