plugify 1.0.0.0
Loading...
Searching...
No Matches
package.hpp
1#pragma once
2
3#include <filesystem>
4#include <functional>
5#include <memory>
6#include <optional>
7#include <set>
8#include <tuple>
9#include <vector>
10
11#include "descriptor.hpp"
12#include "version.hpp"
13
14namespace plugify {
23 struct PackageVersion final {
25 std::string checksum;
26 std::string download;
27 std::optional<std::vector<std::string>> platforms;
28
34 bool operator <(const PackageVersion& rhs) const noexcept { return version > rhs.version || (version == rhs.version && std::tie(checksum, download, platforms) < std::tie(rhs.checksum, rhs.download, rhs.platforms)); }
35 };
36
41 using PackageOpt = const PackageVersion*;
42
50 struct Package {
51 std::string name;
52 std::string type;
53
59 bool operator==(const Package& rhs) const noexcept { return name == rhs.name && type == rhs.type; }
60 };
61
70 struct RemotePackage : public Package {
71 std::string author;
72 std::string description;
73 std::set<PackageVersion> versions;
74
79 PackageOpt LatestVersion() const noexcept {
80 if (!versions.empty())
81 return &(*versions.begin());
82 return {};
83 }
84
91 auto it = versions.find(PackageVersion{ version, {}, {}, {} }); // dummy key for lookup
92 if (it != versions.end())
93 return &(*it);
94 return {};
95 }
96 };
97
106 struct LocalPackage : public Package {
107 std::filesystem::path path;
109 std::shared_ptr<Descriptor> descriptor;
110
115 explicit operator RemotePackage() const {
116 return { name, type, descriptor->createdBy.value_or("unknown"), descriptor->description.value_or(""), { PackageVersion{ descriptor->version, {}, descriptor->downloadURL.value_or(""), descriptor->supportedPlatforms } } };
117 }
118 };
119} // namespace plugify
Represents a locally installed software package.
Definition package.hpp:106
std::filesystem::path path
The file path to the locally installed package.
Definition package.hpp:107
std::shared_ptr< Descriptor > descriptor
A shared pointer to the package descriptor.
Definition package.hpp:109
plg::version version
The semantic version of the locally installed package.
Definition package.hpp:108
Represents a version of a software package.
Definition package.hpp:23
std::optional< std::vector< std::string > > platforms
The platforms supported by the package.
Definition package.hpp:27
std::string checksum
The checksum of the package.
Definition package.hpp:25
plg::version version
The semantic version of the package.
Definition package.hpp:24
bool operator<(const PackageVersion &rhs) const noexcept
Overloaded less-than operator for comparing PackageVersion instances.
Definition package.hpp:34
std::string download
The download URL for the package.
Definition package.hpp:26
Represents a generic software package.
Definition package.hpp:50
std::string type
The type of the package (e.g., module, plugin).
Definition package.hpp:52
std::string name
The name of the package.
Definition package.hpp:51
bool operator==(const Package &rhs) const noexcept
Overloaded equality operator for comparing Package instances.
Definition package.hpp:59
Represents a remotely available software package.
Definition package.hpp:70
std::string author
The author of the package.
Definition package.hpp:71
PackageOpt Version(plg::version version) const
Get a specific version of the package.
Definition package.hpp:90
std::string description
The description of the package.
Definition package.hpp:72
PackageOpt LatestVersion() const noexcept
Get the latest available version of the package.
Definition package.hpp:79
std::set< PackageVersion > versions
The set of available versions for the package.
Definition package.hpp:73