Loading...
Searching...
No Matches
OfflineAction.hpp
1#pragma once
2#include <score/plugins/InterfaceList.hpp>
3
4#include <ossia/detail/hash_map.hpp>
5#include <ossia/detail/small_vector.hpp>
6
7#include <score_lib_process_export.h>
8namespace score
9{
10class Command;
11class Document;
12struct DocumentContext;
13}
14namespace Process
15{
16class ProcessModel;
17
27class SCORE_LIB_PROCESS_EXPORT OfflineAction : public score::InterfaceBase
28{
29 SCORE_INTERFACE(OfflineAction, "0d9e9135-bf4d-4ef2-b872-21be740f990c")
30public:
31 ~OfflineAction() override;
32
33 virtual QString title() const noexcept = 0;
34 virtual UuidKey<Process::ProcessModel> target() const noexcept = 0;
35 virtual void apply(Process::ProcessModel& proc, const score::DocumentContext&) = 0;
36};
37
38class SCORE_LIB_PROCESS_EXPORT OfflineActionList final
40 , public score::IndirectContainer<OfflineAction>
41{
42public:
43 using OfflineActions = ossia::small_pod_vector<OfflineAction*, 4>;
45 using key_type = typename OfflineAction::ConcreteKey;
47
50
51 OfflineActions
52 actionsForProcess(const UuidKey<Process::ProcessModel>& key) const noexcept;
53
54 static const constexpr score::InterfaceKey static_interfaceKey() noexcept
55 {
56 return OfflineAction::static_interfaceKey();
57 }
58
59 constexpr score::InterfaceKey interfaceKey() const noexcept final override
60 {
61 return OfflineAction::static_interfaceKey();
62 }
63
64 void insert(std::unique_ptr<score::InterfaceBase> e) final override
65 {
66 if(auto result = dynamic_cast<factory_type*>(e.get()))
67 {
68 e.release();
69 std::unique_ptr<factory_type> pf{result};
70 vector_type::push_back(pf.get());
71 actionsMap[result->target()].push_back(pf.get());
72
73 auto k = pf->concreteKey();
74 auto it = this->map.find(k);
75 if(it == this->map.end())
76 {
77 this->map.emplace(std::make_pair(k, std::move(pf)));
78 }
79 else
80 {
81 score::debug_types(it->second.get(), result);
82 it->second = std::move(pf);
83 }
84
85 added(vector_type::back());
86 }
87 }
88
90 OfflineAction* get(const key_type& k) const noexcept
91 {
92 auto it = this->map.find(k);
93 return (it != this->map.end()) ? it->second.get() : nullptr;
94 }
95
96 mutable Nano::Signal<void(const factory_type&)> added;
97
98protected:
99 ossia::hash_map<typename OfflineAction::ConcreteKey, std::unique_ptr<OfflineAction>>
100 map;
101
102 ossia::hash_map<UuidKey<Process::ProcessModel>, OfflineActions> actionsMap;
103
104 void optimize() noexcept final override
105 {
106 // score::optimize_hash_map(this->map);
107 this->map.max_load_factor(0.1f);
108 this->map.reserve(map.size());
109 }
110
111 OfflineActionList(const OfflineActionList&) = delete;
113 OfflineActionList& operator=(const OfflineActionList&) = delete;
114 OfflineActionList& operator=(OfflineActionList&&) = delete;
115};
116}
Interface for applying an offline editing action to a process.
Definition OfflineAction.hpp:28
Definition OfflineAction.hpp:41
OfflineAction * get(const key_type &k) const noexcept
Get a particular factory from its ConcreteKey.
Definition OfflineAction.hpp:90
void optimize() noexcept final override
optimize Called when all the factories are loaded.
Definition OfflineAction.hpp:104
void insert(std::unique_ptr< score::InterfaceBase > e) final override
insert Register a new factory.
Definition OfflineAction.hpp:64
constexpr score::InterfaceKey interfaceKey() const noexcept final override
A key that uniquely identifies this family of factories.
Definition OfflineAction.hpp:59
The Process class.
Definition score-lib-process/Process/Process.hpp:61
Definition UuidKey.hpp:343
Definition IndirectContainer.hpp:129
Base class for plug-in interfaces.
Definition Interface.hpp:52
InterfaceListBase Interface to access factories.
Definition InterfaceList.hpp:29
Base classes and tools to implement processes and layers.
Definition JSONVisitor.hpp:1324
Base toolkit upon which the software is built.
Definition Application.cpp:90
Definition DocumentContext.hpp:18