Cuberite
A lightweight, fast and extensible game server for Minecraft
|
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 AString & | value (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, AString > | mState |
The state, represented as a string->string map. More... | |
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.
BlockState::BlockState | ( | ) |
Creates a new instance with an empty map.
Definition at line 8 of file BlockState.cpp.
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::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.
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.
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::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::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.
|
inlineconstexpr |
Definition at line 7 of file BlockState.h.
|
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.
|
inline |
Definition at line 20 of file BlockState.h.
|
inline |
Fast inequality check.
Definition at line 62 of file BlockState.h.
bool BlockState::operator< | ( | const BlockState & | aOther | ) | const |
Less-than comparison.
Definition at line 86 of file BlockState.cpp.
|
inline |
Definition at line 15 of file BlockState.h.
bool BlockState::operator== | ( | const BlockState & | aOther | ) | const |
Fast equality check.
Definition at line 132 of file BlockState.cpp.
Calculates the partial checksum of a single string.
Used from within initializeChecksum().
Definition at line 201 of file BlockState.cpp.
|
protected |
Removes all the keys from mState that have an empty value.
Definition at line 182 of file BlockState.cpp.
BlockType BlockState::Type | ( | ) | const |
Gets the block type of this block state.
Definition at line 12882 of file BlockStates.cpp.
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.
uint_least16_t BlockState::ID |
The state ID of the block state.
Definition at line 26 of file BlockState.h.
|
protected |
The checksum used for the fast equality check.
This is calculated upon creation.
Definition at line 79 of file BlockState.h.
The state, represented as a string->string map.
Definition at line 75 of file BlockState.h.