ug4
Loading...
Searching...
No Matches
registry.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2010-2015: G-CSC, Goethe University Frankfurt
3 * Authors: Andreas Vogel, Sebastian Reiter
4 *
5 * This file is part of UG4.
6 *
7 * UG4 is free software: you can redistribute it and/or modify it under the
8 * terms of the GNU Lesser General Public License version 3 (as published by the
9 * Free Software Foundation) with the following additional attribution
10 * requirements (according to LGPL/GPL v3 §7):
11 *
12 * (1) The following notice must be displayed in the Appropriate Legal Notices
13 * of covered and combined works: "Based on UG4 (www.ug4.org/license)".
14 *
15 * (2) The following notice must be displayed at a prominent place in the
16 * terminal output of covered works: "Based on UG4 (www.ug4.org/license)".
17 *
18 * (3) The following bibliography is recommended for citation and must be
19 * preserved in all covered files:
20 * "Reiter, S., Vogel, A., Heppner, I., Rupp, M., and Wittum, G. A massively
21 * parallel geometric multigrid solver on hierarchically distributed grids.
22 * Computing and visualization in science 16, 4 (2013), 151-164"
23 * "Vogel, A., Reiter, S., Rupp, M., Nägel, A., and Wittum, G. UG4 -- a novel
24 * flexible software system for simulating pde based models on high performance
25 * computers. Computing and visualization in science 16, 4 (2013), 165-179"
26 *
27 * This program is distributed in the hope that it will be useful,
28 * but WITHOUT ANY WARRANTY; without even the implied warranty of
29 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
30 * GNU Lesser General Public License for more details.
31 */
32
33#ifndef __H__UG_BRIDGE__REGISTRY__
34#define __H__UG_BRIDGE__REGISTRY__
35
36#include <vector>
37#include <string>
38#include <cstring>
39#include <typeinfo>
40#include <iostream>
41#include <functional>
42#include <type_traits>
43
44#include "global_function.h"
45#include "class.h"
47#include "parameter_stack.h"
48#include "common/ug_config.h"
49
50namespace ug
51{
52namespace bridge
53{
54
61// PREDECLARATIONS
62class Registry;
63
65
70typedef std::function<void (Registry* pReg)> FuncRegistryChanged;
71
72
75{
76 public:
77 ClassGroupDesc() : m_defaultClass(NULL) {}
78
80 void set_name(const std::string& name) {m_name = name;}
81
83 const std::string& name() const {return m_name;}
84
86 void add_class(IExportedClass* c, const std::string& tag)
87 {m_classes.push_back(c); m_classTags.push_back(tag);}
88
90 size_t num_classes() const {return m_classes.size();}
91
93 bool empty() const {return num_classes() == 0;}
94
96 IExportedClass* get_class(size_t i) {return m_classes[i];}
97
99 const IExportedClass* get_class(size_t i) const {return m_classes[i];}
100
102 const std::string& get_class_tag(size_t i) const{return m_classTags[i];}
103
105 void set_default_class(size_t i) {m_defaultClass = m_classes[i];}
106
108 IExportedClass* get_default_class() const {return m_defaultClass;}
109
110 private:
112 std::string m_name;
113
115 std::vector<IExportedClass*> m_classes;
116
118 std::vector<std::string> m_classTags;
119
122};
123
124
126
138 public:
140 Registry();
141
143 ~Registry();
144
146 void set_force_construct_via_smart_pointer(bool bForceConstructionWithSmartPtr);
147
149 // callbacks
151
153 void add_callback(FuncRegistryChanged callback);
154
156 bool registry_changed();
157
159 // global functions
161
178 template<typename TFunc>
179 Registry& add_function(std::string funcName, TFunc func, std::string group = "",
180 std::string retValInfos = "", std::string paramInfos = "",
181 std::string tooltip = "", std::string help = "");
182
184 template<typename TFunc>
186 add_and_get_function(std::string funcName, TFunc func, std::string group = "",
187 std::string retValInfos = "", std::string paramInfos = "",
188 std::string tooltip = "", std::string help = "");
189
191 size_t num_functions() const;
192
194 ExportedFunction& get_function(size_t ind);
195 const ExportedFunction& get_function(size_t ind) const;
196
198 size_t num_overloads(size_t ind) const;
199
201 ExportedFunction& get_overload(size_t funcInd, size_t oInd);
202
204 ExportedFunctionGroup& get_function_group(size_t ind);
205
207 ExportedFunctionGroup* get_exported_function_group(const std::string& name);
208
210 // classes
212
219 template <typename TClass>
220 ExportedClass<TClass>& add_class_(std::string className,
221 std::string group = "",
222 std::string tooltip = "");
223
230 template <typename TClass, typename TBaseClass>
231 ExportedClass<TClass>& add_class_(std::string className,
232 std::string group = "",
233 std::string tooltip = "");
234
241 template <typename TClass, typename TBaseClass1, typename TBaseClass2>
242 ExportedClass<TClass>& add_class_(std::string className,
243 std::string group = "",
244 std::string tooltip = "");
245
247 template <typename TClass>
248 ExportedClass<TClass>& get_class_();
249
251 size_t num_classes() const;
252
254 const IExportedClass& get_class(size_t ind) const;
255
257 IExportedClass* get_class(const std::string& name);
258
260 const IExportedClass* get_class(const std::string& name) const;
261
263 bool check_consistency();
264
265
267 // class-groups
269
271 size_t num_class_groups() const;
272
274 const ClassGroupDesc* get_class_group(size_t i) const;
275
277 ClassGroupDesc* get_class_group(size_t i);
278
280
281 ClassGroupDesc* get_class_group(const std::string& name);
282
284
285 const ClassGroupDesc* get_class_group(const std::string& name) const;
286
288
291 void add_class_to_group(std::string className, std::string groupName,
292 std::string classTag = "");
293
294
296 bool classname_registered(const std::string& name);
297
299 bool groupname_registered(const std::string& name);
300
302 bool functionname_registered(const std::string& name);
303
304 protected:
306 template <typename TClass, typename TBaseClass>
307 void check_base_class(const std::string& className);
308
309 private:
310 // disallow copy
311 Registry(const Registry& reg);
312
314 std::vector<ExportedFunctionGroup*> m_vFunction;
315
317 std::vector<IExportedClass*> m_vClass;
318
320 std::vector<ClassGroupDesc*> m_vClassGroups;
321
323 std::vector<FuncRegistryChanged> m_callbacksRegChanged;
324
327};
328
329// end group registry
331
332} // end namespace registry
333
334} // end namespace ug
335
337// include implementation
338#include "registry_impl.h"
339
340#endif /* __H__UG_BRIDGE__REGISTRY__ */
location name
Definition checkpoint_util.lua:128
groups classes. One of the members is the default member.
Definition registry.h:75
ClassGroupDesc()
Definition registry.h:77
void add_class(IExportedClass *c, const std::string &tag)
adds a class to group
Definition registry.h:86
void set_default_class(size_t i)
sets the i'th class as default
Definition registry.h:105
size_t num_classes() const
returns number of classes in group
Definition registry.h:90
IExportedClass * m_defaultClass
the current default class
Definition registry.h:121
IExportedClass * get_default_class() const
if no default class is set, this method returns NULL.
Definition registry.h:108
std::vector< std::string > m_classTags
tags can be used to describe classes. One tag for each class.
Definition registry.h:118
const std::string & get_class_tag(size_t i) const
returns the class group tag for a class
Definition registry.h:102
void set_name(const std::string &name)
sets name of group
Definition registry.h:80
std::string m_name
name of class group
Definition registry.h:112
bool empty() const
returns if classes in group
Definition registry.h:93
std::vector< IExportedClass * > m_classes
classes registered to the class group
Definition registry.h:115
const IExportedClass * get_class(size_t i) const
returns a class of the group
Definition registry.h:99
const std::string & name() const
returns name of group
Definition registry.h:83
IExportedClass * get_class(size_t i)
returns a class of the group
Definition registry.h:96
This template class represents real c++ classes in the registry.
Definition class.h:702
Groups of Functions - useful to realize overloaded functions.
Definition global_function.h:243
This class describes a wrapper for a c++ - function, that is exported by ug.
Definition global_function.h:186
Base class for exported Classes.
Definition class.h:502
Registry for functions and classes that are exported to scripts and visualizations.
Definition registry.h:137
std::vector< ClassGroupDesc * > m_vClassGroups
registered class groups
Definition registry.h:320
std::vector< ExportedFunctionGroup * > m_vFunction
registered functions
Definition registry.h:314
std::vector< FuncRegistryChanged > m_callbacksRegChanged
Callback, that are called when registry changed is invoked.
Definition registry.h:323
std::vector< IExportedClass * > m_vClass
registered classes
Definition registry.h:317
bool m_bForceConstructionWithSmartPtr
flag if classes must be constructed via smart-pointer
Definition registry.h:326
std::function< void(Registry *pReg)> FuncRegistryChanged
declaration of registry callback function.
Definition registry.h:70
#define UG_API
Definition ug_config.h:65
the ug namespace
function func(x, y, z, t, si)