ug4
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 <boost/function.hpp>
42 #include <boost/type_traits.hpp>
43 
44 
45 #include "global_function.h"
46 #include "class.h"
48 #include "parameter_stack.h"
49 #include "common/ug_config.h"
50 
51 namespace ug
52 {
53 namespace bridge
54 {
55 
62 // PREDECLARATIONS
63 class Registry;
64 
66 
71 typedef boost::function<void (Registry* pReg)> FuncRegistryChanged;
72 
73 
76 {
77  public:
78  ClassGroupDesc() : m_defaultClass(NULL) {}
79 
81  void set_name(const std::string& name) {m_name = name;}
82 
84  const std::string& name() const {return m_name;}
85 
87  void add_class(IExportedClass* c, const std::string& tag)
88  {m_classes.push_back(c); m_classTags.push_back(tag);}
89 
91  size_t num_classes() const {return m_classes.size();}
92 
94  bool empty() const {return num_classes() == 0;}
95 
97  IExportedClass* get_class(size_t i) {return m_classes[i];}
98 
100  const IExportedClass* get_class(size_t i) const {return m_classes[i];}
101 
103  const std::string& get_class_tag(size_t i) const{return m_classTags[i];}
104 
106  void set_default_class(size_t i) {m_defaultClass = m_classes[i];}
107 
109  IExportedClass* get_default_class() const {return m_defaultClass;}
110 
111  private:
113  std::string m_name;
114 
116  std::vector<IExportedClass*> m_classes;
117 
119  std::vector<std::string> m_classTags;
120 
123 };
124 
125 
127 
139  public:
141  Registry();
142 
144  ~Registry();
145 
147  void set_force_construct_via_smart_pointer(bool bForceConstructionWithSmartPtr);
148 
150  // callbacks
152 
154  void add_callback(FuncRegistryChanged callback);
155 
157  bool registry_changed();
158 
160  // global functions
162 
179  template<typename TFunc>
180  Registry& add_function(std::string funcName, TFunc func, std::string group = "",
181  std::string retValInfos = "", std::string paramInfos = "",
182  std::string tooltip = "", std::string help = "");
183 
185  template<typename TFunc>
187  add_and_get_function(std::string funcName, TFunc func, std::string group = "",
188  std::string retValInfos = "", std::string paramInfos = "",
189  std::string tooltip = "", std::string help = "");
190 
192  size_t num_functions() const;
193 
195  ExportedFunction& get_function(size_t ind);
196  const ExportedFunction& get_function(size_t ind) const;
197 
199  size_t num_overloads(size_t ind) const;
200 
202  ExportedFunction& get_overload(size_t funcInd, size_t oInd);
203 
205  ExportedFunctionGroup& get_function_group(size_t ind);
206 
208  ExportedFunctionGroup* get_exported_function_group(const std::string& name);
209 
211  // classes
213 
220  template <typename TClass>
221  ExportedClass<TClass>& add_class_(std::string className,
222  std::string group = "",
223  std::string tooltip = "");
224 
231  template <typename TClass, typename TBaseClass>
232  ExportedClass<TClass>& add_class_(std::string className,
233  std::string group = "",
234  std::string tooltip = "");
235 
242  template <typename TClass, typename TBaseClass1, typename TBaseClass2>
243  ExportedClass<TClass>& add_class_(std::string className,
244  std::string group = "",
245  std::string tooltip = "");
246 
248  template <typename TClass>
249  ExportedClass<TClass>& get_class_();
250 
252  size_t num_classes() const;
253 
255  const IExportedClass& get_class(size_t ind) const;
256 
258  IExportedClass* get_class(const std::string& name);
259 
261  const IExportedClass* get_class(const std::string& name) const;
262 
264  bool check_consistency();
265 
266 
268  // class-groups
270 
272  size_t num_class_groups() const;
273 
275  const ClassGroupDesc* get_class_group(size_t i) const;
276 
278  ClassGroupDesc* get_class_group(size_t i);
279 
281 
282  ClassGroupDesc* get_class_group(const std::string& name);
283 
285 
286  const ClassGroupDesc* get_class_group(const std::string& name) const;
287 
289 
292  void add_class_to_group(std::string className, std::string groupName,
293  std::string classTag = "");
294 
295 
297  bool classname_registered(const std::string& name);
298 
300  bool groupname_registered(const std::string& name);
301 
303  bool functionname_registered(const std::string& name);
304 
305  protected:
307  template <typename TClass, typename TBaseClass>
308  void check_base_class(const std::string& className);
309 
310  private:
311  // disallow copy
312  Registry(const Registry& reg);
313 
315  std::vector<ExportedFunctionGroup*> m_vFunction;
316 
318  std::vector<IExportedClass*> m_vClass;
319 
321  std::vector<ClassGroupDesc*> m_vClassGroups;
322 
324  std::vector<FuncRegistryChanged> m_callbacksRegChanged;
325 
328 };
329 
330 // end group registry
332 
333 } // end namespace registry
334 
335 } // end namespace ug
336 
338 // include implementation
339 #include "registry_impl.h"
340 
341 #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:76
ClassGroupDesc()
Definition: registry.h:78
void add_class(IExportedClass *c, const std::string &tag)
adds a class to group
Definition: registry.h:87
void set_default_class(size_t i)
sets the i'th class as default
Definition: registry.h:106
size_t num_classes() const
returns number of classes in group
Definition: registry.h:91
const std::string & name() const
returns name of group
Definition: registry.h:84
IExportedClass * m_defaultClass
the current default class
Definition: registry.h:122
const std::string & get_class_tag(size_t i) const
returns the class group tag for a class
Definition: registry.h:103
std::vector< std::string > m_classTags
tags can be used to describe classes. One tag for each class.
Definition: registry.h:119
IExportedClass * get_default_class() const
if no default class is set, this method returns NULL.
Definition: registry.h:109
IExportedClass * get_class(size_t i)
returns a class of the group
Definition: registry.h:97
void set_name(const std::string &name)
sets name of group
Definition: registry.h:81
std::string m_name
name of class group
Definition: registry.h:113
const IExportedClass * get_class(size_t i) const
returns a class of the group
Definition: registry.h:100
bool empty() const
returns if classes in group
Definition: registry.h:94
std::vector< IExportedClass * > m_classes
classes registered to the class group
Definition: registry.h:116
This template class represents real c++ classes in the registry.
Definition: class.h:699
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:499
Registry for functions and classes that are exported to scripts and visualizations.
Definition: registry.h:138
std::vector< ClassGroupDesc * > m_vClassGroups
registered class groups
Definition: registry.h:321
std::vector< ExportedFunctionGroup * > m_vFunction
registered functions
Definition: registry.h:315
std::vector< FuncRegistryChanged > m_callbacksRegChanged
Callback, that are called when registry changed is invoked.
Definition: registry.h:324
std::vector< IExportedClass * > m_vClass
registered classes
Definition: registry.h:318
bool m_bForceConstructionWithSmartPtr
flag if classes must be constructed via smart-pointer
Definition: registry.h:327
boost::function< void(Registry *pReg)> FuncRegistryChanged
declaration of registry callback function.
Definition: registry.h:63
#define UG_API
Definition: ug_config.h:65
the ug namespace
function func(x, y, z, t, si)