Made STATUS_STRING const char*[]

pull/28/head
Tatsuhiro Tsujikawa 2012-09-25 00:01:00 +09:00
parent a8c0794640
commit b640b830a2
2 changed files with 12 additions and 11 deletions

View File

@ -46,10 +46,12 @@
namespace aria2 { namespace aria2 {
const std::string ServerStat::STATUS_STRING[] = { namespace {
const char* STATUS_STRING[] = {
"OK", "OK",
"ERROR" "ERROR"
}; };
} // namespace
ServerStat::ServerStat(const std::string& hostname, const std::string& protocol) ServerStat::ServerStat(const std::string& hostname, const std::string& protocol)
: hostname_(hostname), : hostname_(hostname),
@ -161,18 +163,18 @@ void ServerStat::setStatus(STATUS status)
void ServerStat::setStatus(const std::string& status) void ServerStat::setStatus(const std::string& status)
{ {
const std::string* p = std::find(vbegin(STATUS_STRING), vend(STATUS_STRING), for(int i = 0; i < MAX_STATUS; ++i) {
status); if(strcmp(status.c_str(), STATUS_STRING[i]) == 0) {
if(p != vend(STATUS_STRING)) { status_ = static_cast<STATUS>(i);
status_ = static_cast<STATUS>(ServerStat::OK+ break;
std::distance(vbegin(STATUS_STRING), p)); }
} }
} }
void ServerStat::setStatusInternal(STATUS status) void ServerStat::setStatusInternal(STATUS status)
{ {
A2_LOG_DEBUG(fmt("ServerStat: set status %s for %s (%s)", A2_LOG_DEBUG(fmt("ServerStat: set status %s for %s (%s)",
STATUS_STRING[status].c_str(), STATUS_STRING[status],
hostname_.c_str(), hostname_.c_str(),
protocol_.c_str())); protocol_.c_str()));
status_ = status; status_ = status;
@ -211,7 +213,7 @@ std::string ServerStat::toString() const
getMultiConnectionAvgSpeed(), getMultiConnectionAvgSpeed(),
getLastUpdated().getTime(), getLastUpdated().getTime(),
getCounter(), getCounter(),
ServerStat::STATUS_STRING[getStatus()].c_str()); STATUS_STRING[getStatus()]);
} }
} // namespace aria2 } // namespace aria2

View File

@ -52,10 +52,9 @@ class ServerStat {
public: public:
enum STATUS { enum STATUS {
OK = 0, OK = 0,
A2_ERROR A2_ERROR,
MAX_STATUS
}; };
static const std::string STATUS_STRING[];
ServerStat(const std::string& hostname, const std::string& protocol); ServerStat(const std::string& hostname, const std::string& protocol);