value_initializer.h 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. /*
  2. * libnbt++ - A library for the Minecraft Named Binary Tag format.
  3. * Copyright (C) 2013, 2015 ljfa-ag
  4. *
  5. * This file is part of libnbt++.
  6. *
  7. * libnbt++ is free software: you can redistribute it and/or modify
  8. * it under the terms of the GNU Lesser General Public License as published by
  9. * the Free Software Foundation, either version 3 of the License, or
  10. * (at your option) any later version.
  11. *
  12. * libnbt++ is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU Lesser General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU Lesser General Public License
  18. * along with libnbt++. If not, see <http://www.gnu.org/licenses/>.
  19. */
  20. #ifndef VALUE_INITIALIZER_H_INCLUDED
  21. #define VALUE_INITIALIZER_H_INCLUDED
  22. #include "value.h"
  23. namespace nbt
  24. {
  25. /**
  26. * @brief Helper class for implicitly constructing value objects
  27. *
  28. * This type is a subclass of @ref value. However the only difference to value
  29. * is that this class has additional constructors which allow implicit
  30. * conversion of various types to value objects. These constructors are not
  31. * part of the value class itself because implicit conversions like this
  32. * (especially from @c tag&& to @c value) can cause problems and ambiguities
  33. * in some cases.
  34. *
  35. * value_initializer is especially useful as function parameter type, it will
  36. * allow convenient conversion of various values to tags on function call.
  37. *
  38. * As value_initializer objects are in no way different than value objects,
  39. * they can just be converted to value after construction.
  40. */
  41. class NBT_EXPORT value_initializer : public value
  42. {
  43. public:
  44. value_initializer(std::unique_ptr<tag>&& t) noexcept: value(std::move(t)) {}
  45. value_initializer(std::nullptr_t) noexcept : value(nullptr) {}
  46. value_initializer(value&& val) noexcept : value(std::move(val)) {}
  47. value_initializer(tag&& t) : value(std::move(t)) {}
  48. value_initializer(int8_t val);
  49. value_initializer(int16_t val);
  50. value_initializer(int32_t val);
  51. value_initializer(int64_t val);
  52. value_initializer(float val);
  53. value_initializer(double val);
  54. value_initializer(const std::string& str);
  55. value_initializer(std::string&& str);
  56. value_initializer(const char* str);
  57. };
  58. }
  59. #endif // VALUE_INITIALIZER_H_INCLUDED