tag_string.h 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. /*
  2. libnbt++ - A library for the Minecraft Named Binary Tag format.
  3. Copyright (C) 2013 ljfa-ag
  4. This file is part of libnbt++.
  5. libnbt++ is free software: you can redistribute it and/or modify
  6. it under the terms of the GNU General Public License as published by
  7. the Free Software Foundation, either version 3 of the License, or
  8. (at your option) any later version.
  9. libnbt++ is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. GNU General Public License for more details.
  13. You should have received a copy of the GNU General Public License
  14. along with libnbt++. If not, see <http://www.gnu.org/licenses/>.
  15. */
  16. #ifndef TAG_STRING_H_INCLUDED
  17. #define TAG_STRING_H_INCLUDED
  18. #include "tag_base.h"
  19. namespace nbt
  20. {
  21. ///Contains a UTF-8 string.
  22. class tag_string : public tag
  23. {
  24. public:
  25. ///The type of the tag.
  26. static constexpr tag_type type = tag_type::_string;
  27. ///Default constructor
  28. tag_string() {}
  29. ///String-copy constructor
  30. explicit tag_string(const std::string& s): str(s) {}
  31. ///String-move constructor
  32. explicit tag_string(std::string&& s): str(std::move(s)) {}
  33. tag_type get_type() const noexcept { return type; }
  34. void print(std::ostream& os) const
  35. { os << "string(\"" << str << "\")"; }
  36. ///The contained string.
  37. std::string str;
  38. protected:
  39. void write_payload(std::ostream& os) const;
  40. };
  41. }
  42. #endif // TAG_STRING_H_INCLUDED