tag_int_array.h 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  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_INT_ARRAY_H_INCLUDED
  17. #define TAG_INT_ARRAY_H_INCLUDED
  18. #include "tag_base.h"
  19. #include <vector>
  20. namespace nbt
  21. {
  22. ///Contains an array of signed 32-bit integers.
  23. class tag_int_array : public tag
  24. {
  25. public:
  26. ///The type of the tag.
  27. static constexpr tag_type type = tag_type::_int_array;
  28. ///Default constructor
  29. tag_int_array() {}
  30. ///Vector-copy constructor
  31. explicit tag_int_array(const std::vector<int32_t>& v): data(v) {}
  32. ///Vector-move constructor
  33. explicit tag_int_array(std::vector<int32_t>&& v): data(std::move(v)) {}
  34. ///Fill constructor
  35. explicit tag_int_array(uint32_t len, int32_t val = 0): data(len, val) {}
  36. ///Range constructor
  37. template<class InputIt> tag_int_array(InputIt first, InputIt last): data(first, last) {}
  38. ///Initializer-list constructor
  39. tag_int_array(std::initializer_list<int32_t> il): data(il) {}
  40. tag_type get_type() const noexcept { return type; }
  41. void print(std::ostream& os) const
  42. { os << "int_array(" << data.size() << ')'; }
  43. ///Returns the number of bytes contained.
  44. uint32_t size() const noexcept { return data.size(); }
  45. ///The data array.
  46. std::vector<int32_t> data;
  47. protected:
  48. void write_payload(std::ostream& os) const;
  49. };
  50. }
  51. #endif // TAG_INT_ARRAY_H_INCLUDED