stmm-games-doc  0.32.0
Classes | Public Member Functions | List of all members
stmg::RandomParts< T > Class Template Reference
Inheritance diagram for stmg::RandomParts< T >:
Inheritance graph
[legend]

Public Member Functions

 RandomParts () noexcept
 
void clear () noexcept
 Removes all parts. More...
 
int32_t addRandomPart (int32_t nProb, const T &oData) noexcept
 Adds a random part. More...
 
int32_t addRandomPart (int32_t nProb, T &&oData) noexcept
 Adds a random part. More...
 
T & getRandomPart (int32_t nIdx) noexcept
 Get random part object. More...
 
T & getRandomPart (int32_t nIdx, int32_t &nProb) noexcept
 Get random part object and info. More...
 
T & getRandomPart (int32_t nIdx, int32_t &nProb, int32_t &nPrecProb) noexcept
 Get random part object and info. More...
 
int32_t getTotRandomParts () const noexcept
 The number of added parts. More...
 
int32_t getRandomRange () const noexcept
 The sum of all the parts weights. More...
 
int32_t getRandomPartProbIdx (int32_t nRandom) noexcept
 
T & getRandomPartProb (int32_t nRandom, int32_t &nIdx, int32_t &nRel) noexcept
 Get the part given the probability. More...
 
T & getRandomPartProb (int32_t nRandom, int32_t &nIdx) noexcept
 Get the part given the probability. More...
 
T & getRandomPartProb (int32_t nRandom) noexcept
 Get the part given the probability. More...
 

Constructor & Destructor Documentation

◆ RandomParts()

template<class T>
stmg::RandomParts< T >::RandomParts ( )
inlinenoexcept

Member Function Documentation

◆ addRandomPart() [1/2]

template<class T>
int32_t stmg::RandomParts< T >::addRandomPart ( int32_t  nProb,
const T &  oData 
)
inlinenoexcept

Adds a random part.

Parameters
nProbThe weight of the part (must be non negative).
oDataThe associated data. A copy is made.
Returns
The index of the added part.

◆ addRandomPart() [2/2]

template<class T>
int32_t stmg::RandomParts< T >::addRandomPart ( int32_t  nProb,
T &&  oData 
)
inlinenoexcept

Adds a random part.

Parameters
nProbThe weight of the part (must be non negative).
oDataThe associated data.
Returns
The index of the added part.

◆ clear()

template<class T>
void stmg::RandomParts< T >::clear ( )
inlinenoexcept

Removes all parts.

◆ getRandomPart() [1/3]

template<class T>
T& stmg::RandomParts< T >::getRandomPart ( int32_t  nIdx)
inlinenoexcept

Get random part object.

Parameters
nIdxThe index of the random part. Must be >= 0 and < getTotRandomParts().
Returns
The object associated with the part.

◆ getRandomPart() [2/3]

template<class T>
T& stmg::RandomParts< T >::getRandomPart ( int32_t  nIdx,
int32_t &  nProb 
)
inlinenoexcept

Get random part object and info.

Parameters
nIdxThe index of the random part. Must be >= 0 and < getTotRandomParts().
nProb[output] The weight of the part.
Returns
The object associated with the part.

◆ getRandomPart() [3/3]

template<class T>
T& stmg::RandomParts< T >::getRandomPart ( int32_t  nIdx,
int32_t &  nProb,
int32_t &  nPrecProb 
)
inlinenoexcept

Get random part object and info.

Parameters
nIdxThe index of the random part. Must be >= 0 and < getTotRandomParts().
nProb[output] The weight of the part.
nPrecProb[output] The sum of the weights of the preceding parts.
Returns
The object associated with the part.

◆ getRandomPartProb() [1/3]

template<class T>
T& stmg::RandomParts< T >::getRandomPartProb ( int32_t  nRandom,
int32_t &  nIdx,
int32_t &  nRel 
)
inlinenoexcept

Get the part given the probability.

nRel is set by this function to the value relative to the part 0 .. nProb-1, where nProb is what is returned by getRandomPart(nIdx, nProb)

Parameters
nRandomThe probability. Must be >= 0 and < getRandomRange().
nIdx[output] The index of the selected part.
nRel[output] The probability within the weight of the part.
Returns
The object associated with the selected part.

◆ getRandomPartProb() [2/3]

template<class T>
T& stmg::RandomParts< T >::getRandomPartProb ( int32_t  nRandom,
int32_t &  nIdx 
)
inlinenoexcept

Get the part given the probability.

Parameters
nRandomThe probability. Must be >= 0 and < getRandomRange().
nIdx[output] The index of the selected part.
Returns
The object associated with the selected part.

◆ getRandomPartProb() [3/3]

template<class T>
T& stmg::RandomParts< T >::getRandomPartProb ( int32_t  nRandom)
inlinenoexcept

Get the part given the probability.

Parameters
nRandomThe probability. Must be >= 0 and < getRandomRange().
Returns
The object associated with the selected part.

◆ getRandomPartProbIdx()

template<class T>
int32_t stmg::RandomParts< T >::getRandomPartProbIdx ( int32_t  nRandom)
inlinenoexcept

◆ getRandomRange()

template<class T>
int32_t stmg::RandomParts< T >::getRandomRange ( ) const
inlinenoexcept

The sum of all the parts weights.

Returns
The total weight.

◆ getTotRandomParts()

template<class T>
int32_t stmg::RandomParts< T >::getTotRandomParts ( ) const
inlinenoexcept

The number of added parts.

Returns
The total number of parts.