ScoreKeeper.h
Go to the documentation of this file.00001 #ifndef SCORE_KEEPER_H_
00002 #define SCORE_KEEPER_H_
00003
00004
00005 #include "Kodu/General/GeneralFncs.h"
00006 #include "Kodu/General/GeneralMacros.h"
00007 #include "Kodu/Primitives/KoduActionScore.h"
00008
00009
00010 #include <iostream>
00011 #include <string>
00012
00013 namespace Kodu {
00014
00015 typedef unsigned long Timestamp_t;
00016
00017
00018
00019 class KoduActionScore;
00020
00021 class ScoreChange {
00022 public:
00023
00024 ScoreChange(KoduActionScore::ScoringType_t scoreOp, const std::string& kDesignator,
00025 unsigned int val)
00026 : operationType(scoreOp),
00027 designator(kDesignator),
00028 value(val),
00029 timeCreated(0)
00030 {
00031 timeCreated = GeneralFncs::getTime();
00032 }
00033
00034
00035 ScoreChange(const ScoreChange& kChange)
00036 : operationType(kChange.operationType),
00037 designator(kChange.designator),
00038 value(kChange.value),
00039 timeCreated(kChange.timeCreated)
00040 { }
00041
00042
00043 ~ScoreChange() {
00044
00045 }
00046
00047
00048 ScoreChange& operator=(const ScoreChange& kChange) {
00049 if (this != &kChange) {
00050 operationType = kChange.operationType;
00051 designator = kChange.designator;
00052 value = kChange.value;
00053 timeCreated = kChange.timeCreated;
00054 }
00055 return *this;
00056 }
00057
00058 Timestamp_t getTimestamp() const;
00059
00060
00061 bool operator>(const ScoreChange&);
00062
00063
00064 bool operator<(const ScoreChange&);
00065
00066
00067 bool operator==(const ScoreChange&);
00068
00069
00070 bool operator!=(const ScoreChange&);
00071
00072
00073 friend class ScoreKeeper;
00074
00075 KoduActionScore::ScoringType_t operationType;
00076 std::string designator;
00077 unsigned int value;
00078
00079 private:
00080 Timestamp_t timeCreated;
00081 };
00082
00083
00084 class ScoreKeeper {
00085 public:
00086
00087 ScoreKeeper()
00088 : scoreBoard()
00089 { }
00090
00091
00092 ~ScoreKeeper() {
00093 scoreBoard.clear();
00094 }
00095
00096
00097 ScoreKeeper& operator=(const ScoreKeeper& kKeeper) {
00098 if (this != &kKeeper) {
00099 scoreBoard = kKeeper.scoreBoard;
00100 }
00101 return *this;
00102 }
00103
00104
00105 int addScore(const std::string&, int);
00106
00107
00108 int checkScoreValue(const std::string&);
00109
00110
00111 void initialize();
00112
00113
00114 bool registerScore(const std::string&);
00115
00116
00117 bool scoreExists(const std::string&);
00118
00119
00120 int setScore(const std::string&, int);
00121
00122
00123 int subtractScore(const std::string&, int);
00124
00125 private:
00126
00127 DISALLOW_COPY(ScoreKeeper);
00128
00129
00130 std::map<std::string, int> scoreBoard;
00131 };
00132
00133 }
00134
00135 #endif // SCORE_KEEPER_H_