Cuberite
A lightweight, fast and extensible game server for Minecraft
MemorySettingsRepository.h
Go to the documentation of this file.
1 
2 #pragma once
3 
5 
7 {
8 public:
9 
10  virtual bool KeyExists(const AString keyname) const override;
11 
12  virtual bool HasValue(const AString & a_KeyName, const AString & a_ValueName) const override;
13 
14  virtual int AddKeyName(const AString & keyname) override;
15 
16  virtual bool AddKeyComment(const AString & keyname, const AString & comment) override;
17 
18  virtual AString GetKeyComment(const AString & keyname, const int commentID) const override;
19 
20  virtual bool DeleteKeyComment(const AString & keyname, const int commentID) override;
21 
22  virtual void AddValue (const AString & a_KeyName, const AString & a_ValueName, const AString & a_Value) override;
23  void AddValue (const AString & a_KeyName, const AString & a_ValueName, const Int64 a_Value);
24  void AddValue (const AString & a_KeyName, const AString & a_ValueName, const bool a_Value);
25 
26  virtual std::vector<std::pair<AString, AString>> GetValues(AString a_keyName) override;
27 
28  virtual AString GetValue (const AString & keyname, const AString & valuename, const AString & defValue = "") const override;
29 
30 
31  virtual AString GetValueSet (const AString & keyname, const AString & valuename, const AString & defValue = "") override;
32  virtual int GetValueSetI(const AString & keyname, const AString & valuename, const int defValue = 0) override;
33  virtual Int64 GetValueSetI(const AString & keyname, const AString & valuename, const Int64 defValue = 0) override;
34  virtual bool GetValueSetB(const AString & keyname, const AString & valuename, const bool defValue = false) override;
35 
36  virtual bool SetValue (const AString & a_KeyName, const AString & a_ValueName, const AString & a_Value, const bool a_CreateIfNotExists = true) override;
37  virtual bool SetValueI(const AString & a_KeyName, const AString & a_ValueName, const int a_Value, const bool a_CreateIfNotExists = true) override;
38 
39  virtual bool DeleteValue(const AString & keyname, const AString & valuename) override;
40 
41  virtual bool Flush() override;
42 
43  void SetReadOnly()
44  {
45  m_Writable = false;
46  }
47 
48 private:
49 
50  bool m_Writable = true;
51 
52  struct sValue
53  {
54  sValue(AString value):
55  #ifndef NDEBUG
57  #endif
58  m_stringValue (std::move(value))
59  {
60  }
61 
62  sValue(Int64 value):
63  #ifndef NDEBUG
64  m_Type(eType::Int64),
65  #endif
66  m_intValue(value)
67  {
68  }
69 
70  sValue(bool value):
71  #ifndef NDEBUG
72  m_Type(eType::Bool),
73  #endif
74  m_boolValue(value)
75  {
76  }
77 
80  bool getBoolValue() const { ASSERT(m_Type == eType::Bool); return m_boolValue; }
81 
82  private:
83 
84  #ifndef NDEBUG
85  enum class eType
86  {
87  String,
88  Int64,
89  Bool
90  } m_Type;
91  #endif
92 
94  union
95  {
98  };
99  };
100 
101  std::unordered_map<AString, std::unordered_multimap<AString, sValue>> m_Map{};
102 };
103 
signed long long Int64
Definition: Globals.h:151
#define ASSERT(x)
Definition: Globals.h:276
@ String
std::string AString
Definition: StringUtils.h:11
Definition: FastNBT.h:132
virtual AString GetValue(const AString &keyname, const AString &valuename, const AString &defValue="") const override
Get the value at the specified key and value, returns defValue on failure.
virtual bool DeleteValue(const AString &keyname, const AString &valuename) override
Deletes the specified key, value pair.
virtual AString GetKeyComment(const AString &keyname, const int commentID) const override
Return a key comment, returns "" for repositories that do not return comments.
virtual bool GetValueSetB(const AString &keyname, const AString &valuename, const bool defValue=false) override
virtual int AddKeyName(const AString &keyname) override
Add a key name.
virtual std::vector< std::pair< AString, AString > > GetValues(AString a_keyName) override
returns a vector containing a name, value pair for each value under the key
virtual AString GetValueSet(const AString &keyname, const AString &valuename, const AString &defValue="") override
Gets the value; if not found, write the default to the repository.
virtual void AddValue(const AString &a_KeyName, const AString &a_ValueName, const AString &a_Value) override
Adds a new value to the specified key.
virtual int GetValueSetI(const AString &keyname, const AString &valuename, const int defValue=0) override
virtual bool Flush() override
Writes the changes to the backing store, if the repository has one.
virtual bool SetValue(const AString &a_KeyName, const AString &a_ValueName, const AString &a_Value, const bool a_CreateIfNotExists=true) override
Overwrites the value of the key, value pair Specify the optional parameter as false if you do not wan...
virtual bool AddKeyComment(const AString &keyname, const AString &comment) override
Add a key comment, will always fail if the repository does not support comments.
virtual bool DeleteKeyComment(const AString &keyname, const int commentID) override
Delete a key comment, will always fail if the repository does not support comments.
virtual bool SetValueI(const AString &a_KeyName, const AString &a_ValueName, const int a_Value, const bool a_CreateIfNotExists=true) override
virtual bool HasValue(const AString &a_KeyName, const AString &a_ValueName) const override
Returns true iff the specified value exists.
virtual bool KeyExists(const AString keyname) const override
Returns true iff the specified key exists.
std::unordered_map< AString, std::unordered_multimap< AString, sValue > > m_Map
enum cMemorySettingsRepository::sValue::eType m_Type