Scid  4.7.0
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
Classes | Public Member Functions | Static Public Member Functions | List of all members
NameBase Class Reference

This class stores the database's names (players, events, sites and rounds). More...

#include <namebase.h>

Public Member Functions

void AddElo (idNumberT id, eloT elo)
 A NameBase stores the max ELO for each player. More...
 
std::pair< errorT, idNumberTaddName (nameT nt, const char *name, size_t MAX_LEN, idNumberT MAX_ID)
 Add a name (string) to the NameBase. More...
 
void Clear ()
 Frees memory, leaving the object empty. More...
 
std::tuple< decltype(idx_) &, decltype(names_) &, decltype(eloV_) & > getData ()
 
eloT GetElo (idNumberT id) const
 
std::vector< idNumberTgetFirstMatches (nameT nt, const char *str, size_t maxMatches) const
 Get the first few matches of a name prefix. More...
 
const char * GetName (nameT nt, idNumberT id) const
 Retrieve a name. More...
 
decltype(idx_) const & getNames () const
 
idNumberT GetNumNames (nameT nt) const
 
errorT FindExactName (nameT nt, const char *str, idNumberT *idPtr) const
 Finds an exact full, case-sensitive name. More...
 
std::vector< uint32_t > generateHashMap (nameT nt) const
 For every name generates a 32bit hash with the first 4 chars. More...
 

Static Public Member Functions

static bool IsValidNameType (nameT nt)
 Validate a nameT type. More...
 
static nameT NameTypeFromString (const char *str)
 Match a string to a nameT. More...
 

Detailed Description

This class stores the database's names (players, events, sites and rounds).

Assigns a idNumberT (which will be used as reference) to each name.

Definition at line 33 of file namebase.h.

Member Function Documentation

◆ AddElo()

void NameBase::AddElo ( idNumberT  id,
eloT  elo 
)
inline

A NameBase stores the max ELO for each player.

This functions updates the max ELO of a player if it's greater than the previous one.

Parameters
ida valid idNumberT corresponding to a NAME_PLAYER name.
elothe ELO.

Definition at line 64 of file namebase.h.

◆ addName()

std::pair<errorT, idNumberT> NameBase::addName ( nameT  nt,
const char *  name,
size_t  MAX_LEN,
idNumberT  MAX_ID 
)
inline

Add a name (string) to the NameBase.

If the name already exists the corresponding ID is returned.

Parameters
ntnameT type of the name to add.
namethe name to add.
MAX_LENthe max length for names of type nt
MAX_IDthe max ID allowed for names of type nt
Returns
  • on success, a std::pair containing OK and the ID.
  • on failure, a std::pair containing an error code and 0.

Definition at line 81 of file namebase.h.

◆ Clear()

void NameBase::Clear ( )
inline

Frees memory, leaving the object empty.

Definition at line 112 of file namebase.h.

◆ FindExactName()

errorT NameBase::FindExactName ( nameT  nt,
const char *  str,
idNumberT idPtr 
) const
inline

Finds an exact full, case-sensitive name.

Parameters
ntnameT type of the name to be searched.
strname to be be searched.
[out]idPtrpointer which will receive the ID of the name.
Returns
OK or ERROR_NameNotFound if the name does not exists.

Definition at line 190 of file namebase.h.

◆ generateHashMap()

std::vector<uint32_t> NameBase::generateHashMap ( nameT  nt) const
inline

For every name generates a 32bit hash with the first 4 chars.

Parameters
ntnameT type of the names.
Returns
a vector containing the hashes.

Definition at line 206 of file namebase.h.

◆ getData()

std::tuple<decltype(idx_) &, decltype(names_) &, decltype(eloV_) &> NameBase::getData ( )
inline
Returns
references to the NameBase's containers. (must be used only to read names from files)

Definition at line 119 of file namebase.h.

◆ GetElo()

eloT NameBase::GetElo ( idNumberT  id) const
inline
Parameters
ida valid idNumberT corresponding to a NAME_PLAYER name.
Returns
the max ELO of a player.

Definition at line 128 of file namebase.h.

◆ getFirstMatches()

std::vector<idNumberT> NameBase::getFirstMatches ( nameT  nt,
const char *  str,
size_t  maxMatches 
) const
inline

Get the first few matches of a name prefix.

Parameters
ntnameT type of the name to be searched.
strname prefix be searched.
maxMatchesthe max number of ID to return
Returns
a vector containing the ID of the matching names.

Definition at line 140 of file namebase.h.

◆ GetName()

const char* NameBase::GetName ( nameT  nt,
idNumberT  id 
) const
inline

Retrieve a name.

Parameters
ntthe valid nameT type of the name to retrieve.
idthe valid ID of the name to retrieve.
Returns
the name corresponding to id.

Definition at line 162 of file namebase.h.

◆ getNames()

decltype(idx_) const& NameBase::getNames ( ) const
inline
Returns
a reference to a container with all the names and IDs (given as std::pair<const char*, idNumberT>).

Definition at line 171 of file namebase.h.

◆ GetNumNames()

idNumberT NameBase::GetNumNames ( nameT  nt) const
inline
Parameters
nta valid nameT type.
Returns
the first invalid idNumberT (which is equal to the number of names stored).

Definition at line 178 of file namebase.h.

◆ IsValidNameType()

static bool NameBase::IsValidNameType ( nameT  nt)
inlinestatic

Validate a nameT type.

Parameters
ntnameT type to be validated.
Returns
true if nt is valid.

Definition at line 220 of file namebase.h.

◆ NameTypeFromString()

static nameT NameBase::NameTypeFromString ( const char *  str)
inlinestatic

Match a string to a nameT.

To match, the string should be a prefix of "player", "event", "site" or "round", or be a superstring of it, e.g. "player ...."

Parameters
strthe string to be matched.
Returns
a valid nameT, or NAME_INVALID.

Definition at line 229 of file namebase.h.


The documentation for this class was generated from the following file: