metadata.h 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. /*
  2. Minetest
  3. Copyright (C) 2010-2013 celeron55, Perttu Ahola <celeron55@gmail.com>
  4. This program is free software; you can redistribute it and/or modify
  5. it under the terms of the GNU Lesser General Public License as published by
  6. the Free Software Foundation; either version 2.1 of the License, or
  7. (at your option) any later version.
  8. This program is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. GNU Lesser General Public License for more details.
  12. You should have received a copy of the GNU Lesser General Public License along
  13. with this program; if not, write to the Free Software Foundation, Inc.,
  14. 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  15. */
  16. #pragma once
  17. #include "irr_v3d.h"
  18. #include <iostream>
  19. #include <vector>
  20. #include "util/string.h"
  21. class Metadata
  22. {
  23. bool m_modified = false;
  24. public:
  25. virtual ~Metadata() = default;
  26. virtual void clear();
  27. virtual bool empty() const;
  28. bool operator==(const Metadata &other) const;
  29. inline bool operator!=(const Metadata &other) const
  30. {
  31. return !(*this == other);
  32. }
  33. //
  34. // Key-value related
  35. //
  36. size_t size() const;
  37. bool contains(const std::string &name) const;
  38. const std::string &getString(const std::string &name, u16 recursion = 0) const;
  39. bool getStringToRef(const std::string &name, std::string &str, u16 recursion = 0) const;
  40. virtual bool setString(const std::string &name, const std::string &var);
  41. inline bool removeString(const std::string &name) { return setString(name, ""); }
  42. const StringMap &getStrings() const
  43. {
  44. return m_stringvars;
  45. }
  46. // Add support for variable names in values
  47. const std::string &resolveString(const std::string &str, u16 recursion = 0) const;
  48. inline bool isModified() const { return m_modified; }
  49. inline void setModified(bool v) { m_modified = v; }
  50. protected:
  51. StringMap m_stringvars;
  52. };