mirror of https://github.com/aria2/aria2
Made STATUS_STRING const char*[]
parent
a8c0794640
commit
b640b830a2
|
@ -46,10 +46,12 @@
|
|||
|
||||
namespace aria2 {
|
||||
|
||||
const std::string ServerStat::STATUS_STRING[] = {
|
||||
namespace {
|
||||
const char* STATUS_STRING[] = {
|
||||
"OK",
|
||||
"ERROR"
|
||||
};
|
||||
} // namespace
|
||||
|
||||
ServerStat::ServerStat(const std::string& hostname, const std::string& protocol)
|
||||
: hostname_(hostname),
|
||||
|
@ -161,18 +163,18 @@ void ServerStat::setStatus(STATUS status)
|
|||
|
||||
void ServerStat::setStatus(const std::string& status)
|
||||
{
|
||||
const std::string* p = std::find(vbegin(STATUS_STRING), vend(STATUS_STRING),
|
||||
status);
|
||||
if(p != vend(STATUS_STRING)) {
|
||||
status_ = static_cast<STATUS>(ServerStat::OK+
|
||||
std::distance(vbegin(STATUS_STRING), p));
|
||||
for(int i = 0; i < MAX_STATUS; ++i) {
|
||||
if(strcmp(status.c_str(), STATUS_STRING[i]) == 0) {
|
||||
status_ = static_cast<STATUS>(i);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void ServerStat::setStatusInternal(STATUS status)
|
||||
{
|
||||
A2_LOG_DEBUG(fmt("ServerStat: set status %s for %s (%s)",
|
||||
STATUS_STRING[status].c_str(),
|
||||
STATUS_STRING[status],
|
||||
hostname_.c_str(),
|
||||
protocol_.c_str()));
|
||||
status_ = status;
|
||||
|
@ -211,7 +213,7 @@ std::string ServerStat::toString() const
|
|||
getMultiConnectionAvgSpeed(),
|
||||
getLastUpdated().getTime(),
|
||||
getCounter(),
|
||||
ServerStat::STATUS_STRING[getStatus()].c_str());
|
||||
STATUS_STRING[getStatus()]);
|
||||
}
|
||||
|
||||
} // namespace aria2
|
||||
|
|
|
@ -52,10 +52,9 @@ class ServerStat {
|
|||
public:
|
||||
enum STATUS {
|
||||
OK = 0,
|
||||
A2_ERROR
|
||||
A2_ERROR,
|
||||
MAX_STATUS
|
||||
};
|
||||
|
||||
static const std::string STATUS_STRING[];
|
||||
|
||||
ServerStat(const std::string& hostname, const std::string& protocol);
|
||||
|
||||
|
|
Loading…
Reference in New Issue