libAlgAudio  v1.99-440-g08538e5-dirty
The development library for AlgAudio framework.
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
ModuleCollection.hpp
Go to the documentation of this file.
1 #ifndef MODULE_CONNECTION
2 #define MODULE_CONNECTION
3 /*
4 This file is part of AlgAudio.
5 
6 AlgAudio, Copyright (C) 2015 CeTA - Audiovisual Technology Center
7 
8 AlgAudio is free software: you can redistribute it and/or modify
9 it under the terms of the GNU Lesser General Public License as
10 published by the Free Software Foundation, either version 3 of the
11 License, or (at your option) any later version.
12 
13 AlgAudio is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU Lesser General Public License for more details.
17 
18 You should have received a copy of the GNU Lesser General Public License
19 along with AlgAudio. If not, see <http://www.gnu.org/licenses/>.
20 */
21 #include <fstream>
22 #include <memory>
23 #include <map>
24 
25 #include "ModuleTemplate.hpp"
26 #include "Utilities.hpp"
27 #include "LateReturn.hpp"
28 
29 namespace AlgAudio{
30 
31 class LibLoader;
32 
33 namespace Exceptions{
34 struct CollectionParse : public Exception{
35  CollectionParse(std::string t) : Exception(t) {};
36  CollectionParse(std::string i, std::string t) : Exception(t), id(i) {};
37  virtual std::string what() override {
38  if(id == "") return "While loading an unknown collection: " + text;
39  else return "While loading collection '" + id + "': " + text;
40  };
41  std::string id = "";
42 };
43 struct CollectionLoading : public Exception{
44  CollectionLoading(std::string p, std::string t) : Exception(t), path(p) {};
45  virtual std::string what() override {
46  return "While loading collection from '" + path + "': " + text;
47  };
48  std::string path;
49 };
50 } // namespace Exceptions
51 
55 public:
56  ModuleCollection(std::ifstream& file, std::string basedir);
61  std::shared_ptr<ModuleTemplate> GetTemplateByID(std::string id);
62  std::map<std::string, std::shared_ptr<ModuleTemplate>> templates_by_id;
63  std::string id;
64  std::string name;
65  std::string basedir;
67  std::string defaultlib_path;
68  std::shared_ptr<LibLoader> defaultlib;
69 };
70 
75 private:
76  ModuleCollectionBase() = delete; // static class
77 
78  static std::map<std::string, std::shared_ptr<ModuleCollection>> collections_by_id;
79 public:
80  static std::shared_ptr<ModuleCollection> GetCollectionByID(std::string id);
81  static std::shared_ptr<ModuleTemplate> GetTemplateByID(std::string id);
82  static std::shared_ptr<ModuleCollection> InstallFile(std::string filepath);
83  static const std::map<std::string, std::shared_ptr<ModuleCollection>>& GetCollections();
84  static void InstallDir(std::string dirpath);
85  static std::string ListInstalledTemplates();
87 };
88 
89 } // namespace AlgAudio
90 #endif //MODULE_CONNECTION
Definition: ModuleCollection.hpp:74
virtual std::string what() override
Definition: ModuleCollection.hpp:37
CollectionLoading(std::string p, std::string t)
Definition: ModuleCollection.hpp:44
std::shared_ptr< ModuleTemplate > GetTemplateByID(std::string id)
std::string defaultlib_path
Definition: ModuleCollection.hpp:67
std::string id
Definition: ModuleCollection.hpp:63
std::shared_ptr< LibLoader > defaultlib
Definition: ModuleCollection.hpp:68
Definition: ModuleCollection.hpp:43
Definition: ModuleCollection.hpp:34
static void InstallDir(std::string dirpath)
std::string name
Definition: ModuleCollection.hpp:64
std::map< std::string, std::shared_ptr< ModuleTemplate > > templates_by_id
Definition: ModuleCollection.hpp:62
LateReturn InstallAllTemplatesIntoSC()
static std::shared_ptr< ModuleTemplate > GetTemplateByID(std::string id)
Definition: ModuleCollection.hpp:54
Definition: Alertable.hpp:26
virtual std::string what() override
Definition: ModuleCollection.hpp:45
ModuleCollection(std::ifstream &file, std::string basedir)
std::string basedir
Definition: ModuleCollection.hpp:65
std::string id
Definition: ModuleCollection.hpp:41
static std::shared_ptr< ModuleCollection > GetCollectionByID(std::string id)
CollectionParse(std::string i, std::string t)
Definition: ModuleCollection.hpp:36
static std::string ListInstalledTemplates()
static std::shared_ptr< ModuleCollection > InstallFile(std::string filepath)
std::string text
Definition: Exception.hpp:42
CollectionParse(std::string t)
Definition: ModuleCollection.hpp:35
Definition: LateReturn.hpp:35
static const std::map< std::string, std::shared_ptr< ModuleCollection > > & GetCollections()
bool has_defaultlib
Definition: ModuleCollection.hpp:66
std::string path
Definition: ModuleCollection.hpp:47
Definition: Exception.hpp:29
static LateReturn InstallAllTemplatesIntoSC()