// To parse this JSON data, first install // // json.hpp https://github.com/nlohmann/json // // Then include this file, and then do // // BaseCategories data = nlohmann::json::parse(jsonString); #pragma once #include "json.hpp" #include #include #include #ifndef NLOHMANN_OPT_HELPER #define NLOHMANN_OPT_HELPER namespace nlohmann { template struct adl_serializer> { static void to_json(json &j, const std::shared_ptr &opt) { if (!opt) j = nullptr; else j = *opt; } static std::shared_ptr from_json(const json &j) { if (j.is_null()) return std::unique_ptr(); else return std::unique_ptr(new T(j.get())); } }; } // namespace nlohmann #endif namespace VersionCheck { using nlohmann::json; #ifndef NLOHMANN_UNTYPED_VersionCheck_HELPERHELPER #define NLOHMANN_UNTYPED_VersionCheck_HELPERHELPER inline json get_untyped(const json &j, const char *property) { if (j.find(property) != j.end()) { return j.at(property).get(); } return json(); } inline json get_untyped(const json &j, std::string property) { return get_untyped(j, property.data()); } #endif #ifndef NLOHMANN_OPTIONAL_VersionCheck_ #define NLOHMANN_OPTIONAL_VersionCheck_ template inline std::shared_ptr get_optional(const json &j, const char *property) { if (j.find(property) != j.end()) { return j.at(property).get>(); } return std::shared_ptr(); } template inline std::shared_ptr get_optional(const json &j, std::string property) { return get_optional(j, property.data()); } #endif enum class FileStatus : int { Latest, Missing, Outdated, UnknownFile, Newer, Error }; enum class RepoStatus : int { Latest, Dirty, Missing }; enum class PackageStatus : int { Latest, Dirty, Missing }; class AssetFile { public: AssetFile() = default; virtual ~AssetFile() = default; private: std::string path; std::string sha1; public: const std::string &getPath() const { return path; } std::string &getMutablePath() { return path; } void setPath(const std::string &value) { this->path = value; } const std::string &getSha1() const { return sha1; } std::string &getMutableSha1() { return sha1; } void setSha1(const std::string &value) { this->sha1 = value; } }; class Asset { public: Asset() = default; virtual ~Asset() = default; private: int64_t id; std::string nodeId; std::string name; std::string contentType; std::string url; int64_t size; std::string createdAt; std::string updatedAt; std::string browserDownloadUrl; std::vector files; public: const int64_t &getId() const { return id; } int64_t &getMutableId() { return id; } void setId(const int64_t &value) { this->id = value; } const std::string &getNodeId() const { return nodeId; } std::string &getMutableNodeId() { return nodeId; } void setNodeId(const std::string &value) { this->nodeId = value; } const std::string &getName() const { return name; } std::string &getMutableName() { return name; } void setName(const std::string &value) { this->name = value; } const std::string &getContentType() const { return contentType; } std::string &getMutableContentType() { return contentType; } void setContentType(const std::string &value) { this->contentType = value; } const std::string &getUrl() const { return url; } std::string &getMutableUrl() { return url; } void setUrl(const std::string &value) { this->url = value; } const int64_t &getSize() const { return size; } int64_t &getMutableSize() { return size; } void setSize(const int64_t &value) { this->size = value; } const std::string &getCreatedAt() const { return createdAt; } std::string &getMutableCreatedAt() { return createdAt; } void setCreatedAt(const std::string &value) { this->createdAt = value; } const std::string &getUpdatedAt() const { return updatedAt; } std::string &getMutableUpdatedAt() { return updatedAt; } void setUpdatedAt(const std::string &value) { this->updatedAt = value; } const std::string &getBrowserDownloadUrl() const { return browserDownloadUrl; } std::string &getMutableBrowserDownloadUrl() { return browserDownloadUrl; } void setBrowserDownloadUrl(const std::string &value) { this->browserDownloadUrl = value; } const std::vector &getFiles() const { return files; } std::vector &getMutableFiles() { return files; } void setFiles(const std::vector &value) { this->files = value; } }; class Release { public: Release() = default; virtual ~Release() = default; private: int64_t id; std::string nodeId; std::string name; std::string tagName; bool prerelease; std::string targetCommitish; std::string createdAt; std::string publishedAt; public: const int64_t &getId() const { return id; } int64_t &getMutableId() { return id; } void setId(const int64_t &value) { this->id = value; } const std::string &getNodeId() const { return nodeId; } std::string &getMutableNodeId() { return nodeId; } void setNodeId(const std::string &value) { this->nodeId = value; } const std::string &getName() const { return name; } std::string &getMutableName() { return name; } void setName(const std::string &value) { this->name = value; } const std::string &getTagName() const { return tagName; } std::string &getMutableTagName() { return tagName; } void setTagName(const std::string &value) { this->tagName = value; } const bool &getPrerelease() const { return prerelease; } bool &getMutablePrerelease() { return prerelease; } void setPrerelease(const bool &value) { this->prerelease = value; } const std::string &getTargetCommitish() const { return targetCommitish; } std::string &getMutableTargetCommitish() { return targetCommitish; } void setTargetCommitish(const std::string &value) { this->targetCommitish = value; } const std::string &getCreatedAt() const { return createdAt; } std::string &getMutableCreatedAt() { return createdAt; } void setCreatedAt(const std::string &value) { this->createdAt = value; } const std::string &getPublishedAt() const { return publishedAt; } std::string &getMutablePublishedAt() { return publishedAt; } void setPublishedAt(const std::string &value) { this->publishedAt = value; } }; class RepositoryFile { public: RepositoryFile() = default; virtual ~RepositoryFile() = default; private: std::string path; std::string sha1; Asset asset; Release release; FileStatus status; public: const std::string &getPath() const { return path; } std::string &getMutablePath() { return path; } void setPath(const std::string &value) { this->path = value; } const std::string &getSha1() const { return sha1; } std::string &getMutableSha1() { return sha1; } void setSha1(const std::string &value) { this->sha1 = value; } const Asset &getAsset() const { return asset; } Asset &getMutableAsset() { return asset; } void setAsset(const Asset &value) { this->asset = value; } const Release &getRelease() const { return release; } Release &getMutableRelease() { return release; } void setRelease(const Release &value) { this->release = value; } const FileStatus &getStatus() const { return status; } FileStatus &getMutableStatus() { return status; } void setStatus(const FileStatus &value) { this->status = value; } }; class Tag { public: Tag() = default; virtual ~Tag() = default; private: std::string tagName; public: const std::string &getTagName() const { return tagName; } std::string &getMutableTagName() { return tagName; } void setTagName(const std::string &value) { this->tagName = value; } }; class Repo { public: Repo() = default; virtual ~Repo() = default; private: std::string owner; std::string repo; Tag tag; std::shared_ptr forceTag; public: const std::string &getOwner() const { return owner; } std::string &getMutableOwner() { return owner; } void setOwner(const std::string &value) { this->owner = value; } const std::string &getRepo() const { return repo; } std::string &getMutableRepo() { return repo; } void setRepo(const std::string &value) { this->repo = value; } const Tag &getTag() const { return tag; } Tag &getMutableTag() { return tag; } void setTag(const Tag &value) { this->tag = value; } std::shared_ptr getForceTag() const { return forceTag; } void setForceTag(std::shared_ptr value) { this->forceTag = value; } }; class Repository { public: Repository() = default; virtual ~Repository() = default; private: Repo repo; std::vector files; RepoStatus status; public: const Repo &getRepo() const { return repo; } Repo &getMutableRepo() { return repo; } void setRepo(const Repo &value) { this->repo = value; } const std::vector &getFiles() const { return files; } std::vector &getMutableFiles() { return files; } void setFiles(const std::vector &value) { this->files = value; } const RepoStatus &getStatus() const { return status; } RepoStatus &getMutableStatus() { return status; } void setStatus(const RepoStatus &value) { this->status = value; } size_t getFilesCount(bool onlyRequired) const { return files.size(); } }; class Package { public: Package() = default; virtual ~Package() = default; private: std::string id; std::string name; std::string description; std::vector repositories; bool required; bool preSelected; PackageStatus status; std::string lastUpdateDate; bool isSelected = false; public: const std::string &getId() const { return id; } std::string &getMutableId() { return id; } void setId(const std::string &value) { this->id = value; } const std::string &getName() const { return name; } std::string &getMutableName() { return name; } void setName(const std::string &value) { this->name = value; } const std::string &getDescription() const { return description; } std::string &getMutableDescription() { return description; } void setDescription(const std::string &value) { this->description = value; } const std::vector &getRepositories() const { return repositories; } std::vector &getMutableRepositories() { return repositories; } void setRepositories(const std::vector &value) { this->repositories = value; } const bool &getRequired() const { return required; } bool &getMutableRequired() { return required; } void setRequired(const bool &value) { this->required = value; } const bool &getPreSelected() const { return preSelected; } bool &getMutablePreSelected() { return preSelected; } void setPreSelected(const bool &value) { this->preSelected = value; } const PackageStatus &getStatus() const { return status; } PackageStatus &getMutableStatus() { return status; } void setStatus(const PackageStatus &value) { this->status = value; } const std::string &getLastUpdateDate() const { return lastUpdateDate; } std::string &getMutableLastUpdateDate() { return lastUpdateDate; } void setLastUpdateDate(const std::string &value) { this->lastUpdateDate = value; } const bool &getIsSelected() const { return this->isSelected; } void toggleSelect() { if (!required) this->isSelected = !this->isSelected; } void setSelected(const bool &value) { if (!required) this->isSelected = value; } size_t getFilesCount(bool onlyRequired) const { size_t res = 0; for (auto &repo : getRepositories()) { res += repo.getFilesCount(onlyRequired); } return res; } }; class Category { public: Category() = default; virtual ~Category() = default; private: std::string id; std::string name; std::vector packages; public: const std::string &getId() const { return id; } std::string &getMutableId() { return id; } void setId(const std::string &value) { this->id = value; } const std::string &getName() const { return name; } std::string &getMutableName() { return name; } void setName(const std::string &value) { this->name = value; } const std::vector &getPackages() const { return packages; } std::vector &getMutablePackages() { return packages; } void setPackages(const std::vector &value) { this->packages = value; } size_t getFilesCount(bool onlyRequired) const { size_t res = 0; for (auto &package : getPackages()) { res += package.getFilesCount(onlyRequired); } return res; } const size_t getPackagesCount(bool required) const { if (!required) { return packages.size(); } size_t result = 0; for (auto &cur : packages) { if (cur.getRequired()) { result++; } } return result; } }; class BaseCategory { public: BaseCategory() = default; virtual ~BaseCategory() = default; private: std::string id; std::string name; std::vector category; public: const std::string &getId() const { return id; } std::string &getMutableId() { return id; } void setId(const std::string &value) { this->id = value; } const std::string &getName() const { return name; } std::string &getMutableName() { return name; } void setName(const std::string &value) { this->name = value; } const std::vector &getCategory() const { return category; } std::vector &getMutableCategory() { return category; } void setCategory(const std::vector &value) { this->category = value; } size_t getFilesCount(bool onlyRequired) const { size_t res = 0; for (auto &cat : category) { res += cat.getFilesCount(onlyRequired); } return res; } const size_t getPackagesCount(bool required) const { size_t result = 0; for (auto &cur : category) { result += cur.getPackagesCount(required); } return result; } }; using VersionInfo = std::vector; } // namespace VersionCheck namespace VersionCheck { void from_json(const json &j, AssetFile &x); void from_json(const json &j, Asset &x); void from_json(const json &j, Release &x); void from_json(const json &j, RepositoryFile &x); void from_json(const json &j, Tag &x); void from_json(const json &j, Repo &x); void from_json(const json &j, Repository &x); void from_json(const json &j, Package &x); void from_json(const json &j, Category &x); void from_json(const json &j, BaseCategory &x); inline void from_json(const json &j, AssetFile &x) { x.setPath(j.at("path").get()); x.setSha1(j.at("sha1").get()); } inline void from_json(const json &j, Asset &x) { x.setId(j.at("id").get()); x.setNodeId(j.at("node_id").get()); x.setName(j.at("name").get()); x.setContentType(j.at("content_type").get()); x.setUrl(j.at("url").get()); x.setSize(j.at("size").get()); x.setCreatedAt(j.at("created_at").get()); x.setUpdatedAt(j.at("updated_at").get()); x.setBrowserDownloadUrl(j.at("browser_download_url").get()); x.setFiles(j.at("files").get>()); } inline void from_json(const json &j, Release &x) { x.setId(j.at("id").get()); x.setNodeId(j.at("node_id").get()); x.setName(j.at("name").get()); x.setTagName(j.at("tag_name").get()); x.setPrerelease(j.at("prerelease").get()); x.setTargetCommitish(j.at("target_commitish").get()); x.setCreatedAt(j.at("created_at").get()); x.setPublishedAt(j.at("published_at").get()); } inline void from_json(const json &j, RepositoryFile &x) { x.setPath(j.at("path").get()); x.setSha1(j.at("sha1").get()); x.setAsset(j.at("asset").get()); x.setRelease(j.at("release").get()); } inline void from_json(const json &j, Tag &x) { x.setTagName(j.at("tag_name").get()); } inline void from_json(const json &j, Repo &x) { x.setOwner(j.at("owner").get()); x.setRepo(j.at("repo").get()); x.setTag(j.at("tag").get()); x.setForceTag(get_optional(j, "forceTag")); } inline void from_json(const json &j, Repository &x) { x.setRepo(j.at("repo").get()); x.setFiles(j.at("files").get>()); } inline void from_json(const json &j, Package &x) { x.setId(j.at("id").get()); x.setName(j.at("name").get()); x.setDescription(j.at("description").get()); x.setRepositories(j.at("repositories").get>()); x.setRequired(j.at("required").get()); x.setPreSelected(j.at("preSelected").get()); } inline void from_json(const json &j, Category &x) { x.setId(j.at("id").get()); x.setName(j.at("name").get()); x.setPackages(j.at("packages").get>()); } inline void from_json(const json &j, BaseCategory &x) { x.setId(j.at("id").get()); x.setName(j.at("name").get()); x.setCategory(j.at("category").get>()); } } // namespace VersionCheck