reapack

Package manager for REAPER
Log | Files | Refs | Submodules | README | LICENSE

index.hpp (2781B)


      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_INDEX_HPP
     19 #define REAPACK_INDEX_HPP
     20 
     21 #include "metadata.hpp"
     22 #include "package.hpp"
     23 #include "source.hpp"
     24 
     25 #include <map>
     26 #include <memory>
     27 #include <string>
     28 #include <unordered_map>
     29 #include <vector>
     30 
     31 class Index;
     32 class Path;
     33 class Remote;
     34 class XmlNode;
     35 struct NetworkOpts;
     36 
     37 typedef std::shared_ptr<const Index> IndexPtr;
     38 
     39 class Index : public std::enable_shared_from_this<const Index> {
     40 public:
     41   static Path pathFor(const std::string &name);
     42   static IndexPtr load(const std::string &name, const char *data = nullptr);
     43 
     44   Index(const std::string &name);
     45   ~Index();
     46 
     47   void setName(const std::string &);
     48   const std::string &name() const { return m_name; }
     49 
     50   Metadata *metadata() { return &m_metadata; }
     51   const Metadata *metadata() const { return &m_metadata; }
     52 
     53   bool addCategory(const Category *cat);
     54   const auto &categories() const { return m_categories; }
     55   const Category *category(size_t i) const { return m_categories[i]; }
     56   const Category *category(const std::string &name) const;
     57   const Package *find(const std::string &cat, const std::string &pkg) const;
     58 
     59   const std::vector<const Package *> &packages() const { return m_packages; }
     60 
     61 private:
     62   static void loadV1(XmlNode, Index *);
     63 
     64   std::string m_name;
     65   Metadata m_metadata;
     66   std::vector<const Category *> m_categories;
     67   std::vector<const Package *> m_packages;
     68 
     69   std::unordered_map<std::string, size_t> m_catMap;
     70 };
     71 
     72 class Category {
     73 public:
     74   Category(const std::string &name, const Index *);
     75   ~Category();
     76 
     77   const Index *index() const { return m_index; }
     78   const std::string &name() const { return m_name; }
     79   std::string fullName() const;
     80 
     81   bool addPackage(const Package *pack);
     82   const auto &packages() const { return m_packages; }
     83   const Package *package(size_t i) const { return m_packages[i]; }
     84   const Package *package(const std::string &name) const;
     85 
     86 private:
     87   const Index *m_index;
     88 
     89   std::string m_name;
     90   std::vector<const Package *> m_packages;
     91   std::unordered_map<std::string, size_t> m_pkgMap;
     92 };
     93 
     94 #endif