plugify  1.0.0.0
package.hpp
1 #pragma once
2 
3 #include <filesystem>
4 #include <functional>
5 #include <memory>
6 #include <optional>
7 #include <plugify/descriptor.hpp>
8 #include <set>
9 #include <tuple>
10 
11 namespace plugify {
20  struct PackageVersion final {
21  int32_t version;
22  std::string checksum;
23  std::string download;
24  std::vector<std::string> platforms;
25 
31  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)); }
32  };
33 
38  using PackageOpt = const PackageVersion*;
39 
47  struct Package {
48  std::string name;
49  std::string type;
50 
56  bool operator==(const Package& rhs) const noexcept { return name == rhs.name && type == rhs.type; }
57  };
58 
67  struct RemotePackage final : public Package {
68  std::string author;
69  std::string description;
70  std::set<PackageVersion> versions;
71 
76  PackageOpt LatestVersion() const noexcept {
77  if (!versions.empty())
78  return &(*versions.begin());
79  return {};
80  }
81 
87  PackageOpt Version(int32_t version) const {
88  auto it = versions.find(PackageVersion{ version, {}, {}, {} }); // dummy key for lookup
89  if (it != versions.end())
90  return &(*it);
91  return {};
92  }
93  };
94 
103  struct LocalPackage final : public Package {
104  std::filesystem::path path;
105  int32_t version;
106  std::shared_ptr<Descriptor> descriptor;
107 
112  explicit operator RemotePackage() const {
113  return { name, type, descriptor->createdBy, descriptor->description, { PackageVersion{ descriptor->version, {}, descriptor->downloadURL, descriptor->supportedPlatforms} }};
114  }
115  };
116 } // namespace plugify
Represents a locally installed software package.
Definition: package.hpp:103
int32_t version
The version number of the locally installed package.
Definition: package.hpp:105
std::filesystem::path path
The file path to the locally installed package.
Definition: package.hpp:104
std::shared_ptr< Descriptor > descriptor
A shared pointer to the package descriptor.
Definition: package.hpp:106
Represents a version of a software package.
Definition: package.hpp:20
int32_t version
The version number of the package.
Definition: package.hpp:21
std::string checksum
The checksum of the package.
Definition: package.hpp:22
bool operator<(const PackageVersion &rhs) const noexcept
Overloaded less-than operator for comparing PackageVersion instances.
Definition: package.hpp:31
std::vector< std::string > platforms
The platforms supported by the package.
Definition: package.hpp:24
std::string download
The download URL for the package.
Definition: package.hpp:23
Represents a generic software package.
Definition: package.hpp:47
std::string type
The type of the package (e.g., module, plugin).
Definition: package.hpp:49
std::string name
The name of the package.
Definition: package.hpp:48
bool operator==(const Package &rhs) const noexcept
Overloaded equality operator for comparing Package instances.
Definition: package.hpp:56
Represents a remotely available software package.
Definition: package.hpp:67
PackageOpt Version(int32_t version) const
Get a specific version of the package.
Definition: package.hpp:87
std::string author
The author of the package.
Definition: package.hpp:68
std::string description
The description of the package.
Definition: package.hpp:69
PackageOpt LatestVersion() const noexcept
Get the latest available version of the package.
Definition: package.hpp:76
std::set< PackageVersion > versions
The set of available versions for the package.
Definition: package.hpp:70