whatsnew.hpp 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. /*
  2. * Copyright (c) 2023 Dennis Sädtler <[email protected]>
  3. *
  4. * Permission to use, copy, modify, and distribute this software for any
  5. * purpose with or without fee is hereby granted, provided that the above
  6. * copyright notice and this permission notice appear in all copies.
  7. *
  8. * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
  9. * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
  10. * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
  11. * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
  12. * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
  13. * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
  14. * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  15. */
  16. #pragma once
  17. #include <string>
  18. #include <optional>
  19. #include <nlohmann/json.hpp>
  20. /* Ubuntu 22.04 be damned. */
  21. #ifndef NLOHMANN_DEFINE_TYPE_INTRUSIVE_WITH_DEFAULT
  22. #define NLOHMANN_JSON_FROM_WITH_DEFAULT(v1) \
  23. nlohmann_json_t.v1 = \
  24. nlohmann_json_j.value(#v1, nlohmann_json_default_obj.v1);
  25. #define NLOHMANN_DEFINE_TYPE_INTRUSIVE_WITH_DEFAULT(Type, ...) \
  26. friend void to_json(nlohmann::json &nlohmann_json_j, \
  27. const Type &nlohmann_json_t) \
  28. { \
  29. NLOHMANN_JSON_EXPAND( \
  30. NLOHMANN_JSON_PASTE(NLOHMANN_JSON_TO, __VA_ARGS__)) \
  31. } \
  32. friend void from_json(const nlohmann::json &nlohmann_json_j, \
  33. Type &nlohmann_json_t) \
  34. { \
  35. Type nlohmann_json_default_obj; \
  36. NLOHMANN_JSON_EXPAND(NLOHMANN_JSON_PASTE( \
  37. NLOHMANN_JSON_FROM_WITH_DEFAULT, __VA_ARGS__)) \
  38. }
  39. #endif
  40. /*
  41. * Support for (de-)serialising std::optional
  42. * Adapted from https://github.com/nlohmann/json/issues/1749#issuecomment-1555093802
  43. */
  44. template<typename T> struct nlohmann::adl_serializer<std::optional<T>> {
  45. static std::optional<T> from_json(const json &json)
  46. {
  47. return json.is_null() ? std::nullopt
  48. : std::optional{json.get<T>()};
  49. }
  50. static void to_json(json &json, std::optional<T> t)
  51. {
  52. if (t)
  53. json = *t;
  54. else
  55. json = nullptr;
  56. }
  57. };
  58. struct WhatsNewPlatforms {
  59. bool windows = false;
  60. bool macos = false;
  61. bool linux = false;
  62. NLOHMANN_DEFINE_TYPE_INTRUSIVE_WITH_DEFAULT(WhatsNewPlatforms, windows,
  63. macos, linux)
  64. };
  65. struct WhatsNewItem {
  66. /* Target OBS version (patch is ignored) */
  67. std::string version;
  68. /* Beta/RC release to target */
  69. int Beta = 0;
  70. int RC = 0;
  71. /* URL of webpage to be displayed */
  72. std::string url;
  73. /* Increment for this version's item */
  74. int increment = 0;
  75. /* Optional OS filter */
  76. std::optional<WhatsNewPlatforms> os = std::nullopt;
  77. NLOHMANN_DEFINE_TYPE_INTRUSIVE_WITH_DEFAULT(WhatsNewItem, version, Beta,
  78. RC, url, increment, os)
  79. };
  80. using WhatsNewList = std::vector<WhatsNewItem>;