Cuberite
A lightweight, fast and extensible game server for Minecraft
BlockState.h
Go to the documentation of this file.
1 #pragma once
2 
3 #include <initializer_list>
4 
5 
6 
7 
8 
20 {
21 public:
22 
24  BlockState();
25 
28  BlockState(const AString & aKey, const AString & aValue);
29 
32  BlockState(std::initializer_list<std::pair<const AString, AString>> aKeysAndValues);
33 
37  BlockState(const std::map<AString, AString> & aKeysAndValues);
38 
41  BlockState(std::map<AString, AString> && aKeysAndValues);
42 
47  BlockState(const BlockState & aCopyFrom, std::initializer_list<std::pair<const AString, AString>> aAdditionalKeysAndValues);
48 
53  BlockState(const BlockState & aCopyFrom, const std::map<AString, AString> & aAdditionalKeysAndValues);
54 
56  bool operator <(const BlockState & aOther) const;
57 
59  bool operator ==(const BlockState & aOther) const;
60 
62  bool operator !=(const BlockState & aOther) const
63  {
64  return !(operator ==(aOther));
65  }
66 
69  const AString & value(const AString & aKey) const;
70 
71 
72 protected:
73 
75  std::map<AString, AString> mState;
76 
80 
81 
86 
88  void removeEmptyKeys();
89 
92  UInt32 partialChecksum(const AString & aString);
93 };
unsigned int UInt32
Definition: Globals.h:157
std::string AString
Definition: StringUtils.h:11
Represents the state of a single block (previously known as "block meta").
Definition: BlockState.h:20
UInt32 partialChecksum(const AString &aString)
Calculates the partial checksum of a single string.
Definition: BlockState.cpp:201
BlockState()
Creates a new instance with an empty map.
Definition: BlockState.cpp:8
bool operator<(const BlockState &aOther) const
Less-than comparison.
Definition: BlockState.cpp:86
bool operator!=(const BlockState &aOther) const
Fast inequality check.
Definition: BlockState.h:62
UInt32 initializeChecksum()
Normalizes mState and calculates the checksum from it.
Definition: BlockState.cpp:163
const AString & value(const AString &aKey) const
Returns the value at the specified key.
Definition: BlockState.cpp:148
UInt32 mChecksum
The checksum used for the fast equality check.
Definition: BlockState.h:79
bool operator==(const BlockState &aOther) const
Fast equality check.
Definition: BlockState.cpp:132
void removeEmptyKeys()
Removes all the keys from mState that have an empty value.
Definition: BlockState.cpp:182
std::map< AString, AString > mState
The state, represented as a string->string map.
Definition: BlockState.h:75