Cuberite
A lightweight, fast and extensible game server for Minecraft
Public Member Functions | Public Attributes | Protected Member Functions | Protected Attributes | List of all members
BlockState Struct Reference

Represents the state of a single block (previously known as "block meta"). More...

#include <BlockState.h>

Public Member Functions

 BlockState ()
 Creates a new instance with an empty map. More...
 
 BlockState (const AString &aKey, const AString &aValue)
 Creates a new instance consisting of a single key-value pair. More...
 
 BlockState (const BlockState &aCopyFrom, const std::map< AString, AString > &aAdditionalKeysAndValues)
 Creates a copy of the specified BlockState with the (dynamic) additional keys and values added to it. More...
 
 BlockState (const BlockState &aCopyFrom, std::initializer_list< std::pair< const AString, AString >> aAdditionalKeysAndValues)
 Creates a copy of the specified BlockState with the (hard-coded) additional keys and values added to it. More...
 
 BlockState (const std::map< AString, AString > &aKeysAndValues)
 Creates a new instance initialized with several (dynamic) key-value pairs. More...
 
 BlockState (std::initializer_list< std::pair< const AString, AString >> aKeysAndValues)
 Creates a new instance initialized with several (hard-coded) key-value pairs. More...
 
 BlockState (std::map< AString, AString > &&aKeysAndValues)
 Creates a new instance initialized with several (dynamic) key-value pairs. More...
 
constexpr BlockState (uint_least16_t StateID)
 
bool operator!= (BlockState Block) const
 
bool operator!= (const BlockState &aOther) const
 Fast inequality check. More...
 
bool operator< (const BlockState &aOther) const
 Less-than comparison. More...
 
bool operator== (BlockState Block) const
 
bool operator== (const BlockState &aOther) const
 Fast equality check. More...
 
BlockType Type () const
 Gets the block type of this block state. More...
 
const AStringvalue (const AString &aKey) const
 Returns the value at the specified key. More...
 

Public Attributes

uint_least16_t ID
 The state ID of the block state. More...
 

Protected Member Functions

UInt32 initializeChecksum ()
 Normalizes mState and calculates the checksum from it. More...
 
UInt32 partialChecksum (const AString &aString)
 Calculates the partial checksum of a single string. More...
 
void removeEmptyKeys ()
 Removes all the keys from mState that have an empty value. More...
 

Protected Attributes

UInt32 mChecksum
 The checksum used for the fast equality check. More...
 
std::map< AString, AStringmState
 The state, represented as a string->string map. More...
 

Detailed Description

Represents the state of a single block (previously known as "block meta").

The state consists of a map of string -> string, plus a mechanism for fast equality checks between two BlockState instances. Once a BlockState instance is created, it is then immutable - there's no way of changing it, only by creating a (modified) copy. A BlockState instance can be created from hard-coded data or from dynamic data: BlockState bs({{"key1", "value1"}, {key2", "value2"}}); // Hard-coded

Definition at line 19 of file BlockState.h.

Constructor & Destructor Documentation

◆ BlockState() [1/8]

BlockState::BlockState ( )

Creates a new instance with an empty map.

Definition at line 8 of file BlockState.cpp.

◆ BlockState() [2/8]

BlockState::BlockState ( const AString aKey,
const AString aValue 
)

Creates a new instance consisting of a single key-value pair.

If the value is empty, it is not stored wihin the map.

Definition at line 18 of file BlockState.cpp.

◆ BlockState() [3/8]

BlockState::BlockState ( std::initializer_list< std::pair< const AString, AString >>  aKeysAndValues)

Creates a new instance initialized with several (hard-coded) key-value pairs.

Any key with an empty value is not stored within the map.

Definition at line 28 of file BlockState.cpp.

◆ BlockState() [4/8]

BlockState::BlockState ( const std::map< AString, AString > &  aKeysAndValues)

Creates a new instance initialized with several (dynamic) key-value pairs.

Makes a copy of aKeysAndValues for this object. Any key with an empty value is not stored within the map.

