summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorHuynh Tran <nthuynh75@gmail.com>2005-06-17 19:45:47 +0000
committerHuynh Tran <nthuynh75@gmail.com>2005-06-17 19:45:47 +0000
commit2224209b0e1a6189e839ed62c4434c16aacca6ce (patch)
treecd740001496d76d48209d8f338fd31e5a0bc6bb8 /src
parent836536c2478cac29f905464ab0f53b98af77c6b1 (diff)
downloadmanaserv-2224209b0e1a6189e839ed62c4434c16aacca6ce.tar.gz
manaserv-2224209b0e1a6189e839ed62c4434c16aacca6ce.tar.bz2
manaserv-2224209b0e1a6189e839ed62c4434c16aacca6ce.tar.xz
manaserv-2224209b0e1a6189e839ed62c4434c16aacca6ce.zip
Fixed instantiation of Beings.
Diffstat (limited to 'src')
-rw-r--r--src/dalstorage.cpp52
1 files changed, 37 insertions, 15 deletions
diff --git a/src/dalstorage.cpp b/src/dalstorage.cpp
index db435b5d..268c674f 100644
--- a/src/dalstorage.cpp
+++ b/src/dalstorage.cpp
@@ -21,7 +21,6 @@
*/
-#include <functional>
#include <sstream>
#include "dalstorage.h"
@@ -34,18 +33,37 @@ namespace
/**
* Functor used for the search of an Account by name.
*/
-template <typename T>
struct account_name_equals_to
- : public std::binary_function<T, std::string, bool>
+ : public std::binary_function<Account*, std::string, bool>
{
bool
- operator()(const T& account, const std::string& name) const
+ operator()(Account* account,
+ const std::string& name) const
{
return account->getName() == name;
}
};
+/**
+ * Functor to convert a string into another type using
+ * std::istringstream.operator>>().
+ */
+template <typename T>
+struct string_to: public std::unary_function<std::string, T>
+{
+ T
+ operator()(const std::string& s) const
+ {
+ std::istringstream is(s);
+ T value;
+ is >> value;
+
+ return value;
+ }
+};
+
+
/* Values for user level could be:
* 0: Normal user
* 1: Moderator (has medium level rights)
@@ -220,14 +238,13 @@ DALStorage::getAccount(const std::string& userName)
std::find_if(
mAccounts.begin(),
mAccounts.end(),
- std::bind2nd(account_name_equals_to<Account*>(), userName)
+ std::bind2nd(account_name_equals_to(), userName)
);
if (it != mAccounts.end()) {
return (*it);
}
-
using namespace dal;
// the account was not in the list, look for it in the database.
@@ -262,17 +279,22 @@ DALStorage::getAccount(const std::string& userName)
if (!charInfo.isEmpty()) {
Beings beings;
+ // specialize the string_to functor to convert
+ // a string to an unsigned int.
+ string_to<unsigned int> toUint;
+
for (unsigned int i = 0; i < charInfo.rows(); ++i) {
Being* being =
- new Being(charInfo(i, 2), // name
- charInfo(i, 3), // gender
- charInfo(i, 4), // level
- charInfo(i, 5), // money
- charInfo(i, 9), // strength
- charInfo(i, 10), // agility
- charInfo(i, 11), // vitality
- charInfo(i, 13), // dexterity
- charInfo(i, 14)); // luck
+ new Being(charInfo(i, 2), // name
+ toUint(charInfo(i, 3)), // gender
+ toUint(charInfo(i, 4)), // level
+ toUint(charInfo(i, 5)), // money
+ toUint(charInfo(i, 9)), // strength
+ toUint(charInfo(i, 10)), // agility
+ toUint(charInfo(i, 11)), // vitality
+ toUint(charInfo(i, 13)), // dexterity
+ toUint(charInfo(i, 14)) // luck
+ );
mCharacters.push_back(being);
beings.push_back(being);