Loading [MathJax]/extensions/tex2jax.js
Plugins
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
promesh_registry.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2015: G-CSC, Goethe University Frankfurt
3 * Author: 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_promesh_registry
34#define __H__UG_promesh_registry
35
36#include <map>
37#include <set>
38#include <string>
39#include <vector>
40#include "keys.h"
41#include "registry/registry.h"
42#include "boost/mpl/assert.hpp"
43#include "boost/mpl/contains.hpp"
44namespace ug{
45namespace promesh{
46
58
59namespace detail {
60
62
64 public:
66 int priority,
67 int groupPriority,
68 unsigned int target,
69 int shortcutKey = 0,
70 ModifierKeys modifierKey = MK_NONE)
71 :
72 m_exportedFunction(exportedFunction),
73 m_priority(priority),
74 m_groupPriority(groupPriority),
75 m_target(target),
76 m_shortcutKey(shortcutKey),
77 m_modifierKey(modifierKey)
78 {}
79
81 exported_function() {return m_exportedFunction;}
82
84 exported_function() const {return m_exportedFunction;}
85
86 int priority() const {return m_priority;}
87 int group_priority() const {return m_groupPriority;}
88
89 bool has_target(RegistryTargets t) const {return (m_target & t) == t;}
90
91 bool operator < (const ProMeshFunction& f) const
92 {
93 if(m_priority != f.priority())
94 return m_priority < f.priority();
95 if(m_groupPriority != f.group_priority())
96 return m_groupPriority < f.group_priority();
97 if(m_exportedFunction->group() != f.exported_function()->group())
98 return m_exportedFunction->group() < f.exported_function()->group();
99 if(m_exportedFunction->name() != f.exported_function()->name())
100 return m_exportedFunction->name() < f.exported_function()->name();
101 return m_exportedFunction->num_parameter() < f.exported_function()->num_parameter();
102 }
103
104 int shortcut_key() const {return m_shortcutKey;}
105 ModifierKeys shortcut_modifier_key() const {return m_modifierKey;}
106
107 private:
111 unsigned int m_target;
114};
115
116}// end of namespace detail
117
119
123 public:
124 typedef std::multiset<detail::ProMeshFunction> ProMeshFunctionSet;
125 typedef ProMeshFunctionSet::iterator func_iter_t;
126 typedef ProMeshFunctionSet::const_iterator const_func_iter_t;
127
128 ProMeshRegistry(bridge::Registry* reg) : m_reg(reg), m_counter(0) {}
129
146 template<typename TFunc>
147 ProMeshRegistry& add_function( std::string funcName,
148 TFunc func,
149 std::string group = "",
150 std::string retValInfos = "",
151 std::string paramInfos = "",
152 std::string tooltip = "",
153 std::string help = "",
154 unsigned int target = RT_DEFAULT,
155 int shortcutKey = 0,
156 ModifierKeys modifyerKey = MK_NONE)
157 {
158 using namespace bridge;
159 ExportedFunction* ef =
160 m_reg->add_and_get_function(
161 funcName, func, group, retValInfos,
162 paramInfos, tooltip, help);
163
164 int& groupPriority = m_groupPriority[group];
165 if(!groupPriority){
166 groupPriority = m_counter;
167 }
168
169 m_funcSet.insert(
170 detail::ProMeshFunction(ef, m_counter, groupPriority,
171 target, shortcutKey, modifyerKey));
172 ++m_counter;
173 return *this;
174 }
175
182 template <typename TClass>
184 add_class_( std::string className,
185 std::string group = "",
186 std::string tooltip = "")
187 {
188 return m_reg->add_class_<TClass>(className, group, tooltip);
189 }
190
197 template <typename TClass, typename TBaseClass>
199 add_class_( std::string className,
200 std::string group = "",
201 std::string tooltip = "")
202 {
203 return m_reg->add_class_<TClass, TBaseClass>(className, group, tooltip);
204 }
205
212 template <typename TClass, typename TBaseClass1, typename TBaseClass2>
214 add_class_( std::string className,
215 std::string group = "",
216 std::string tooltip = "")
217 {
218 return m_reg->add_class_<TClass, TBaseClass1, TBaseClass2>(
219 className, group, tooltip);
220 }
221
223 bridge::Registry* registry() {return m_reg;}
224
225
226 func_iter_t functions_begin() {return m_funcSet.begin();}
227 const_func_iter_t functions_begin() const {return m_funcSet.begin();}
228 func_iter_t functions_end() {return m_funcSet.end();}
229 const_func_iter_t functions_end() const {return m_funcSet.end();}
230
231 private:
235 std::map<std::string, int> m_groupPriority;
236};
237
239
240}// end of namespace
241}// end of namespace
242
243#endif //__H__UG_promesh_registry
const std::string & name() const
const std::string & group() const
Register functions for ug-script and ProMesh through this class.
Definition promesh_registry.h:122
ProMeshFunctionSet::const_iterator const_func_iter_t
Definition promesh_registry.h:126
std::map< std::string, int > m_groupPriority
Definition promesh_registry.h:235
bridge::ExportedClass< TClass > & add_class_(std::string className, std::string group="", std::string tooltip="")
Register a class at this registry.
Definition promesh_registry.h:184
bridge::ExportedClass< TClass > & add_class_(std::string className, std::string group="", std::string tooltip="")
Register a class at this registry together with its base class.
Definition promesh_registry.h:199
bridge::Registry * m_reg
Definition promesh_registry.h:232
const_func_iter_t functions_end() const
Definition promesh_registry.h:229
ProMeshFunctionSet m_funcSet
Definition promesh_registry.h:233
int m_counter
Definition promesh_registry.h:234
const_func_iter_t functions_begin() const
Definition promesh_registry.h:227
std::multiset< detail::ProMeshFunction > ProMeshFunctionSet
Definition promesh_registry.h:124
bridge::ExportedClass< TClass > & add_class_(std::string className, std::string group="", std::string tooltip="")
Register a class at this registry together with two base classes.
Definition promesh_registry.h:214
ProMeshRegistry(bridge::Registry *reg)
Definition promesh_registry.h:128
func_iter_t functions_begin()
Definition promesh_registry.h:226
ProMeshRegistry & add_function(std::string funcName, TFunc func, std::string group="", std::string retValInfos="", std::string paramInfos="", std::string tooltip="", std::string help="", unsigned int target=RT_DEFAULT, int shortcutKey=0, ModifierKeys modifyerKey=MK_NONE)
adds a function to the registry
Definition promesh_registry.h:147
ProMeshFunctionSet::iterator func_iter_t
Definition promesh_registry.h:125
bridge::Registry * registry()
returns a pointer to the ug::bridge::Registry which is encapsulated by this class.
Definition promesh_registry.h:223
func_iter_t functions_end()
Definition promesh_registry.h:228
All functions registered in the ProMeshRegistry are encapsulated in a ProMeshFunction.
Definition promesh_registry.h:63
int shortcut_key() const
Definition promesh_registry.h:104
int m_shortcutKey
Definition promesh_registry.h:112
int m_groupPriority
Definition promesh_registry.h:110
bridge::ExportedFunction * exported_function()
Definition promesh_registry.h:81
const bridge::ExportedFunction * exported_function() const
Definition promesh_registry.h:84
bridge::ExportedFunction * m_exportedFunction
Definition promesh_registry.h:108
int group_priority() const
Definition promesh_registry.h:87
unsigned int m_target
Definition promesh_registry.h:111
ModifierKeys shortcut_modifier_key() const
Definition promesh_registry.h:105
bool has_target(RegistryTargets t) const
Definition promesh_registry.h:89
int priority() const
Definition promesh_registry.h:86
ModifierKeys m_modifierKey
Definition promesh_registry.h:113
ProMeshFunction(bridge::ExportedFunction *exportedFunction, int priority, int groupPriority, unsigned int target, int shortcutKey=0, ModifierKeys modifierKey=MK_NONE)
Definition promesh_registry.h:65
int m_priority
Definition promesh_registry.h:109
RegistryTargets
Definition promesh_registry.h:49
@ RT_UGSCRIPT
Definition promesh_registry.h:51
@ RT_NO_UGSCRIPT
Definition promesh_registry.h:56
@ RT_NO_PROMESH
Definition promesh_registry.h:55
@ RT_PROMESH
Definition promesh_registry.h:52
@ RT_DEFAULT
Definition promesh_registry.h:54
@ RT_NONE
Definition promesh_registry.h:50
#define UG_API
ModifierKeys
Definition keys.h:39