Definition at line 38 of file BlockState.cpp.

◆ BlockState() [5/8]

BlockState::BlockState ( std::map< AString, AString > &&  aKeysAndValues)

Creates a new instance initialized with several (dynamic) key-value pairs.

Any key with an empty value is not stored within the map.

Definition at line 48 of file BlockState.cpp.

◆ BlockState() [6/8]

BlockState::BlockState ( const BlockState aCopyFrom,
std::initializer_list< std::pair< const AString, AString >>  aAdditionalKeysAndValues 
)

Creates a copy of the specified BlockState with the (hard-coded) additional keys and values added to it.

Any key in aAdditionalKeysAndValues that is already present in aCopyFrom is overwritten with the aAdditionalKeysAndValues' one. Any key with an empty value is not stored in the map. (it's possible to erase a key from aCopyFrom by setting it to empty string in aAdditionalKeysAndValues).

Definition at line 58 of file BlockState.cpp.

◆ BlockState() [7/8]

BlockState::BlockState ( const BlockState aCopyFrom,
const std::map< AString, AString > &  aAdditionalKeysAndValues 
)

Creates a copy of the specified BlockState with the (dynamic) additional keys and values added to it.

Any key in aAdditionalKeysAndValues that is already present in aCopyFrom is overwritten with the aAdditionalKeysAndValues' one. Any key with an empty value is not stored in the map. (it's possible to erase a key from aCopyFrom by setting it to empty string in aAdditionalKeysAndValues).

Definition at line 72 of file BlockState.cpp.

◆ BlockState() [8/8]

constexpr BlockState::BlockState ( uint_least16_t  StateID)
inlineconstexpr

Definition at line 7 of file BlockState.h.

Member Function Documentation

◆ initializeChecksum()

UInt32 BlockState::initializeChecksum ( )
protected

Normalizes mState and calculates the checksum from it.

Removes all the empty values from mState. Used only from constructors.

Definition at line 163 of file BlockState.cpp.

◆ operator!=() [1/2]

bool BlockState::operator!= ( BlockState  Block) const
inline

Definition at line 20 of file BlockState.h.

◆ operator!=() [2/2]

bool BlockState::operator!= ( const BlockState aOther) const
inline

Fast inequality check.

Definition at line 62 of file BlockState.h.

◆ operator<()

bool BlockState::operator< ( const BlockState aOther) const

Less-than comparison.

Definition at line 86 of file BlockState.cpp.

◆ operator==() [1/2]

bool BlockState::operator== ( BlockState  Block) const
inline

Definition at line 15 of file BlockState.h.

◆ operator==() [2/2]

bool BlockState::operator== ( const BlockState aOther) const

Fast equality check.

Definition at line 132 of file BlockState.cpp.

◆ partialChecksum()

UInt32 BlockState::partialChecksum ( const AString aString)
protected

Calculates the partial checksum of a single string.

Used from within initializeChecksum().

Definition at line 201 of file BlockState.cpp.

◆ removeEmptyKeys()

void BlockState::removeEmptyKeys ( )
protected

Removes all the keys from mState that have an empty value.

Definition at line 182 of file BlockState.cpp.

◆ Type()

BlockType BlockState::Type ( ) const

Gets the block type of this block state.

Definition at line 12882 of file BlockStates.cpp.

◆ value()

const AString & BlockState::value ( const AString aKey) const

Returns the value at the specified key.

If the key is not present, returns an empty string.

Definition at line 148 of file BlockState.cpp.

Member Data Documentation

◆ ID

uint_least16_t BlockState::ID

The state ID of the block state.

Definition at line 26 of file BlockState.h.

◆ mChecksum

UInt32 BlockState::mChecksum
protected

The checksum used for the fast equality check.

This is calculated upon creation.

Definition at line 79 of file BlockState.h.

◆ mState

std::map<AString, AString> BlockState::mState
protected

The state, represented as a string->string map.

Definition at line 75 of file BlockState.h.


The documentation for this struct was generated from the following files: