diff options
| author | Simon Robertshaw <simon@hardwired.org.uk> | 2012-06-10 18:52:24 (GMT) |
|---|---|---|
| committer | Simon Robertshaw <simon@hardwired.org.uk> | 2012-06-10 18:52:24 (GMT) |
| commit | fd572e9da68385d13a147164cd07d50160f2fc69 (patch) | |
| tree | 2cd99a57db8f11f4d41defe4ca4253553cd0b562 /src/client | |
| parent | cdc4b4df86d61abf8fe08fe120afcb2393755660 (diff) | |
| download | powder-fd572e9da68385d13a147164cd07d50160f2fc69.zip powder-fd572e9da68385d13a147164cd07d50160f2fc69.tar.gz | |
Change stamp storage to a list, insert new stamps at the begining, 'l' loads the first stamp or the previously used stamp, 'k' shows the stamp browser
Diffstat (limited to 'src/client')
| -rw-r--r-- | src/client/Client.cpp | 33 | ||||
| -rw-r--r-- | src/client/Client.h | 7 |
2 files changed, 30 insertions, 10 deletions
diff --git a/src/client/Client.cpp b/src/client/Client.cpp index 23a487c..68e59e0 100644 --- a/src/client/Client.cpp +++ b/src/client/Client.cpp @@ -253,12 +253,12 @@ SaveFile * Client::GetStamp(string stampID) void Client::DeleteStamp(string stampID) { - for(int i = 0; i < stampIDs.size(); i++) + for (std::list<string>::iterator iterator = stampIDs.begin(), end = stampIDs.end(); iterator != end; ++iterator) { - if(stampIDs[i] == stampID) + if((*iterator) == stampID) { remove(string(STAMPS_DIR PATH_SEP + stampID + ".stm").c_str()); - stampIDs.erase(stampIDs.begin()+i); + stampIDs.erase(iterator); return; } } @@ -294,7 +294,7 @@ string Client::AddStamp(GameSave * saveData) stampStream.write((const char *)gameData, gameDataLength); stampStream.close(); - stampIDs.push_back(saveID.str()); + stampIDs.push_front(saveID.str()); updateStamps(); @@ -312,18 +312,35 @@ void Client::updateStamps() std::ofstream stampsStream; stampsStream.open(string(STAMPS_DIR PATH_SEP "stamps.def").c_str(), ios::binary); - for(int i = 0; i < stampIDs.size(); i++) + for (std::list<string>::const_iterator iterator = stampIDs.begin(), end = stampIDs.end(); iterator != end; ++iterator) { - stampsStream.write(stampIDs[i].c_str(), 10); + stampsStream.write((*iterator).c_str(), 10); } stampsStream.write("\0", 1); stampsStream.close(); return; } -vector<string> Client::GetStamps() +int Client::GetStampsCount() { - return stampIDs; + return stampIDs.size(); +} + +vector<string> Client::GetStamps(int start, int count) +{ + //if(start+count > stampIDs.size()) { + // if(start > stampIDs.size()) + // return vector<string>(); + // count = stampIDs.size()-start; + //} + + vector<string> stampRange; + int index = 0; + for (std::list<string>::const_iterator iterator = stampIDs.begin(), end = stampIDs.end(); iterator != end; ++iterator, ++index) { + if(index>=start && index < start+count) + stampRange.push_back(*iterator); + } + return stampRange; } RequestStatus Client::ExecVote(int saveID, int direction) diff --git a/src/client/Client.h b/src/client/Client.h index 53f0e79..6c1baa5 100644 --- a/src/client/Client.h +++ b/src/client/Client.h @@ -3,6 +3,7 @@ #include <queue> #include <vector> +#include <list> #include <fstream> #include "Config.h" @@ -30,7 +31,7 @@ class Client: public Singleton<Client> { private: std::string lastError; - vector<string> stampIDs; + list<string> stampIDs; int lastStampTime; int lastStampName; @@ -58,7 +59,9 @@ public: SaveFile * GetStamp(string stampID); void DeleteStamp(string stampID); string AddStamp(GameSave * saveData); - vector<string> GetStamps(); + vector<string> GetStamps(int start, int count); + int GetStampsCount(); + SaveFile * GetFirstStamp(); unsigned char * GetSaveData(int saveID, int saveDate, int & dataLength); LoginStatus Login(string username, string password, User & user); |
