mirror of https://github.com/aria2/aria2
2008-05-18 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com>
Made Option::get(...) return const reference of std::string. * src/Option.cc * src/Option.hpull/1/head
parent
e4b0446c61
commit
0a95211100
|
@ -1,3 +1,9 @@
|
||||||
|
2008-05-18 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com>
|
||||||
|
|
||||||
|
Made Option::get(...) return const reference of std::string.
|
||||||
|
* src/Option.cc
|
||||||
|
* src/Option.h
|
||||||
|
|
||||||
2008-05-18 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com>
|
2008-05-18 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com>
|
||||||
|
|
||||||
Replaced std:copy with insert.
|
Replaced std:copy with insert.
|
||||||
|
|
|
@ -36,6 +36,7 @@
|
||||||
#include "prefs.h"
|
#include "prefs.h"
|
||||||
#include "A2STR.h"
|
#include "A2STR.h"
|
||||||
#include <cstdlib>
|
#include <cstdlib>
|
||||||
|
#include <cstring>
|
||||||
|
|
||||||
namespace aria2 {
|
namespace aria2 {
|
||||||
|
|
||||||
|
@ -51,7 +52,7 @@ bool Option::defined(const std::string& name) const {
|
||||||
return table.count(name) == 1;
|
return table.count(name) == 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string Option::get(const std::string& name) const {
|
const std::string& Option::get(const std::string& name) const {
|
||||||
std::map<std::string, std::string>::const_iterator itr = table.find(name);
|
std::map<std::string, std::string>::const_iterator itr = table.find(name);
|
||||||
if(itr == table.end()) {
|
if(itr == table.end()) {
|
||||||
return A2STR::NIL;
|
return A2STR::NIL;
|
||||||
|
@ -61,26 +62,26 @@ std::string Option::get(const std::string& name) const {
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t Option::getAsInt(const std::string& name) const {
|
int32_t Option::getAsInt(const std::string& name) const {
|
||||||
std::string value = get(name);
|
const std::string& value = get(name);
|
||||||
if(value.empty()) {
|
if(value.empty()) {
|
||||||
return 0;
|
return 0;
|
||||||
} else {
|
} else {
|
||||||
return strtol(value.c_str(), NULL, 10);
|
return strtol(value.c_str(), 0, 10);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int64_t Option::getAsLLInt(const std::string& name) const {
|
int64_t Option::getAsLLInt(const std::string& name) const {
|
||||||
std::string value = get(name);
|
const std::string& value = get(name);
|
||||||
if(value.empty()) {
|
if(value.empty()) {
|
||||||
return 0;
|
return 0;
|
||||||
} else {
|
} else {
|
||||||
return strtoll(value.c_str(), NULL, 10);
|
return strtoll(value.c_str(), 0, 10);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Option::getAsBool(const std::string& name) const {
|
bool Option::getAsBool(const std::string& name) const {
|
||||||
std::string value = get(name);
|
const std::string& value = get(name);
|
||||||
if(value == V_TRUE) {
|
if(strcmp(value.c_str(), V_TRUE) == 0) {
|
||||||
return true;
|
return true;
|
||||||
} else {
|
} else {
|
||||||
return false;
|
return false;
|
||||||
|
@ -88,7 +89,7 @@ bool Option::getAsBool(const std::string& name) const {
|
||||||
}
|
}
|
||||||
|
|
||||||
double Option::getAsDouble(const std::string& name) const {
|
double Option::getAsDouble(const std::string& name) const {
|
||||||
std::string value = get(name);
|
const std::string& value = get(name);
|
||||||
if(value.empty()) {
|
if(value.empty()) {
|
||||||
return 0.0;
|
return 0.0;
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -50,7 +50,7 @@ public:
|
||||||
|
|
||||||
void put(const std::string& name, const std::string& value);
|
void put(const std::string& name, const std::string& value);
|
||||||
bool defined(const std::string& name) const;
|
bool defined(const std::string& name) const;
|
||||||
std::string get(const std::string& name) const;
|
const std::string& get(const std::string& name) const;
|
||||||
int getAsInt(const std::string& name) const;
|
int getAsInt(const std::string& name) const;
|
||||||
int64_t getAsLLInt(const std::string& name) const;
|
int64_t getAsLLInt(const std::string& name) const;
|
||||||
bool getAsBool(const std::string& name) const;
|
bool getAsBool(const std::string& name) const;
|
||||||
|
|
Loading…
Reference in New Issue