registry.hpp (2810B)
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_REGISTRY_HPP 19 #define REAPACK_REGISTRY_HPP 20 21 #include "database.hpp" 22 #include "package.hpp" 23 #include "path.hpp" 24 #include "version.hpp" 25 26 #include <set> 27 #include <string> 28 29 class Registry { 30 public: 31 struct Entry { 32 enum Flag { 33 PinnedFlag = 1<<0, 34 BleedingEdgeFlag = 1<<1, 35 }; 36 37 typedef int64_t id_t; 38 39 id_t id; 40 std::string remote; 41 std::string category; 42 std::string package; 43 std::string description; 44 Package::Type type; 45 VersionName version; 46 std::string author; 47 int flags; 48 49 operator bool() const { return id > 0; } 50 bool operator==(const Entry &o) const { return id == o.id; } 51 bool test(Flag f) const { return (flags & f) == f; } 52 }; 53 54 struct File { 55 Path path; 56 int sections; 57 Package::Type type; 58 59 bool operator<(const File &o) const { return path < o.path; } 60 }; 61 62 Registry(const Path &path = {}); 63 64 Entry getEntry(const Package *) const; 65 Entry getOwner(const Path &) const; 66 std::vector<Entry> getEntries(const std::string &) const; 67 std::vector<File> getFiles(const Entry &) const; 68 std::vector<File> getMainFiles(const Entry &) const; 69 Entry push(const Version *, int flags = 0, std::vector<Path> *conflicts = nullptr); 70 void setFlags(const Entry &, int flags); 71 void forget(const Entry &); 72 73 void savepoint() { m_db.savepoint(); } 74 void restore() { m_db.restore(); } 75 void commit() { m_db.commit(); } 76 77 private: 78 void migrate(); 79 void convertImplicitSections(); 80 void fillEntry(const Statement *, Entry *) const; 81 82 Database m_db; 83 Statement *m_insertEntry; 84 Statement *m_updateEntry; 85 Statement *m_setFlags; 86 Statement *m_findEntry; 87 Statement *m_allEntries; 88 Statement *m_forgetEntry; 89 Statement *m_getOwner; 90 91 Statement *m_getFiles; 92 Statement *m_insertFile; 93 Statement *m_clearFiles; 94 Statement *m_forgetFiles; 95 }; 96 97 namespace std { 98 template<> struct hash<Registry::Entry> { 99 std::size_t operator()(const Registry::Entry &e) const 100 { 101 return std::hash<Registry::Entry::id_t>()(e.id); 102 } 103 }; 104 } 105 106 #endif