KratosMultiphysics
KRATOS Multiphysics (Kratos) is a framework for building parallel, multi-disciplinary simulation software, aiming at modularity, extensibility, and high performance. Kratos is written in C++, and counts with an extensive Python interface.
define_registry.h
Go to the documentation of this file.
1 // | / |
2 // ' / __| _` | __| _ \ __|
3 // . \ | ( | | ( |\__ `
4 // _|\_\_| \__,_|\__|\___/ ____/
5 // Multi-Physics
6 //
7 // License: BSD License
8 // Kratos default license: kratos/license.txt
9 //
10 // Main authors: Carlos Roig
11 // Ruben Zorrilla
12 //
13 
14 #pragma once
15 
16 // System includes
17 #include <stdexcept>
18 #include <sstream>
19 
20 
21 // External includes
22 
23 // Project includes
24 #include "includes/registry.h"
25 #include "includes/registry_item.h"
26 
27 #define KRATOS_REGISTRY_NAME_(A,B) A##B
28 #define KRATOS_REGISTRY_NAME(A,B) KRATOS_REGISTRY_NAME_(A,B)
29 
43 #define KRATOS_REGISTRY_ADD_PROTOTYPE(NAME, X, Y) \
44  static inline bool KRATOS_REGISTRY_NAME(_is_registered_, __LINE__) = []() -> bool { \
45  using TFunctionType = std::function<std::shared_ptr<X>()>; \
46  std::string key_name = NAME + std::string(".") + std::string(#Y); \
47  if (!Registry::HasItem(key_name)) \
48  { \
49  auto &r_item = Registry::AddItem<RegistryItem>(key_name); \
50  TFunctionType dispatcher = [](){return std::make_shared<Y>();}; \
51  r_item.AddItem<TFunctionType>("Prototype", std::move(dispatcher)); \
52  } \
53  return Registry::HasItem(key_name); \
54  }();
55 
56 #define KRATOS_REGISTRY_ADD_TEMPLATE_PROTOTYPE(NAME, X, Y, ...) \
57  static inline bool KRATOS_REGISTRY_NAME(_is_registered_, __LINE__) = []() -> bool { \
58  using TFunctionType = std::function<std::shared_ptr<X>()>; \
59  std::string key_name = NAME + std::string(".") + std::string(#Y) + "<" + Kratos::Registry::RegistryTemplateToString(__VA_ARGS__) + ">"; \
60  if (!Registry::HasItem(key_name)) \
61  { \
62  auto &r_item = Registry::AddItem<RegistryItem>(key_name); \
63  TFunctionType dispatcher = [](){return std::make_shared<Y<__VA_ARGS__>>();}; \
64  r_item.AddItem<TFunctionType>("Prototype", std::move(dispatcher)); \
65  } else { \
66  } \
67  return Registry::HasItem(key_name); \
68  }();