CommandGeneratorMap.hpp
Go to the documentation of this file.
1 #pragma once
2 #include <score/command/CommandFactoryKey.hpp>
3 #include <score/plugins/StringFactoryKey.hpp>
4 #include <score/tools/Debug.hpp>
5 #include <score/tools/std/HashMap.hpp>
6 
7 #include <ossia/detail/algorithms.hpp>
8 
9 #include <QByteArray>
10 
11 #include <score_lib_base_export.h>
12 
13 namespace score
14 {
15 class Command;
16 }
47 using CommandFactory = score::Command* (*)(const QByteArray&);
48 
54 using CommandGeneratorMap = std::vector<std::pair<CommandKey, CommandFactory>>;
55 
56 namespace score
57 {
58 namespace commands
59 {
60 
66 {
67  CommandGeneratorMap& fact;
68  template <typename TheCommand>
69  void operator()() const
70  {
71  SCORE_ASSERT(bool(ossia::find_if(fact, [](auto& e) {
72  return e.first == TheCommand::static_key();
73  }) == fact.end()));
74  constexpr CommandFactory f = [](const QByteArray& data) -> score::Command* {
75  auto t = new TheCommand;
76  t->deserialize(data);
77  return t;
78  };
79  fact.emplace_back(TheCommand::static_key(), f);
80  }
81 };
82 }
83 }
std::vector< std::pair< CommandKey, CommandFactory > > CommandGeneratorMap
The CommandGeneratorMap struct.
Definition: CommandGeneratorMap.hpp:54
score::Command *(*)(const QByteArray &) CommandFactory
Base factory for commands.
Definition: CommandGeneratorMap.hpp:47
The Command class.
Definition: Command.hpp:34
Base toolkit upon which the software is built.
Definition: Application.cpp:90
Creates and inserts a new factory class for a given command, in a list of such factories.
Definition: CommandGeneratorMap.hpp:66