summaryrefslogtreecommitdiff
path: root/src/resources
diff options
context:
space:
mode:
Diffstat (limited to 'src/resources')
-rw-r--r--src/resources/buddylist.cpp67
-rw-r--r--src/resources/buddylist.h11
-rw-r--r--src/resources/image.cpp34
-rw-r--r--src/resources/image.h8
-rw-r--r--src/resources/itemmanager.cpp8
-rw-r--r--src/resources/itemmanager.h2
6 files changed, 57 insertions, 73 deletions
diff --git a/src/resources/buddylist.cpp b/src/resources/buddylist.cpp
index e41327a5..9327ef60 100644
--- a/src/resources/buddylist.cpp
+++ b/src/resources/buddylist.cpp
@@ -30,34 +30,27 @@
BuddyList::BuddyList()
{
// Find saved buddy list file
- filename = new std::string(std::string(config.getValue("homeDir", "") + "/buddy.txt"));
+ mFilename = config.getValue("homeDir", "") + "/buddy.txt";
// Load buddy from file
loadFile();
}
-BuddyList::~BuddyList()
-{
- delete filename;
-}
-
void BuddyList::loadFile()
{
- char *buddy;
-
// Open file
- std::ifstream inputStream(filename->c_str(), std::ios::in);
- if( !inputStream ) {
+ std::ifstream inputStream(mFilename.c_str(), std::ios::in);
+ if (!inputStream) {
std::cerr << "Error opening input stream" << std::endl;
return;
}
do {
- buddy = (char *) calloc(LEN_MAX_USERNAME, sizeof(char));
+ char *buddy = new char[LEN_MAX_USERNAME];
inputStream.getline(buddy, LEN_MAX_USERNAME);
// Ugly ?
- if(strcmp(buddy,"") != 0) buddylist.push_back(buddy);
- free(buddy);
+ if(strcmp(buddy,"")) mBuddylist.push_back(buddy);
+ delete [] buddy;
} while(!inputStream.eof());
// Read buddy and close file
@@ -69,31 +62,29 @@ void BuddyList::saveFile()
std::string str;
// Open file
- std::ofstream outputStream(filename->c_str(), std::ios::trunc);
- if( !outputStream ) {
+ std::ofstream outputStream(mFilename.c_str(), std::ios::trunc);
+ if (!outputStream) {
std::cerr << "Error opening output stream" << std::endl;
return;
}
// Write buddy and close file
- for (buddyit = buddylist.begin(); buddyit != buddylist.end(); buddyit++)
+ for (BuddyIterator i = mBuddylist.begin(); i != mBuddylist.end(); ++i)
{
- str = *buddyit;
- outputStream << (const char*) str.c_str() << std::endl;
+ outputStream << (const char*) i->c_str() << std::endl;
}
outputStream.close();
}
bool BuddyList::addBuddy(const std::string buddy)
{
- for (buddyit = buddylist.begin(); buddyit != buddylist.end(); buddyit++)
+ if (find(mBuddylist.begin(), mBuddylist.end(), buddy) != mBuddylist.end())
{
- // Buddy already exist
- if (*buddyit == buddy) return false;
+ return false;
}
// Buddy doesnt exist, add it
- buddylist.push_back(buddy);
+ mBuddylist.push_back(buddy);
// Save file
saveFile();
@@ -103,37 +94,29 @@ bool BuddyList::addBuddy(const std::string buddy)
bool BuddyList::removeBuddy(const std::string buddy)
{
- if (buddylist.size() > 0) {
- for (buddyit = buddylist.begin(); buddyit != buddylist.end(); buddyit++)
- {
- // Buddy exist, remove it
- if (*buddyit == buddy) {
- buddylist.remove(buddy);
-
- // Save file
- saveFile();
- return true;
- }
- }
+ BuddyIterator i = find(mBuddylist.begin(), mBuddylist.end(), buddy);
+
+ if (i != mBuddylist.end()) {
+ mBuddylist.erase(i);
+ saveFile();
+ return true;
}
- // Buddy doesnt exist
return false;
}
int BuddyList::getNumberOfElements()
{
- return buddylist.size();
+ return mBuddylist.size();
}
std::string BuddyList::getElementAt(int number)
{
- if (number <= (int) buddylist.size() - 1)
- {
- buddyit = buddylist.begin();
- std::advance(buddyit, number);
- return *buddyit;
+ if (number >= (int) mBuddylist.size()) {
+ return "";
}
- return "";
+ BuddyIterator i = mBuddylist.begin();
+ std::advance(i, number);
+ return *i;
}
diff --git a/src/resources/buddylist.h b/src/resources/buddylist.h
index df5d6247..3791a03a 100644
--- a/src/resources/buddylist.h
+++ b/src/resources/buddylist.h
@@ -24,8 +24,8 @@
#ifndef _TMW_BUDDYLIST_H
#define _TMW_BUDDYLIST_H
-#include <iosfwd>
#include <list>
+#include <string>
#include <guichan/listmodel.hpp>
@@ -39,7 +39,7 @@ class BuddyList : public gcn::ListModel {
/**
* Destructor
*/
- virtual ~BuddyList();
+ virtual ~BuddyList() { }
/**
* Adds buddy to the list
@@ -72,9 +72,10 @@ class BuddyList : public gcn::ListModel {
*/
void loadFile();
- std::list<std::string> buddylist; /**< Buddy list */
- std::list<std::string>::iterator buddyit; /**< Iterator */
- std::string *filename; /* File to work with */
+ typedef std::list<std::string> Buddies;
+ typedef Buddies::iterator BuddyIterator;
+ Buddies mBuddylist; /**< Buddy list */
+ std::string mFilename; /* File to work with */
};
#endif /* _TMW_BUDDYLIST_H */
diff --git a/src/resources/image.cpp b/src/resources/image.cpp
index f5082c60..ee2736d4 100644
--- a/src/resources/image.cpp
+++ b/src/resources/image.cpp
@@ -35,10 +35,10 @@ Image::Image(const std::string &idPath, SDL_Surface *image):
Resource(idPath), mImage(image),
mAlpha(1.0f)
{
- bounds.x = 0;
- bounds.y = 0;
- bounds.w = mImage->w;
- bounds.h = mImage->h;
+ mBounds.x = 0;
+ mBounds.y = 0;
+ mBounds.w = mImage->w;
+ mBounds.h = mImage->h;
}
#ifdef USE_OPENGL
@@ -51,10 +51,10 @@ Image::Image(const std::string &idPath, GLuint glimage, int width, int height,
mImage(0),
mAlpha(1.0)
{
- bounds.x = 0;
- bounds.y = 0;
- bounds.w = width;
- bounds.h = height;
+ mBounds.x = 0;
+ mBounds.y = 0;
+ mBounds.w = width;
+ mBounds.h = height;
}
#endif
@@ -258,7 +258,7 @@ Image* Image::load(void *buffer, unsigned int bufferSize,
void Image::unload()
{
- loaded = false;
+ mLoaded = false;
if (!mImage) return;
@@ -315,10 +315,10 @@ SubImage::SubImage(Image *parent, SDL_Surface *image,
mParent->incRef();
// Set up the rectangle.
- bounds.x = x;
- bounds.y = y;
- bounds.w = width;
- bounds.h = height;
+ mBounds.x = x;
+ mBounds.y = y;
+ mBounds.w = width;
+ mBounds.h = height;
}
#ifdef USE_OPENGL
@@ -330,10 +330,10 @@ SubImage::SubImage(Image *parent, GLuint image,
mParent->incRef();
// Set up the rectangle.
- bounds.x = x;
- bounds.y = y;
- bounds.w = width;
- bounds.h = height;
+ mBounds.x = x;
+ mBounds.y = y;
+ mBounds.w = width;
+ mBounds.h = height;
}
#endif
diff --git a/src/resources/image.h b/src/resources/image.h
index 44142155..1f67fcae 100644
--- a/src/resources/image.h
+++ b/src/resources/image.h
@@ -70,14 +70,14 @@ class Image : public Resource
* Returns the width of the image.
*/
virtual int
- getWidth() const { return bounds.w; }
+ getWidth() const { return mBounds.w; }
/**
* Returns the height of the image.
*/
virtual int
- getHeight() const { return bounds.h; }
+ getHeight() const { return mBounds.h; }
/**
* Creates a new image with the desired clipping rectangle.
@@ -119,8 +119,8 @@ class Image : public Resource
#endif
Image(const std::string &idPath, SDL_Surface *image);
- SDL_Rect bounds;
- bool loaded;
+ SDL_Rect mBounds;
+ bool mLoaded;
#ifdef USE_OPENGL
GLuint mGLImage;
diff --git a/src/resources/itemmanager.cpp b/src/resources/itemmanager.cpp
index 994f11b9..9f6607c1 100644
--- a/src/resources/itemmanager.cpp
+++ b/src/resources/itemmanager.cpp
@@ -38,8 +38,8 @@
ItemManager::ItemManager()
{
- unknown = new ItemInfo();
- unknown->setName("Unknown item");
+ mUnknown = new ItemInfo();
+ mUnknown->setName("Unknown item");
ResourceManager *resman = ResourceManager::getInstance();
int size;
@@ -161,7 +161,7 @@ ItemManager::~ItemManager()
}
mItemInfos.clear();
- delete unknown;
+ delete mUnknown;
}
ItemInfo*
@@ -169,5 +169,5 @@ ItemManager::getItemInfo(int id)
{
ItemInfoIterator i = mItemInfos.find(id);
- return (i != mItemInfos.end()) ? i->second : unknown;
+ return (i != mItemInfos.end()) ? i->second : mUnknown;
}
diff --git a/src/resources/itemmanager.h b/src/resources/itemmanager.h
index 5a571de2..06eee507 100644
--- a/src/resources/itemmanager.h
+++ b/src/resources/itemmanager.h
@@ -51,7 +51,7 @@ class ItemManager
typedef std::map<int, ItemInfo*> ItemInfos;
typedef ItemInfos::iterator ItemInfoIterator;
ItemInfos mItemInfos;
- ItemInfo *unknown;
+ ItemInfo *mUnknown;
};
extern ItemManager *itemDb;