version.hpp (3042B)
1 /* ReaPack: Package manager for REAPER 2 * Copyright (C) 2015-2025 Christian Fillion 3 * 4 * This program is free software: you can redistribute it and/or modify 5 * it under the terms of the GNU Lesser General Public License as published by 6 * the Free Software Foundation, either version 3 of the License, or 7 * (at your option) any later version. 8 * 9 * This program is distributed in the hope that it will be useful, 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 * GNU Lesser General Public License for more details. 13 * 14 * You should have received a copy of the GNU Lesser General Public License 15 * along with this program. If not, see <http://www.gnu.org/licenses/>. 16 */ 17 18 #ifndef REAPACK_VERSION_HPP 19 #define REAPACK_VERSION_HPP 20 21 #include "time.hpp" 22 23 #include <cstdint> 24 #include <map> 25 #include <set> 26 #include <variant> 27 #include <vector> 28 29 class Package; 30 class Path; 31 class Source; 32 33 class VersionName { 34 public: 35 VersionName(); 36 VersionName(const std::string &); 37 VersionName(const VersionName &); 38 39 VersionName &operator=(const VersionName &) = default; 40 41 void parse(const std::string &); 42 bool tryParse(const std::string &, std::string *errorOut = nullptr); 43 44 size_t size() const { return m_segments.size(); } 45 bool isStable() const { return m_stable; } 46 const std::string &toString() const { return m_string; } 47 48 int compare(const VersionName &) const; 49 50 #define COMPOP(op) \ 51 bool operator op (const VersionName &o) const { return compare(o) op 0; } 52 53 COMPOP(<) COMPOP(<=) COMPOP(>) COMPOP(>=) COMPOP(==) COMPOP(!=) 54 55 #undef COMPOP 56 57 private: 58 typedef uint16_t Numeric; 59 typedef std::variant<Numeric, std::string> Segment; 60 61 Segment segment(size_t i) const; 62 63 std::string m_string; 64 std::vector<Segment> m_segments; 65 bool m_stable; 66 }; 67 68 class Version { 69 public: 70 static std::string displayAuthor(const std::string &name); 71 72 Version(const std::string &, const Package *); 73 ~Version(); 74 75 const VersionName &name() const { return m_name; } 76 const Package *package() const { return m_package; } 77 std::string fullName() const; 78 79 void setAuthor(const std::string &author) { m_author = author; } 80 const std::string &author() const { return m_author; } 81 std::string displayAuthor() const { return displayAuthor(m_author); } 82 83 void setTime(const Time &time) { if(time) m_time = time; } 84 const Time &time() const { return m_time; } 85 86 void setChangelog(const std::string &cl) { m_changelog = cl; } 87 const std::string &changelog() const { return m_changelog; } 88 89 bool addSource(const Source *source); 90 const auto &sources() const { return m_sources; } 91 const Source *source(size_t i) const { return m_sources[i]; } 92 93 const std::set<Path> &files() const { return m_files; } 94 95 private: 96 VersionName m_name; 97 std::string m_author; 98 std::string m_changelog; 99 Time m_time; 100 const Package *m_package; 101 std::vector<const Source *> m_sources; 102 std::set<Path> m_files; 103 }; 104 105 std::ostream &operator<<(std::ostream &, const Version &); 106 107 #endif