From b6d455a02bd338e9dc0faa09d4d8177ecd8d569a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Petr=20Mr=C3=A1zek?= Date: Sun, 10 Apr 2016 15:53:05 +0200 Subject: NOISSUE reorganize and document libraries --- libraries/logic/wonko/format/WonkoFormat.cpp | 80 ------------- libraries/logic/wonko/format/WonkoFormat.h | 54 --------- libraries/logic/wonko/format/WonkoFormatV1.cpp | 156 ------------------------- libraries/logic/wonko/format/WonkoFormatV1.h | 30 ----- 4 files changed, 320 deletions(-) delete mode 100644 libraries/logic/wonko/format/WonkoFormat.cpp delete mode 100644 libraries/logic/wonko/format/WonkoFormat.h delete mode 100644 libraries/logic/wonko/format/WonkoFormatV1.cpp delete mode 100644 libraries/logic/wonko/format/WonkoFormatV1.h (limited to 'libraries/logic/wonko/format') diff --git a/libraries/logic/wonko/format/WonkoFormat.cpp b/libraries/logic/wonko/format/WonkoFormat.cpp deleted file mode 100644 index 11192cbe..00000000 --- a/libraries/logic/wonko/format/WonkoFormat.cpp +++ /dev/null @@ -1,80 +0,0 @@ -/* Copyright 2015 MultiMC Contributors - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "WonkoFormat.h" - -#include "WonkoFormatV1.h" - -#include "wonko/WonkoIndex.h" -#include "wonko/WonkoVersion.h" -#include "wonko/WonkoVersionList.h" - -static int formatVersion(const QJsonObject &obj) -{ - if (!obj.contains("formatVersion")) { - throw WonkoParseException(QObject::tr("Missing required field: 'formatVersion'")); - } - if (!obj.value("formatVersion").isDouble()) { - throw WonkoParseException(QObject::tr("Required field has invalid type: 'formatVersion'")); - } - return obj.value("formatVersion").toInt(); -} - -void WonkoFormat::parseIndex(const QJsonObject &obj, WonkoIndex *ptr) -{ - const int version = formatVersion(obj); - switch (version) { - case 1: - ptr->merge(WonkoFormatV1().parseIndexInternal(obj)); - break; - default: - throw WonkoParseException(QObject::tr("Unknown formatVersion: %1").arg(version)); - } -} -void WonkoFormat::parseVersion(const QJsonObject &obj, WonkoVersion *ptr) -{ - const int version = formatVersion(obj); - switch (version) { - case 1: - ptr->merge(WonkoFormatV1().parseVersionInternal(obj)); - break; - default: - throw WonkoParseException(QObject::tr("Unknown formatVersion: %1").arg(version)); - } -} -void WonkoFormat::parseVersionList(const QJsonObject &obj, WonkoVersionList *ptr) -{ - const int version = formatVersion(obj); - switch (version) { - case 10: - ptr->merge(WonkoFormatV1().parseVersionListInternal(obj)); - break; - default: - throw WonkoParseException(QObject::tr("Unknown formatVersion: %1").arg(version)); - } -} - -QJsonObject WonkoFormat::serializeIndex(const WonkoIndex *ptr) -{ - return WonkoFormatV1().serializeIndexInternal(ptr); -} -QJsonObject WonkoFormat::serializeVersion(const WonkoVersion *ptr) -{ - return WonkoFormatV1().serializeVersionInternal(ptr); -} -QJsonObject WonkoFormat::serializeVersionList(const WonkoVersionList *ptr) -{ - return WonkoFormatV1().serializeVersionListInternal(ptr); -} diff --git a/libraries/logic/wonko/format/WonkoFormat.h b/libraries/logic/wonko/format/WonkoFormat.h deleted file mode 100644 index 450d6ccc..00000000 --- a/libraries/logic/wonko/format/WonkoFormat.h +++ /dev/null @@ -1,54 +0,0 @@ -/* Copyright 2015 MultiMC Contributors - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#pragma once - -#include -#include - -#include "Exception.h" -#include "wonko/BaseWonkoEntity.h" - -class WonkoIndex; -class WonkoVersion; -class WonkoVersionList; - -class WonkoParseException : public Exception -{ -public: - using Exception::Exception; -}; - -class WonkoFormat -{ -public: - virtual ~WonkoFormat() {} - - static void parseIndex(const QJsonObject &obj, WonkoIndex *ptr); - static void parseVersion(const QJsonObject &obj, WonkoVersion *ptr); - static void parseVersionList(const QJsonObject &obj, WonkoVersionList *ptr); - - static QJsonObject serializeIndex(const WonkoIndex *ptr); - static QJsonObject serializeVersion(const WonkoVersion *ptr); - static QJsonObject serializeVersionList(const WonkoVersionList *ptr); - -protected: - virtual BaseWonkoEntity::Ptr parseIndexInternal(const QJsonObject &obj) const = 0; - virtual BaseWonkoEntity::Ptr parseVersionInternal(const QJsonObject &obj) const = 0; - virtual BaseWonkoEntity::Ptr parseVersionListInternal(const QJsonObject &obj) const = 0; - virtual QJsonObject serializeIndexInternal(const WonkoIndex *ptr) const = 0; - virtual QJsonObject serializeVersionInternal(const WonkoVersion *ptr) const = 0; - virtual QJsonObject serializeVersionListInternal(const WonkoVersionList *ptr) const = 0; -}; diff --git a/libraries/logic/wonko/format/WonkoFormatV1.cpp b/libraries/logic/wonko/format/WonkoFormatV1.cpp deleted file mode 100644 index 363eebfb..00000000 --- a/libraries/logic/wonko/format/WonkoFormatV1.cpp +++ /dev/null @@ -1,156 +0,0 @@ -/* Copyright 2015 MultiMC Contributors - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "WonkoFormatV1.h" -#include - -#include "Json.h" - -#include "wonko/WonkoIndex.h" -#include "wonko/WonkoVersion.h" -#include "wonko/WonkoVersionList.h" -#include "Env.h" - -using namespace Json; - -static WonkoVersionPtr parseCommonVersion(const QString &uid, const QJsonObject &obj) -{ - const QVector requiresRaw = obj.contains("requires") ? requireIsArrayOf(obj, "requires") : QVector(); - QVector requires; - requires.reserve(requiresRaw.size()); - std::transform(requiresRaw.begin(), requiresRaw.end(), std::back_inserter(requires), [](const QJsonObject &rObj) - { - WonkoReference ref(requireString(rObj, "uid")); - ref.setVersion(ensureString(rObj, "version", QString())); - return ref; - }); - - WonkoVersionPtr version = std::make_shared(uid, requireString(obj, "version")); - if (obj.value("time").isString()) - { - version->setTime(QDateTime::fromString(requireString(obj, "time"), Qt::ISODate).toMSecsSinceEpoch() / 1000); - } - else - { - version->setTime(requireInteger(obj, "time")); - } - version->setType(ensureString(obj, "type", QString())); - version->setRequires(requires); - return version; -} -static void serializeCommonVersion(const WonkoVersion *version, QJsonObject &obj) -{ - QJsonArray requires; - for (const WonkoReference &ref : version->requires()) - { - if (ref.version().isEmpty()) - { - requires.append(QJsonObject({{"uid", ref.uid()}})); - } - else - { - requires.append(QJsonObject({ - {"uid", ref.uid()}, - {"version", ref.version()} - })); - } - } - - obj.insert("version", version->version()); - obj.insert("type", version->type()); - obj.insert("time", version->time().toString(Qt::ISODate)); - obj.insert("requires", requires); -} - -BaseWonkoEntity::Ptr WonkoFormatV1::parseIndexInternal(const QJsonObject &obj) const -{ - const QVector objects = requireIsArrayOf(obj, "index"); - QVector lists; - lists.reserve(objects.size()); - std::transform(objects.begin(), objects.end(), std::back_inserter(lists), [](const QJsonObject &obj) - { - WonkoVersionListPtr list = std::make_shared(requireString(obj, "uid")); - list->setName(ensureString(obj, "name", QString())); - return list; - }); - return std::make_shared(lists); -} -BaseWonkoEntity::Ptr WonkoFormatV1::parseVersionInternal(const QJsonObject &obj) const -{ - WonkoVersionPtr version = parseCommonVersion(requireString(obj, "uid"), obj); - - version->setData(OneSixVersionFormat::versionFileFromJson(QJsonDocument(obj), - QString("%1/%2.json").arg(version->uid(), version->version()), - obj.contains("order"))); - return version; -} -BaseWonkoEntity::Ptr WonkoFormatV1::parseVersionListInternal(const QJsonObject &obj) const -{ - const QString uid = requireString(obj, "uid"); - - const QVector versionsRaw = requireIsArrayOf(obj, "versions"); - QVector versions; - versions.reserve(versionsRaw.size()); - std::transform(versionsRaw.begin(), versionsRaw.end(), std::back_inserter(versions), [this, uid](const QJsonObject &vObj) - { return parseCommonVersion(uid, vObj); }); - - WonkoVersionListPtr list = std::make_shared(uid); - list->setName(ensureString(obj, "name", QString())); - list->setVersions(versions); - return list; -} - -QJsonObject WonkoFormatV1::serializeIndexInternal(const WonkoIndex *ptr) const -{ - QJsonArray index; - for (const WonkoVersionListPtr &list : ptr->lists()) - { - index.append(QJsonObject({ - {"uid", list->uid()}, - {"name", list->name()} - })); - } - return QJsonObject({ - {"formatVersion", 1}, - {"index", index} - }); -} -QJsonObject WonkoFormatV1::serializeVersionInternal(const WonkoVersion *ptr) const -{ - QJsonObject obj = OneSixVersionFormat::versionFileToJson(ptr->data(), true).object(); - serializeCommonVersion(ptr, obj); - obj.insert("formatVersion", 1); - obj.insert("uid", ptr->uid()); - // TODO: the name should be looked up in the UI based on the uid - obj.insert("name", ENV.wonkoIndex()->getListGuaranteed(ptr->uid())->name()); - - return obj; -} -QJsonObject WonkoFormatV1::serializeVersionListInternal(const WonkoVersionList *ptr) const -{ - QJsonArray versions; - for (const WonkoVersionPtr &version : ptr->versions()) - { - QJsonObject obj; - serializeCommonVersion(version.get(), obj); - versions.append(obj); - } - return QJsonObject({ - {"formatVersion", 10}, - {"uid", ptr->uid()}, - {"name", ptr->name().isNull() ? QJsonValue() : ptr->name()}, - {"versions", versions} - }); -} diff --git a/libraries/logic/wonko/format/WonkoFormatV1.h b/libraries/logic/wonko/format/WonkoFormatV1.h deleted file mode 100644 index 92759804..00000000 --- a/libraries/logic/wonko/format/WonkoFormatV1.h +++ /dev/null @@ -1,30 +0,0 @@ -/* Copyright 2015 MultiMC Contributors - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#pragma once - -#include "WonkoFormat.h" - -class WonkoFormatV1 : public WonkoFormat -{ -public: - BaseWonkoEntity::Ptr parseIndexInternal(const QJsonObject &obj) const override; - BaseWonkoEntity::Ptr parseVersionInternal(const QJsonObject &obj) const override; - BaseWonkoEntity::Ptr parseVersionListInternal(const QJsonObject &obj) const override; - - QJsonObject serializeIndexInternal(const WonkoIndex *ptr) const override; - QJsonObject serializeVersionInternal(const WonkoVersion *ptr) const override; - QJsonObject serializeVersionListInternal(const WonkoVersionList *ptr) const override; -}; -- cgit v1.2.3