Files
wagic/projects/mtg/include/DeckDataWrapper.h
jean.chalard 01bd44025d J :
* Performance improvement for the deck editor when scrolling cards
  (transform 2*N*log(N)<Cmp1> + N*<read> into log(N)<Cmp1> +
  N*<read>). I expect this improvement to be much more significant,
  performance-wise, than last night's one.
2009-06-05 01:58:41 +00:00

48 lines
1.1 KiB
C++

#ifndef _DECKDATAWRAPPER_H_
#define _DECKDATAWRAPPER_H_
#include "../include/MTGDefinitions.h"
#include "../include/MTGCard.h"
#include <map>
#include <string>
using std::map;
using std::string;
class MTGDeck;
class Cmp1 { // compares cards by their name
public:
bool operator()(MTGCard * card1, MTGCard * card2) const {
if (!card2) return true;
if (!card1) return false;
int result = card1->name.compare(card2->name);
if (!result) return card1->getMTGId() < card2->getMTGId();
return ( result < 0);
}
};
class DeckDataWrapper{
public:
int colors[Constants::MTG_NB_COLORS+1];
int currentColor;
map<MTGCard *, int,Cmp1> cards;
MTGDeck * parent;
DeckDataWrapper(MTGDeck * deck);
~DeckDataWrapper();
int Add(MTGCard * card);
int Remove(MTGCard * card);
MTGCard * getNext(MTGCard * previous = NULL, int color = -1);
MTGCard * getPrevious(MTGCard * next = NULL, int color = -1);
void updateCounts(MTGCard * card = NULL, int removed = 0);
int getCount(int color = -1);
int totalPrice();
void save();
int countByName(MTGCard * card);
int count(MTGCard * card);
};
#endif