Rumba C++ SDK
Registry.h
Go to the documentation of this file.
1 /*
2 
3  *
4  ***
5  *****
6  ********************* Mercenaries Engineering SARL
7  ***************** Copyright (C) 2018
8  *************
9  ********* http://www.mercenaries-engineering.com
10  ***********
11  **** ****
12  ** **
13 
14 */
15 #pragma once
16 
17 #include "PlugDescriptor.h"
18 #include "Version.h"
19 
33  namespace maquina
34  {
35  class Node;
36  class Value;
37  class NodePlugin;
38  class NodeLoaderPlugin;
40  class Registry
41  {
42  public:
43  virtual ~Registry() {};
44 
46  using Factory = std::function<std::shared_ptr<NodePlugin>( Node *node )>;
47 
49 
50  virtual void register_node(
51  const char *class_name,
52  const char *base_class_name,
53  Factory factory,
54  const std::vector<PlugDescriptor> &plug_desc,
55  const char *ui_descriptor = ""
56  ) = 0;
57 
59 
60  virtual void register_node(
61  const char *class_name,
62  const char *base_class_name,
63  const std::vector<PlugDescriptor> &plug_desc,
64  const char *ui_descriptor = ""
65  ) = 0;
66 
69  virtual void register_node_loader(const std::shared_ptr<NodeLoaderPlugin>& node_loader) = 0;
70 
72  /* \raise{std::runtime_error,RuntimeError} in case the value is already registered or the parent type name does not exist. */
73  template<class UD>
75  const char *parent_type_name = "Value" // The parent's value type_name
76  )
77  {
78  std::shared_ptr<UD> default_value = std::make_shared<UD>();
79  register_value(default_value->type_name().c_str(), default_value, parent_type_name);
80  };
81 
83  /* \raise{std::runtime_error,RuntimeError} in case the value is already registered or the parent type name does not exist. */
84  virtual void register_value(
85  const char *type_name, // The value type_name
86  std::shared_ptr<const maquina::UserData> default_value, /* The UserData for the default_value. That UserData will be shared by all the default value
87  instance of that type. It should not be modified. */
88  const char *parent_type_name = "Value" // The parent's value type_name
89  ) = 0;
90 
91  };
92 
94  MAQUINA_EXPORT Registry& registry();
95 
96  MAQUINA_EXPORT Value default_value(const maquina::StringView& type_name);
97  }
98 
100 #define MAQUINA_DECLARE_PLUGINS extern "C" MAQUINA_DLL_EXPORT int rumba_sdk_version; int rumba_sdk_version = RUMBA_SDK_BETA_VERSION;
101 #define MAQUINA_REGISTER_PLUGINS extern "C" MAQUINA_DLL_EXPORT void rumba_register_plugins( ::maquina::Registry &r )
virtual ~Registry()
Definition: Registry.h:43
const_pointer c_str() const noexcept
Definition: StringView.h:124
This version of the SDK is unstable, i-e, it may change with no warning.
Definition: AddCurveAction.h:20
Registry class used to declare and register a plug-in node.
Definition: Registry.h:40
MAQUINA_EXPORT Value default_value(const maquina::StringView &type_name)
Return the default value of a type.
virtual void register_node(const char *class_name, const char *base_class_name, Factory factory, const std::vector< PlugDescriptor > &plug_desc, const char *ui_descriptor="")=0
Declare a plug-in node.
StringView type_name() const
Return the type name of the Value.
std::function< std::shared_ptr< NodePlugin >(Node *node)> Factory
The factory function prototype.
Definition: Registry.h:46
#define MAQUINA_EXPORT
Definition: Export.h:31
void register_value(const char *parent_type_name="Value")
Register a new type of value.
Definition: Registry.h:74
virtual void register_node_loader(const std::shared_ptr< NodeLoaderPlugin > &node_loader)=0
Declare a node loader plug-in.
Base class of all Rumba nodes.
Definition: Node.h:37