X-Git-Url: https://git.lizzy.rs/?a=blobdiff_plain;f=src%2Fmetadata.h;h=5333f8a9d07470265bd57dcd5580b5bb6166ce8d;hb=32cb9d0828828da3068259c9e0a3c0f5da170439;hp=a96bfc408d20333850da7fb9ff4e24f69b0a3907;hpb=bbdd869d72d7b5aae2994d287f69e1c1d866f4e2;p=dragonfireclient.git diff --git a/src/metadata.h b/src/metadata.h index a96bfc408..5333f8a9d 100644 --- a/src/metadata.h +++ b/src/metadata.h @@ -17,43 +17,47 @@ with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ -#ifndef METADATA_HEADER -#define METADATA_HEADER +#pragma once #include "irr_v3d.h" #include #include #include "util/string.h" -/* - NodeMetadata stores arbitary amounts of data for special blocks. - Used for furnaces, chests and signs. - - There are two interaction methods: inventory menu and text input. - Only one can be used for a single metadata, thus only inventory OR - text input should exist in a metadata. -*/ - -class Inventory; -class IItemDefManager; - class Metadata { + bool m_modified = false; public: - void clear(); - bool empty() const; - - // Generic key/value store - std::string getString(const std::string &name, u16 recursion = 0) const; - void setString(const std::string &name, const std::string &var); - // Support variable names in values - std::string resolveString(const std::string &str, u16 recursion = 0) const; + virtual ~Metadata() = default; + + virtual void clear(); + virtual bool empty() const; + + bool operator==(const Metadata &other) const; + inline bool operator!=(const Metadata &other) const + { + return !(*this == other); + } + + // + // Key-value related + // + + size_t size() const; + bool contains(const std::string &name) const; + const std::string &getString(const std::string &name, u16 recursion = 0) const; + bool getStringToRef(const std::string &name, std::string &str, u16 recursion = 0) const; + virtual bool setString(const std::string &name, const std::string &var); + inline bool removeString(const std::string &name) { return setString(name, ""); } const StringMap &getStrings() const { return m_stringvars; } -private: + // Add support for variable names in values + const std::string &resolveString(const std::string &str, u16 recursion = 0) const; + + inline bool isModified() const { return m_modified; } + inline void setModified(bool v) { m_modified = v; } +protected: StringMap m_stringvars; }; - -#endif