summaryrefslogtreecommitdiffstats
path: root/src/MemorySettingsRepository.h
diff options
context:
space:
mode:
authorHaoTNN <haotnn@gmail.com>2015-05-19 23:22:27 +0200
committerHaoTNN <haotnn@gmail.com>2015-05-19 23:22:27 +0200
commitac1bfd967153cee45b1ffc93655fbb4833faa531 (patch)
tree7ca3aef2a46a272ae815912af66dea0afe06e63b /src/MemorySettingsRepository.h
parentFixes lit furnace issue in #2051 (diff)
parentMerge pull request #2076 from mc-server/Cert-disable (diff)
downloadcuberite-ac1bfd967153cee45b1ffc93655fbb4833faa531.tar
cuberite-ac1bfd967153cee45b1ffc93655fbb4833faa531.tar.gz
cuberite-ac1bfd967153cee45b1ffc93655fbb4833faa531.tar.bz2
cuberite-ac1bfd967153cee45b1ffc93655fbb4833faa531.tar.lz
cuberite-ac1bfd967153cee45b1ffc93655fbb4833faa531.tar.xz
cuberite-ac1bfd967153cee45b1ffc93655fbb4833faa531.tar.zst
cuberite-ac1bfd967153cee45b1ffc93655fbb4833faa531.zip
Diffstat (limited to 'src/MemorySettingsRepository.h')
-rw-r--r--src/MemorySettingsRepository.h80
1 files changed, 80 insertions, 0 deletions
diff --git a/src/MemorySettingsRepository.h b/src/MemorySettingsRepository.h
new file mode 100644
index 000000000..335bc4513
--- /dev/null
+++ b/src/MemorySettingsRepository.h
@@ -0,0 +1,80 @@
+
+#pragma once
+
+#include "SettingsRepositoryInterface.h"
+
+#include <unordered_map>
+
+class cMemorySettingsRepository : public cSettingsRepositoryInterface
+{
+public:
+
+ virtual bool KeyExists(const AString keyname) const override;
+
+ virtual bool HasValue(const AString & a_KeyName, const AString & a_ValueName) const override;
+
+ virtual int AddKeyName(const AString & keyname) override;
+
+ virtual bool AddKeyComment(const AString & keyname, const AString & comment) override;
+
+ virtual AString GetKeyComment(const AString & keyname, const int commentID) const override;
+
+ virtual bool DeleteKeyComment(const AString & keyname, const int commentID) override;
+
+ virtual void AddValue (const AString & a_KeyName, const AString & a_ValueName, const AString & a_Value) override;
+ void AddValue (const AString & a_KeyName, const AString & a_ValueName, const Int64 a_Value);
+ void AddValue (const AString & a_KeyName, const AString & a_ValueName, const bool a_Value);
+
+ virtual std::vector<std::pair<AString, AString>> GetValues(AString a_keyName) override;
+
+ virtual AString GetValue (const AString & keyname, const AString & valuename, const AString & defValue = "") const override;
+
+
+ virtual AString GetValueSet (const AString & keyname, const AString & valuename, const AString & defValue = "") override;
+ virtual int GetValueSetI(const AString & keyname, const AString & valuename, const int defValue = 0) override;
+ virtual Int64 GetValueSetI(const AString & keyname, const AString & valuename, const Int64 defValue = 0) override;
+ virtual bool GetValueSetB(const AString & keyname, const AString & valuename, const bool defValue = false) override;
+
+ virtual bool SetValue (const AString & a_KeyName, const AString & a_ValueName, const AString & a_Value, const bool a_CreateIfNotExists = true) override;
+ virtual bool SetValueI(const AString & a_KeyName, const AString & a_ValueName, const int a_Value, const bool a_CreateIfNotExists = true) override;
+
+ virtual bool DeleteValue(const AString & keyname, const AString & valuename) override;
+
+ virtual bool Flush() override;
+
+ void SetReadOnly()
+ {
+ m_Writable = false;
+ }
+
+private:
+
+ bool m_Writable = true;
+
+ struct sValue
+ {
+ sValue(AString value) : m_Type(eType::String), m_stringValue (value) {}
+ sValue(Int64 value) : m_Type(eType::Int64), m_intValue(value) {}
+ sValue(bool value) : m_Type(eType::Bool), m_boolValue(value) {}
+
+ AString getStringValue() const { ASSERT(m_Type == eType::String); return m_stringValue; }
+ Int64 getIntValue() const { ASSERT(m_Type == eType::Int64); return m_intValue; }
+ bool getBoolValue() const { ASSERT(m_Type == eType::Bool); return m_boolValue; }
+ private:
+ enum class eType
+ {
+ String,
+ Int64,
+ Bool
+ } m_Type;
+ AString m_stringValue;
+ union
+ {
+ Int64 m_intValue;
+ bool m_boolValue;
+ };
+ };
+
+ std::unordered_map<AString, std::unordered_multimap<AString, sValue>> m_Map{};
+};
+