@@ -21,29 +21,40 Q_DECLARE_LOGGING_CATEGORY(LOG_CatalogueController) | |||
|
21 | 21 | class DataSourceItem; |
|
22 | 22 | class Variable; |
|
23 | 23 | |
|
24 | constexpr auto default_repo = "default"; | |
|
25 | ||
|
24 | 26 | /** |
|
25 | 27 | * @brief The CatalogueController class aims to handle catalogues and event |
|
26 | 28 | * using the CatalogueAPI library. |
|
27 | 29 | */ |
|
28 | 30 | class SCIQLOP_CORE_EXPORT CatalogueController : public QObject |
|
29 | 31 | { |
|
32 | Q_OBJECT | |
|
33 | public: | |
|
30 | 34 | using time_t = double; |
|
35 | using Product_t = CatalogiCpp::Product<time_t>; | |
|
31 | 36 | using Repository_t = CatalogiCpp::Repository<time_t>; |
|
32 | 37 | using Event_t = Repository_t::Event_t; |
|
33 | 38 | using Event_ptr = Repository_t::Event_ptr; |
|
34 | 39 | using Catalogue_t = Repository_t::Catalogue_t; |
|
35 | 40 | using Catalogue_ptr = typename Repository_t::Catalogue_ptr; |
|
36 | 41 | using uuid_t = Repository_t::uuid_t; |
|
42 | template<typename... _Args> | |
|
43 | static inline Catalogue_ptr make_catalogue_ptr(_Args&&... __args) | |
|
44 | { | |
|
45 | return Repository_t::make_catalogue_ptr(std::forward<_Args>(__args)...); | |
|
46 | } | |
|
47 | ||
|
48 | template<typename... _Args> | |
|
49 | static inline Event_ptr make_event_ptr(_Args&&... __args) | |
|
50 | { | |
|
51 | return Catalogue_t::make_event_ptr(std::forward<_Args>(__args)...); | |
|
52 | } | |
|
37 | 53 | |
|
38 | std::map<QString, CatalogiCpp::Repository<time_t>> _lastSavedRepos; | |
|
39 | std::map<QString, CatalogiCpp::Repository<time_t>> _currentRepos; | |
|
40 | ||
|
41 | Q_OBJECT | |
|
42 | public: | |
|
43 | 54 | explicit CatalogueController(QObject* parent = nullptr); |
|
44 | 55 | virtual ~CatalogueController(); |
|
45 | 56 | |
|
46 |
QStringList |
|
|
57 | QStringList repositories() const; | |
|
47 | 58 | void loadRepository(const QString& path, const QString& name); |
|
48 | 59 | void saveRepository(const QString& path, const QString& name); |
|
49 | 60 | |
@@ -62,6 +73,11 public: | |||
|
62 | 73 | void save(Catalogue_ptr catalogue); |
|
63 | 74 | void save(const QString& repository); |
|
64 | 75 | |
|
76 | void add(const QString& repository); | |
|
77 | void add(const QString& catalogue, const QString& repository); | |
|
78 | void add(Event_ptr event, Catalogue_ptr catalogue); | |
|
79 | void add(Event_ptr event, const QString& repository = default_repo); | |
|
80 | ||
|
65 | 81 | // // Event |
|
66 | 82 | // /// retrieveEvents with empty repository retrieve them from the default |
|
67 | 83 | // repository std::list<std::shared_ptr<DBEvent>> retrieveEvents(const |
@@ -116,6 +132,9 public: | |||
|
116 | 132 | // void initialize(); |
|
117 | 133 | |
|
118 | 134 | private: |
|
135 | std::map<QString, CatalogiCpp::Repository<time_t>> _lastSavedRepos; | |
|
136 | std::map<QString, CatalogiCpp::Repository<time_t>> _currentRepos; | |
|
137 | ||
|
119 | 138 | // class CatalogueControllerPrivate; |
|
120 | 139 | // spimpl::unique_impl_ptr<CatalogueControllerPrivate> impl; |
|
121 | 140 | }; |
@@ -23,6 +23,27 namespace SciQLop::containers | |||
|
23 | 23 | return container.find(value) != std::cend(container); |
|
24 | 24 | } |
|
25 | 25 | |
|
26 | template<class T1, class T2> | |
|
27 | auto index_of(const T1& container, const T2& value) | |
|
28 | -> decltype(container.front() == value, 0) | |
|
29 | { | |
|
30 | return std::distance( | |
|
31 | std::cbegin(container), | |
|
32 | std::find(std::cbegin(container), std::cend(container), value)); | |
|
33 | } | |
|
34 | ||
|
35 | template<class T1, class T2> | |
|
36 | auto index_of(const T1& container, const T2& value) | |
|
37 | -> decltype(container.front().get(), std::is_pointer<T2>::value, 0) | |
|
38 | { | |
|
39 | return std::distance(std::cbegin(container), | |
|
40 | std::find_if(std::cbegin(container), | |
|
41 | std::cend(container), | |
|
42 | [value](const auto& item) { | |
|
43 | return value == item.get(); | |
|
44 | })); | |
|
45 | } | |
|
46 | ||
|
26 | 47 | } // namespace SciQLop::containers |
|
27 | 48 | |
|
28 | 49 | #endif // CONTAINERS_H |
@@ -47,7 +47,7 CatalogueController::CatalogueController(QObject* parent) | |||
|
47 | 47 | |
|
48 | 48 | CatalogueController::~CatalogueController() {} |
|
49 | 49 | |
|
50 |
QStringList CatalogueController:: |
|
|
50 | QStringList CatalogueController::repositories() const | |
|
51 | 51 | { |
|
52 | 52 | QStringList repos; |
|
53 | 53 | std::transform(std::begin(_currentRepos), std::end(_currentRepos), |
@@ -209,6 +209,26 void CatalogueController::save(const QString& repository) | |||
|
209 | 209 | } |
|
210 | 210 | } |
|
211 | 211 | |
|
212 | void CatalogueController::add(const QString& repository) | |
|
213 | { | |
|
214 | if(!contains(_currentRepos, repository)) | |
|
215 | { _currentRepos[repository] = Repository_t{}; } | |
|
216 | } | |
|
217 | ||
|
218 | void CatalogueController::add(const QString& catalogue, | |
|
219 | const QString& repository) | |
|
220 | { | |
|
221 | if(!contains(_currentRepos, repository)) | |
|
222 | { _currentRepos[repository] = Repository_t{}; } | |
|
223 | auto new_catalogue = make_catalogue_ptr(); | |
|
224 | new_catalogue->name = catalogue.toStdString(); | |
|
225 | _currentRepos[repository].add(std::move(new_catalogue)); | |
|
226 | } | |
|
227 | ||
|
228 | void CatalogueController::add(CatalogueController::Event_ptr event, | |
|
229 | const QString& repository) | |
|
230 | {} | |
|
231 | ||
|
212 | 232 | // void CatalogueController::saveDB(const QString& destinationPath, const |
|
213 | 233 | // QString& repositoryName) |
|
214 | 234 | //{ |
General Comments 0
You need to be logged in to leave comments.
Login now