stmm-games-doc  0.32.0
Classes | Public Member Functions | Protected Member Functions | List of all members
stmg::Highscore Class Reference

Class the holds highscores. More...

Classes

struct  Score
 

Public Member Functions

 Highscore (const shared_ptr< HighscoresDefinition > &refHighscoresDefinition, const std::string &sCodeString, const std::string &sTitleString) noexcept
 Constructor. More...
 
 Highscore (const shared_ptr< HighscoresDefinition > &refHighscoresDefinition, const std::string &sCodeString, const std::string &sTitleString, const std::vector< Score > &aScores) noexcept
 Constructor. More...
 
const shared_ptr< HighscoresDefinition > & getHighscoresDefinition () const noexcept
 The HighscoresDefinition this Highscore is based on. More...
 
const std::string & getCodeString () const noexcept
 The code string as passed to the constructor. More...
 
const std::string & getTitleString () const noexcept
 The title string as passed to the constructor. More...
 
int32_t getTotScores () const noexcept
 The total number of scores. More...
 
const ScoregetScore (int32_t nPosition) const noexcept
 Get the score at a given position. More...
 
void setScoreTeamName (int32_t nPosition, const std::string &sTeam) noexcept
 Override the team name of a score. More...
 
std::vector< int32_t > includeGame (const Game &oGame) noexcept
 Insert all the teams that ended the game in the highscores (if they are eligible). More...
 
std::vector< int32_t > includeGame (const Game &oGame, bool bCheckElegibility) noexcept
 Insert the teams in a game in the highscores. More...
 
int32_t positionIfIncluded (const Game &oGame, int32_t nTeam) const noexcept
 Get the position of a team if it were included in the highscores. More...
 

Protected Member Functions

void reInit (const shared_ptr< HighscoresDefinition > &refHighscoresDefinition, const std::string &sCodeString, const std::string &sTitleString) noexcept
 See constructor. More...
 
void reInit (const shared_ptr< HighscoresDefinition > &refHighscoresDefinition, const std::string &sCodeString, const std::string &sTitleString, const std::vector< Score > &aScores) noexcept
 See constructor. More...
 

Detailed Description

Class the holds highscores.

All position are 0 based. That is the best score has position 0, the second best has position 1 and so on.

Constructor & Destructor Documentation

◆ Highscore() [1/2]

stmg::Highscore::Highscore ( const shared_ptr< HighscoresDefinition > &  refHighscoresDefinition,
const std::string &  sCodeString,
const std::string &  sTitleString 
)
noexcept

Constructor.

Parameters
refHighscoresDefinitionThe highscore definition. Cannot be null.
sCodeStringThe code string. Must have been generated by refHighscoresDefinition or be empty.
sTitleStringThe title string. Should have been generated by refHighscoresDefinition or be empty.

◆ Highscore() [2/2]

stmg::Highscore::Highscore ( const shared_ptr< HighscoresDefinition > &  refHighscoresDefinition,
const std::string &  sCodeString,
const std::string &  sTitleString,
const std::vector< Score > &  aScores 
)
noexcept

Constructor.

Parameters
refHighscoresDefinitionThe highscore definition. Cannot be null.
sCodeStringThe code string. Must have been generated by refHighscoresDefinition.
sTitleStringThe title string. Should have been generated by refHighscoresDefinition.
aScoresThe initial scores. The team name of the scores must be defined.

Member Function Documentation

◆ getCodeString()

const std::string& stmg::Highscore::getCodeString ( ) const
inlinenoexcept

The code string as passed to the constructor.

Returns
The code string or empty.

◆ getHighscoresDefinition()

const shared_ptr<HighscoresDefinition>& stmg::Highscore::getHighscoresDefinition ( ) const
inlinenoexcept

The HighscoresDefinition this Highscore is based on.

Returns
The highscores definition. Cannot be null.

◆ getScore()

const Score& stmg::Highscore::getScore ( int32_t  nPosition) const
inlinenoexcept

Get the score at a given position.

Parameters
nPositionThe position. 0 is the top highscore.
Returns
The score.

◆ getTitleString()

const std::string& stmg::Highscore::getTitleString ( ) const
inlinenoexcept

The title string as passed to the constructor.

Returns
The title string or empty.

◆ getTotScores()

int32_t stmg::Highscore::getTotScores ( ) const
inlinenoexcept

The total number of scores.

Returns
The number of scores if the table so far.

◆ includeGame() [1/2]

std::vector<int32_t> stmg::Highscore::includeGame ( const Game oGame)
noexcept

Insert all the teams that ended the game in the highscores (if they are eligible).

Before possibly inserting the teams it sets the m_nTeam value of the existing teams to -1 so that after this call that field is only set for the teams that just played.

Parameters
oGameThe game.
Returns
The positions of the inserted new scores. The top position is 0.

◆ includeGame() [2/2]

std::vector<int32_t> stmg::Highscore::includeGame ( const Game oGame,
bool  bCheckElegibility 
)
noexcept

Insert the teams in a game in the highscores.

Before possibly inserting the teams it sets the m_nTeam value of the existing teams to -1 so that after this call that field is only set for the teams that just played.

The eligibility check also includes whether a team has finished the game. This means that if you call this function when the game isn't finished yet with parameter bCheckElegibility set to true the empty vector is returned.

Parameters
oGameThe game.
bCheckElegibilityWhether to check for eligibility.
Returns
The positions of the inserted new scores. The top position is 0.

◆ positionIfIncluded()

int32_t stmg::Highscore::positionIfIncluded ( const Game oGame,
int32_t  nTeam 
) const
noexcept

Get the position of a team if it were included in the highscores.

Constraints and eligibilities are not evaluated.

Parameters
oGameThe game. Might be running.
nTeamThe team. Must be valid.
Returns
The position (starts from 0) or -1 if unknown or not good enough.

◆ reInit() [1/2]

void stmg::Highscore::reInit ( const shared_ptr< HighscoresDefinition > &  refHighscoresDefinition,
const std::string &  sCodeString,
const std::string &  sTitleString 
)
protectednoexcept

See constructor.

◆ reInit() [2/2]

void stmg::Highscore::reInit ( const shared_ptr< HighscoresDefinition > &  refHighscoresDefinition,
const std::string &  sCodeString,
const std::string &  sTitleString,
const std::vector< Score > &  aScores 
)
protectednoexcept

See constructor.

◆ setScoreTeamName()

void stmg::Highscore::setScoreTeamName ( int32_t  nPosition,
const std::string &  sTeam 
)
inlinenoexcept

Override the team name of a score.

Parameters
nPositionThe score position. Must be valid.
sTeamThe new team name. Cannot be empty.