summaryrefslogtreecommitdiff
path: root/src/ServerStat.cc
diff options
context:
space:
mode:
authorTatsuhiro Tsujikawa <tatsuhiro.t@gmail.com>2008-08-09 11:29:27 +0000
committerTatsuhiro Tsujikawa <tatsuhiro.t@gmail.com>2008-08-09 11:29:27 +0000
commitd85014b937db0def7f2084f9df638a67a05a5a13 (patch)
treefc73ab1eba3b0d5fff284493a073f39bdfcf72b3 /src/ServerStat.cc
parent8208e538ba2065e9040d24ba660374739bb743c3 (diff)
2008-08-09 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com>
Implemented ServerStatMan::load(...) function and its test case. * src/ServerStat.cc * src/ServerStat.h * src/ServerStatMan.cc * test/ServerStatManTest.cc * test/ServerStatTest.cc
Diffstat (limited to 'src/ServerStat.cc')
-rw-r--r--src/ServerStat.cc23
1 files changed, 21 insertions, 2 deletions
diff --git a/src/ServerStat.cc b/src/ServerStat.cc
index 196b6866..055648fb 100644
--- a/src/ServerStat.cc
+++ b/src/ServerStat.cc
@@ -33,7 +33,9 @@
*/
/* copyright --> */
#include "ServerStat.h"
+#include "array_fun.h"
#include <ostream>
+#include <algorithm>
namespace aria2 {
@@ -93,6 +95,23 @@ void ServerStat::updateDownloadSpeed(unsigned int downloadSpeed)
void ServerStat::setStatus(STATUS status)
{
_status = status;
+}
+
+void ServerStat::setStatus(const std::string& status)
+{
+ size_t len = arrayLength(STATUS_STRING);
+ const std::string* p = std::find(&STATUS_STRING[0],
+ &STATUS_STRING[len],
+ status);
+ if(p != &STATUS_STRING[len]) {
+ _status = static_cast<STATUS>(ServerStat::OK+
+ std::distance(&STATUS_STRING[0], p));
+ }
+}
+
+void ServerStat::setStatusInternal(STATUS status)
+{
+ _status = status;
_lastUpdated.reset();
}
@@ -108,7 +127,7 @@ bool ServerStat::isOK() const
void ServerStat::setOK()
{
- setStatus(OK);
+ setStatusInternal(OK);
}
bool ServerStat::isError() const
@@ -118,7 +137,7 @@ bool ServerStat::isError() const
void ServerStat::setError()
{
- setStatus(ERROR);
+ setStatusInternal(ERROR);
}
bool ServerStat::operator<(const ServerStat& serverStat) const