ug4
Loading...
Searching...
No Matches
class.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2010-2015: G-CSC, Goethe University Frankfurt
3 * Author: Andreas Vogel
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
34#ifndef __H__UG_BRIDGE__CLASS__
35#define __H__UG_BRIDGE__CLASS__
36
37#include <cstdlib>
38#include <cstring>
39#include <string>
40
41#include <type_traits> // for std::is_void
42
43// std::optional is Cxx17 and not yet supported by all compilers, so we use boost::optional for now
44#include <boost/optional.hpp> // for boost::optional
45
46#include "parameter_stack.h"
47#include "function_traits.h"
48#include "global_function.h"
49#include "common/common.h"
50#include "error.h"
51#include "registry_util.h"
52
53#ifdef PROFILE_BRIDGE
54#ifndef UG_PROFILER
55 #error "You need to define UG_PROFILER to use PROFILE_BRIDGE"
56#endif
58#else
59#endif
60
61
62namespace ug
63{
64namespace bridge
65{
66
69
71{
72 public:
73 template <typename TMethod>
75 {
76 size = sizeof(TMethod);
77 data = malloc(size);
78 memcpy(data, &m, size);
79 }
80
82 {
83 size = mpw.size;
84 data = malloc(size);
85 memcpy(data, mpw.get_raw_ptr(), size);
86 }
87
89
90 void* get_raw_ptr() const {return data;}
91
92 protected:
93 void* data;
94 int size;
95};
96
98template <class TClass> void CastAndDelete(const void* ptr)
99{
100 delete reinterpret_cast<const TClass*>(ptr);
101}
102
103template <> inline void CastAndDelete<void>(const void* ptr)
104{
105 UG_THROW("Can't delete instance of class 'void'");
106}
107
108
113{
114 public:
115 // all c++ functions are wrapped by a proxy function of the following type
116 typedef void (*ProxyFunc)(const MethodPtrWrapper& func, void* obj,
117 const ParameterStack& in, ParameterStack& out);
118
119 public:
121 const std::string& name, const std::string& className,
122 const std::string& methodOptions,
123 const std::string& retValInfos, const std::string& paramInfos,
124 const std::string& tooltip, const std::string& help)
125 : ExportedFunctionBase(name, methodOptions, retValInfos, paramInfos, tooltip, help),
126 m_ptrWrapper(m), m_proxy_func(pf), m_className(className)
127#ifdef PROFILE_BRIDGE
128 ,m_dpi((m_className + ":" + name).c_str(), true, "registry", false)
129#endif
130 {
131 }
132
134 void execute(void* obj, const ParameterStack& paramsIn, ParameterStack& paramsOut) const
135 {
136#ifdef PROFILE_BRIDGE
137 m_dpi.beginNode();
138#endif
139 m_proxy_func(m_ptrWrapper, obj, paramsIn, paramsOut);
140
141#ifdef PROFILE_BRIDGE
142 m_dpi.endNode();
143#endif
144 }
145
147 template <typename TFunc>
149 {
150 ExportedFunctionBase::create_parameter_stack<TFunc>();
152 }
153
155 const std::string& class_name() const {return m_className;}
156
158 bool has_custom_return() const {return m_customReturn;}
159
160 private:
163
166
168 std::string m_className;
169
171
172#ifdef PROFILE_BRIDGE
173 mutable RuntimeProfileInfo m_dpi;
174#endif
175};
176
178// ExportedMethodGroup (sreiter)
180
183{
185
186 public:
187 ExportedMethodGroup(const std::string& name) : m_name(name)
188 {}
189
191 {
192 for(size_t i = 0; i < m_overloads.size(); ++i)
193 delete m_overloads[i].m_func;
194 }
195
197 const std::string& name() const {return m_name;}
198
200 template <class TFunc>
201 bool add_overload( const TFunc& m, ProxyFunc pf,
202 const std::string& className,
203 const std::string& methodOptions, const std::string& retValInfos,
204 const std::string& paramInfos, const std::string& tooltip,
205 const std::string& help)
206 {
207 size_t typeID = GetUniqueTypeID<TFunc>();
208
209 // make sure that the overload didn't exist
210 if(get_overload_by_type_id(typeID))
211 return false;
212
213 // create a new overload
215 pf, m_name, className,
216 methodOptions, retValInfos,
217 paramInfos, tooltip, help);
218
219 m_overloads.push_back(Overload(func, typeID));
220
221
222 // create parameter in list
223 func->create_parameter_stack<TFunc>();
224
225 return true;
226 }
227
228 size_t num_overloads() const {return m_overloads.size();}
229
230 ExportedMethod* get_overload(size_t index) {return m_overloads.at(index).m_func;}
231
232 const ExportedMethod* get_overload(size_t index) const {return m_overloads.at(index).m_func;}
233
234 template <class TType>
236 {
237 size_t typeID = GetUniqueTypeID<TType>();
238 return get_overload_by_type_id(typeID);
239 }
240
241 template <class TType>
243 {
244 size_t typeID = GetUniqueTypeID<TType>();
245 return get_overload_by_type_id(typeID);
246 }
247
249 {
250 for(size_t i = 0; i < m_overloads.size(); ++i){
251 if(m_overloads[i].m_typeID == typeID)
252 return m_overloads[i].m_func;
253 }
254 return NULL;
255 }
256
257 const ExportedMethod* get_overload_by_type_id(size_t typeID) const
258 {
259 for(size_t i = 0; i < m_overloads.size(); ++i){
260 if(m_overloads[i].m_typeID == typeID)
261 return m_overloads[i].m_func;
262 }
263 return NULL;
264 }
265
266 size_t get_overload_type_id(size_t index) const {return m_overloads.at(index).m_typeID;}
267
268 private:
269 struct Overload{
271 Overload(ExportedMethod* func, size_t typeID)
272 : m_func(func), m_typeID(typeID)
273 {}
275 size_t m_typeID;
276 };
277
278 std::string m_name;
279 std::vector<Overload> m_overloads;
280};
281
282template <typename TClass, typename TMethod,
283 typename TRet = typename func_traits<TMethod>::return_type>
285{
286 static void apply(const MethodPtrWrapper& method, void* obj,
287 const ParameterStack& in, ParameterStack& out)
288 {
289 // cast to method pointer
290 TMethod mptr = *(TMethod*) method.get_raw_ptr();
291
292 // cast object to type
293 TClass* objPtr = (TClass*) (obj);
294
295 // get parameter
296 typedef typename func_traits<TMethod>::params_type params_type;
298
299 // apply method
300 TRet res = func_traits<TMethod>::apply(mptr, objPtr, args);
301
302 // write return value
303 out.push<TRet>(res);
304 }
305};
306
307template <typename TClass, typename TMethod>
308struct MethodProxy<TClass, TMethod, void>
309{
310 static void apply(const MethodPtrWrapper& method, void* obj,
311 const ParameterStack& in, ParameterStack& out)
312 {
313 // cast to method pointer
314 TMethod mptr = *(TMethod*) method.get_raw_ptr();
315
316 // cast object to type
317 TClass* objPtr = (TClass*) (obj);
318
319 // get parameter
320 typedef typename func_traits<TMethod>::params_type params_type;
322
323 // apply method
324 func_traits<TMethod>::apply(mptr, objPtr, args);
325 }
326};
327
328template <typename TClass, typename TMethod>
329struct MethodProxy<TClass, TMethod, CustomReturn>
330{
331 static void apply(const MethodPtrWrapper& method, void* obj,
332 const ParameterStack& in, ParameterStack& out)
333 {
334 // cast to method pointer
335 TMethod mptr = *(TMethod*) method.get_raw_ptr();
336
337 // cast object to type
338 TClass* objPtr = (TClass*) (obj);
339
340 // get parameter
341 typedef typename func_traits<TMethod>::params_type params_type;
343
344 // apply method
345 func_traits<TMethod>::apply(mptr, objPtr, args);
346 }
347};
348
349
351// Exported Constructor
353
356{
357 public:
358 // all c++ functions are wrapped by a proxy function of the following type
359 typedef void* (*ProxyFunc)(const ParameterStack& in);
360
361 public:
362 ExportedConstructor(ProxyFunc pf,
363 const std::string& className, const std::string& options,
364 const std::string& paramInfos,
365 const std::string& tooltip, const std::string& help);
366
368 void* create(const ParameterStack& paramsIn) const
369 {
370#ifdef PROFILE_BRIDGE
371 m_dpi.beginNode();
372#endif
373
374 void *pRet = m_proxy_func(paramsIn);
375
376#ifdef PROFILE_BRIDGE
377 m_dpi.endNode();
378#endif
379 return pRet;
380 }
381
383 const std::string& options() const {return m_options;}
384
386 size_t num_parameter() const {return m_vvParamInfo.size();}
387
389 size_t num_infos(size_t i) const {return m_vvParamInfo.at(i).size();}
390
392 const std::string& parameter_name(size_t i) const {return parameter_info(i, 0);}
393
395 const std::string& parameter_info(size_t i, size_t j) const {return m_vvParamInfo.at(i).at(j);}
396
398 const std::vector<std::string>& parameter_info_vec(size_t i) const {return m_vvParamInfo.at(i);}
399
401 const std::string& parameter_info_string() const {return m_paramInfos;}
402
404 const std::string& tooltip() const {return m_tooltip;}
405
407 const std::string& help() const {return m_help;}
408
410 const ParameterInfo& params_in() const {return m_paramsIn;}
411
413 ParameterInfo& params_in() {return m_paramsIn;}
414
416 bool check_consistency(std::string classname) const;
417
418 template <typename TFunc>
420 {
421 typedef typename func_traits<TFunc>::params_type params_type;
423
424 // arbitrary choosen minimum number of infos exported
425 // (If values non given we set them to an empty string)
426 const size_t MinNumInfos = 3; // for "name | style | options"
427
428 // Fill missing Parameter
429 m_vvParamInfo.resize(m_paramsIn.size());
430
431 // resize missing infos for each parameter
432 for(int i = 0; i < (int)m_vvParamInfo.size(); ++i)
433 for(size_t j = m_vvParamInfo.at(i).size(); j < MinNumInfos; ++j)
434 m_vvParamInfo.at(i).push_back(std::string(""));
435 }
436
437 protected:
438 // help function to tokenize the parameter string
439 void tokenize(const std::string& str, std::vector<std::string>& tokens,
440 const char delimiter);
441
442 protected:
443 private:
445 ProxyFunc m_proxy_func;
446
448 std::string m_className;
449
451 std::string m_options;
452
454 std::string m_paramInfos;
455
457 std::vector<std::vector<std::string> > m_vvParamInfo;
458
459 std::string m_tooltip;
460 std::string m_help;
461
463
464#ifdef PROFILE_BRIDGE
465 mutable RuntimeProfileInfo m_dpi;
466#endif
467};
468
469template <typename TClass, typename TMethod>
471{
472 static void* create(const ParameterStack& in)
473 {
474 // get parameter
475 typedef typename func_traits<TMethod>::params_type params_type;
477
478 // apply method
480
481 // return new pointer
482 return (void*) newInst;
483 }
484};
485
486template <typename TClass>
487void DestructorProxy(void* obj)
488{
489 TClass* pObj = (TClass*)obj;
490 delete pObj;
491}
492
494// Interface Exported Class
496
497
499
502{
503 public:
504 typedef void (*DeleteFunction)(const void*);
505
506 public:
508 virtual const std::string& name() const = 0;
509
511 virtual const std::string& group() const = 0;
512
514 virtual const ClassNameNode& class_name_node() const = 0;
515
517 virtual const std::string& tooltip() const = 0;
518
520 virtual const std::vector<const char*>* class_names() const = 0;
521
523 virtual size_t num_methods() const = 0;
524
526 virtual size_t num_const_methods() const = 0;
527
529 virtual const ExportedMethod& get_method(size_t i) const = 0;
530
532 virtual const ExportedMethod& get_const_method(size_t i) const = 0;
533
535 virtual size_t num_overloads(size_t funcInd) const = 0;
536
538 virtual size_t num_const_overloads(size_t funcInd) const = 0;
539
541 virtual const ExportedMethod& get_overload(size_t funcInd, size_t oInd) const = 0;
542
544 virtual const ExportedMethod& get_const_overload(size_t funcInd, size_t oInd) const = 0;
545
547 virtual const ExportedMethodGroup& get_method_group(size_t ind) const = 0;
548
550 virtual const ExportedMethodGroup& get_const_method_group(size_t ind) const = 0;
551
552 virtual const ExportedMethodGroup* get_exported_method_group(const std::string& name) const = 0;
553
554 virtual const ExportedMethodGroup* get_const_exported_method_group(const std::string& name) const = 0;
555
558 virtual bool is_instantiable() const = 0;
559
561 virtual size_t num_constructors() const = 0;
562
564 virtual const ExportedConstructor& get_constructor(size_t i) const = 0;
565
567 virtual const boost::optional<ExportedConstructor&> get_json_constructor() const = 0;
568
570 virtual bool is_json_constructible() const = 0;
571
573 virtual bool construct_as_smart_pointer() const = 0;
574
576 virtual void destroy(void* obj) const = 0;
577
580
582 virtual bool check_consistency() const;
583
585 virtual ~IExportedClass() {};
586};
587
589
591{
592 private:
593 // disallow
596
597 public:
598 ExportedClassBaseImpl(const std::string& tooltip);
599
601 virtual ~ExportedClassBaseImpl();
602
604 virtual const std::string& tooltip() const;
605
607 virtual size_t num_methods() const;
608
610 virtual size_t num_const_methods() const;
611
613 virtual const ExportedMethod& get_method(size_t i) const;
614
616 virtual const ExportedMethod& get_const_method(size_t i) const;
617
619 virtual size_t num_overloads(size_t funcInd) const;
620
622 virtual size_t num_const_overloads(size_t funcInd) const;
623
625 virtual const ExportedMethod& get_overload(size_t funcInd, size_t oInd) const;
626
628 virtual const ExportedMethod& get_const_overload(size_t funcInd, size_t oInd) const;
629
631 virtual const ExportedMethodGroup& get_method_group(size_t ind) const;
632
634 virtual const ExportedMethodGroup& get_const_method_group(size_t ind) const;
635
636 virtual const ExportedMethodGroup* get_exported_method_group(const std::string& name) const;
637
638 virtual const ExportedMethodGroup* get_const_exported_method_group(const std::string& name) const;
639
641 virtual size_t num_constructors() const;
642
644 virtual const ExportedConstructor& get_constructor(size_t i) const;
645
647 virtual const boost::optional<ExportedConstructor&> get_json_constructor() const;
648
650 virtual bool construct_as_smart_pointer() const;
651
653
654 virtual void set_construct_as_smart_pointer(bool enable);
655
657 virtual bool is_instantiable() const;
658
660 virtual void destroy(void* obj) const;
661
662 protected:
664 bool constructor_type_id_registered(size_t typeID);
665
667 bool constmethodname_registered(const std::string& name);
668
670 bool methodname_registered(const std::string& name);
671
673
675
676 protected:
685
686 std::vector<ConstructorOverload> m_vConstructor;
687
688 typedef void (*DestructorFunc)(void*);
690
691 std::vector<ExportedMethodGroup*> m_vMethod;
692 std::vector<ExportedMethodGroup*> m_vConstMethod;
693 std::string m_tooltip;
694
696};
697
698
700template <typename TClass>
702{
703 private:
704 // disallow
707
708 public:
709 // contructor
710 ExportedClass(const std::string& name, const std::string& group,
711 const std::string& tooltip)
713 {
716 }
717
719 virtual ~ExportedClass(){}
720
722 virtual const std::string& name() const {return ClassNameProvider<TClass>::name();}
723
726
728 virtual const std::string& group() const {return ClassNameProvider<TClass>::group();}
729
731 virtual bool is_json_constructible() const { return std::is_base_of<JSONConstructible, TClass>::value; }
732
733 //\todo: remove this method, use class name nodes instead
735 virtual const std::vector<const char*>* class_names() const {return &ClassNameProvider<TClass>::names();}
736
737 template<typename T>
739 {
740 return t.add_to(*this);
741 }
743
754 template <typename TMethod>
755 ExportedClass<TClass>& add_method (std::string methodName, TMethod func,
756 std::string retValInfos = "", std::string paramInfos = "",
757 std::string tooltip = "", std::string help = "")
758 {
759 // At this point the method name contains parameters (name|param1=...).
760 //todo: they should be removed and specified with an extra parameter.
761
762 std::string strippedMethodName = methodName;
763 std::string methodOptions;
764 std::string::size_type pos = strippedMethodName.find("|");
765 if(pos != std::string::npos){
766 methodOptions = strippedMethodName.substr(pos + 1, strippedMethodName.length() - pos);
767 strippedMethodName = strippedMethodName.substr(0, pos);
768 }
769
770 // trim whitespaces
771 strippedMethodName = TrimString(strippedMethodName);
772 methodOptions = TrimString(methodOptions);
773
774 // check that name is not empty
775 if(strippedMethodName.empty())
776 {
777 UG_THROW_REGISTRY_ERROR(strippedMethodName,
778 "Trying to register empty method name.");
779 }
780
781 // check that name does not contain illegal characters
782 if (!IsValidRegistryIdentifier(strippedMethodName)) {
783 UG_THROW_REGISTRY_ERROR(strippedMethodName,
784 "Trying to register method '"<< strippedMethodName << "' that"
785 << " contains illegal characters. "
787 }
788
789 // if the method is already in use, we have to add an overload.
790 // If not, we have to create a new method group
791 ExportedMethodGroup* methodGrp = NULL;
793 methodGrp = get_const_exported_method_group(strippedMethodName);
794 else
795 methodGrp = get_exported_method_group(strippedMethodName);
796
797 if(!methodGrp){
798 methodGrp = new ExportedMethodGroup(strippedMethodName);
800 m_vConstMethod.push_back(methodGrp);
801 else
802 m_vMethod.push_back(methodGrp);
803 }
804
805 bool success = methodGrp->add_overload(func, &MethodProxy<TClass, TMethod>::apply,
807 methodOptions, retValInfos, paramInfos,
808 tooltip, help);
809
810 if(!success)
811 {
813 "Trying to register method name '" << strippedMethodName
814 << "' to class '" << name() << "', but another method with this name "
815 << " and the same function signature is already registered for this class.");
816 }
817
818 return *this;
819 }
820
823 {
824 // add also in new style
825 add_constructor<void (*)()>();
826
827 // remember constructor proxy
828 m_destructor = &DestructorProxy<TClass>;
829
830 return *this;
831 }
832
834
842 template <typename TFunc>
843 ExportedClass<TClass>& add_constructor(std::string paramInfos = "",
844 std::string tooltip = "", std::string help = "",
845 std::string options = "")
846 {
847 // return-type must be void
848 if(!(std::is_void< typename func_traits<TFunc>::return_type >::value))
849 {
851 "Trying to register constructor of class "
852 <<name()<<"with non-void return value in signature function.");
853 }
854
855 // type id of constructor
856 size_t typeID = GetUniqueTypeID<TFunc>();
857
858 // make sure that the overload didn't exist
860 {
862 "Trying to register constructor of class "
863 <<name()<<" with same signature twice.");
864 }
865
866 // create new exported constructor
867 ExportedConstructor* expConstr
870 options, paramInfos, tooltip, help);
871
872 // create parameter stack
873 expConstr->create_parameter_stack<TFunc>();
874
875 // rememeber it
876 m_vConstructor.push_back(ConstructorOverload(expConstr, typeID));
877
878 // done
879 return *this;
880 }
881
884 {
885 return CastAndDelete<TClass>;
886 }
887};
888
889// end group registry
891
892} // end namespace bridge
893} // end namespace ug
894
895
896#endif /* __H__UG_BRIDGE__CLASS__ */
node for class names
Definition class_name_provider.h:65
provides the name for a class
Definition class_name_provider.h:102
static const ClassNameNode & class_name_node()
return the class name node in the class hierarchy
Definition class_name_provider.h:136
static const std::string & group()
groups
Definition class_name_provider.h:130
static const std::string & name()
name of this class
Definition class_name_provider_impl.h:152
static void set_name(const std::string &nameIn, const std::string &group, bool newName=false)
set name of class and copy parent names
Definition class_name_provider_impl.h:51
static const std::vector< const char * > & names()
returns vector of all names including parent class names
Definition class_name_provider_impl.h:162
Definition function_traits.h:56
A base implementation with non-template methods.
Definition class.h:591
virtual size_t num_constructors() const
number of registered constructors
Definition class.cpp:256
void(* DestructorFunc)(void *)
Definition class.h:688
ExportedClassBaseImpl()
Definition class.cpp:159
std::string m_tooltip
Definition class.h:693
std::vector< ExportedMethodGroup * > m_vConstMethod
Definition class.h:692
virtual bool construct_as_smart_pointer() const
returns whether the class shall be wrapped in a SmartPtr on construction
Definition class.cpp:281
virtual size_t num_const_methods() const
number of registered const-methods (overloads are not counted)
Definition class.cpp:202
virtual void destroy(void *obj) const
destructur for object
Definition class.cpp:299
virtual size_t num_overloads(size_t funcInd) const
returns the number of overloads of a method
Definition class.cpp:220
virtual const ExportedConstructor & get_constructor(size_t i) const
get exported constructor
Definition class.cpp:262
virtual const ExportedMethod & get_method(size_t i) const
returns the first overload of an exported function
Definition class.cpp:208
virtual size_t num_const_overloads(size_t funcInd) const
returns the number of overloads of a const method
Definition class.cpp:226
bool constmethodname_registered(const std::string &name)
returns true if methodname is already used by a method in this class
Definition class.cpp:316
virtual bool is_instantiable() const
is instantiable
Definition class.cpp:293
std::vector< ExportedMethodGroup * > m_vMethod
Definition class.h:691
virtual size_t num_methods() const
number of registered methods (overloads are not counted)
Definition class.cpp:196
virtual void set_construct_as_smart_pointer(bool enable)
sets whether the class shall be wrapped in a SmartPtr
Definition class.cpp:287
virtual const ExportedMethodGroup * get_exported_method_group(const std::string &name) const
Definition class.cpp:346
bool constructor_type_id_registered(size_t typeID)
returns if a constructor overload is registered
Definition class.cpp:306
virtual const ExportedMethodGroup & get_const_method_group(size_t ind) const
returns the i-th method group (all overloads of the i-th function)
Definition class.cpp:250
virtual const boost::optional< ExportedConstructor & > get_json_constructor() const
get constructor for construction from json
Definition class.cpp:268
virtual ~ExportedClassBaseImpl()
destructor
Definition class.cpp:175
virtual const ExportedMethod & get_const_method(size_t i) const
returns the first overload of an exported const function
Definition class.cpp:214
virtual const ExportedMethodGroup * get_const_exported_method_group(const std::string &name) const
Definition class.cpp:366
virtual const ExportedMethodGroup & get_method_group(size_t ind) const
returns the i-th method group (all overloads of the i-th function)
Definition class.cpp:244
virtual const ExportedMethod & get_const_overload(size_t funcInd, size_t oInd) const
returns the i-th overload of a const method
Definition class.cpp:238
std::vector< ConstructorOverload > m_vConstructor
Definition class.h:686
bool m_constructAsSmartPtr
Definition class.h:695
bool methodname_registered(const std::string &name)
returns true if methodname is already used by a method in this class
Definition class.cpp:326
DestructorFunc m_destructor
Definition class.h:689
virtual const std::string & tooltip() const
tooltip
Definition class.cpp:190
virtual const ExportedMethod & get_overload(size_t funcInd, size_t oInd) const
returns the i-th overload of a method
Definition class.cpp:232
This template class represents real c++ classes in the registry.
Definition class.h:702
virtual const ClassNameNode & class_name_node() const
name node of class
Definition class.h:725
virtual const std::string & group() const
get groups
Definition class.h:728
virtual DeleteFunction get_delete_function() const
return pointer to the delete method
Definition class.h:883
virtual bool is_json_constructible() const
is json constructible
Definition class.h:731
ExportedClass(const std::string &name, const std::string &group, const std::string &tooltip)
Definition class.h:710
ExportedClass()
Definition class.h:705
virtual ~ExportedClass()
destructor
Definition class.h:719
ExportedClass< TClass > & add_(T t)
Definition class.h:738
ExportedClass< TClass > & add_constructor()
Make default constructor accessible.
Definition class.h:822
virtual const std::vector< const char * > * class_names() const
class-hierarchy
Definition class.h:735
virtual const std::string & name() const
name of class
Definition class.h:722
ExportedClass< TClass > & add_method(std::string methodName, TMethod func, std::string retValInfos="", std::string paramInfos="", std::string tooltip="", std::string help="")
Method registration.
Definition class.h:755
ExportedClass< TClass > & add_constructor(std::string paramInfos="", std::string tooltip="", std::string help="", std::string options="")
constructor registration
Definition class.h:843
ExportedClass(const ExportedClass &other)
describing information for constructor
Definition class.h:356
std::string m_options
options
Definition class.h:451
std::string m_paramInfos
string with Infos about parameter
Definition class.h:454
std::vector< std::vector< std::string > > m_vvParamInfo
tokenized strings for each Parameter and each Info (name | style | options | ...)
Definition class.h:457
std::string m_className
name of class constructed
Definition class.h:448
ParameterInfo m_paramsIn
Definition class.h:462
ProxyFunc m_proxy_func
proxy function to call method
Definition class.h:445
size_t num_infos(size_t i) const
number of info strings for one parameter
Definition class.h:389
const std::vector< std::string > & parameter_info_vec(size_t i) const
type info of i th parameters
Definition class.h:398
std::string m_help
Definition class.h:460
const std::string & parameter_info_string() const
whole string of all type infos for of all parameters
Definition class.h:401
const std::string & help() const
help informations
Definition class.h:407
void * create(const ParameterStack &paramsIn) const
executes the function
Definition class.h:368
size_t num_parameter() const
number of parameters.
Definition class.h:386
ParameterInfo & params_in()
non-const export of param list
Definition class.h:413
const std::string & parameter_name(size_t i) const
name of parameter i
Definition class.h:392
const std::string & parameter_info(size_t i, size_t j) const
type info of all parameters
Definition class.h:395
const std::string & options() const
options
Definition class.h:383
void create_parameter_stack()
Definition class.h:419
std::string m_tooltip
Definition class.h:459
const ParameterInfo & params_in() const
parameter list for input values
Definition class.h:410
const std::string & tooltip() const
gives some information to the exported functions
Definition class.h:404
Base class for function/method export.
Definition global_function.h:66
const std::string & help() const
help informations
Definition global_function.h:112
const std::string & tooltip() const
gives some information to the exported functions
Definition global_function.h:109
const std::string & name() const
name of function
Definition global_function.h:73
Groups of methods - useful to realize overloaded methods.
Definition class.h:183
bool add_overload(const TFunc &m, ProxyFunc pf, const std::string &className, const std::string &methodOptions, const std::string &retValInfos, const std::string &paramInfos, const std::string &tooltip, const std::string &help)
adds an overload. Returns false if the overload already existed.
Definition class.h:201
~ExportedMethodGroup()
Definition class.h:190
const ExportedMethod * get_overload(size_t index) const
Definition class.h:232
ExportedMethod * get_overload_by_type_id(size_t typeID)
Definition class.h:248
ExportedMethodGroup(const std::string &name)
Definition class.h:187
size_t get_overload_type_id(size_t index) const
Definition class.h:266
const ExportedMethod * get_overload_by_type() const
Definition class.h:242
std::string m_name
Definition class.h:278
const std::string & name() const
name of function group
Definition class.h:197
const ExportedMethod * get_overload_by_type_id(size_t typeID) const
Definition class.h:257
ExportedMethod::ProxyFunc ProxyFunc
Definition class.h:184
size_t num_overloads() const
Definition class.h:228
ExportedMethod * get_overload(size_t index)
Definition class.h:230
std::vector< Overload > m_overloads
Definition class.h:279
ExportedMethod * get_overload_by_type()
Definition class.h:235
Definition class.h:113
std::string m_className
name of class this method belongs to
Definition class.h:168
bool has_custom_return() const
returns true if this method handles its own return of values to lua
Definition class.h:158
bool m_customReturn
Definition class.h:170
void create_parameter_stack()
Definition class.h:148
const std::string & class_name() const
returns the class name this method belongs to
Definition class.h:155
MethodPtrWrapper m_ptrWrapper
pointer to function (stored in a wrapper)
Definition class.h:162
void execute(void *obj, const ParameterStack &paramsIn, ParameterStack &paramsOut) const
executes the function
Definition class.h:134
ProxyFunc m_proxy_func
proxy function to call method
Definition class.h:165
ExportedMethod(const MethodPtrWrapper &m, ProxyFunc pf, const std::string &name, const std::string &className, const std::string &methodOptions, const std::string &retValInfos, const std::string &paramInfos, const std::string &tooltip, const std::string &help)
Definition class.h:120
void(* ProxyFunc)(const MethodPtrWrapper &func, void *obj, const ParameterStack &in, ParameterStack &out)
Definition class.h:116
Base class for exported Classes.
Definition class.h:502
virtual bool check_consistency() const
returns false is consistency-check failed
Definition class.cpp:114
virtual void destroy(void *obj) const =0
destructur for object
virtual bool is_instantiable() const =0
virtual const ExportedConstructor & get_constructor(size_t i) const =0
get exported constructor
virtual const ExportedMethod & get_const_method(size_t i) const =0
get exported const-method
virtual const ExportedMethod & get_method(size_t i) const =0
get exported method
virtual const boost::optional< ExportedConstructor & > get_json_constructor() const =0
get constructor for construction from json
virtual const ExportedMethodGroup * get_exported_method_group(const std::string &name) const =0
virtual size_t num_methods() const =0
number of method of the class
virtual const ClassNameNode & class_name_node() const =0
name node of class
virtual size_t num_constructors() const =0
number of registered constructors
virtual const ExportedMethodGroup * get_const_exported_method_group(const std::string &name) const =0
virtual size_t num_overloads(size_t funcInd) const =0
returns the number of overloads of a method
virtual const std::string & group() const =0
get groups
void(* DeleteFunction)(const void *)
Definition class.h:504
virtual size_t num_const_methods() const =0
number of registered const-methods
virtual size_t num_const_overloads(size_t funcInd) const =0
returns the number of overloads of a const method
virtual const ExportedMethodGroup & get_const_method_group(size_t ind) const =0
returns the i-th method group (all overloads of the i-th function)
virtual const std::vector< const char * > * class_names() const =0
name-list of class hierarchy
virtual DeleteFunction get_delete_function() const =0
returns a function which will call delete on the object
virtual const std::string & name() const =0
name of class
virtual ~IExportedClass()
virtual destructor
Definition class.h:585
virtual const ExportedMethod & get_const_overload(size_t funcInd, size_t oInd) const =0
returns the i-th overload of a const method
virtual bool is_json_constructible() const =0
get constructor for construction from json
virtual const std::string & tooltip() const =0
get tooltip
virtual const ExportedMethodGroup & get_method_group(size_t ind) const =0
returns the i-th method group (all overloads of the i-th function)
virtual bool construct_as_smart_pointer() const =0
true if the class shall be wrapped in a SmartPtr on construction
virtual const ExportedMethod & get_overload(size_t funcInd, size_t oInd) const =0
returns the i-th overload of a method
Definition class.h:498
Definition class.h:71
int size
Definition class.h:94
MethodPtrWrapper(TMethod m)
Definition class.h:74
MethodPtrWrapper(const MethodPtrWrapper &mpw)
Definition class.h:81
~MethodPtrWrapper()
Definition class.h:88
void * data
Definition class.h:93
void * get_raw_ptr() const
Definition class.h:90
a stack holding parameter infos about a parameter stack
Definition parameter_stack.h:73
A stack that can hold values together with their type-id.
Definition parameter_stack.h:270
void push(void *ptr, const ClassNameNode *classNameNode)
Definition parameter_stack.h:367
void CastAndDelete< void >(const void *ptr)
Definition class.h:103
void DestructorProxy(void *obj)
Definition class.h:487
void CastAndDelete(const void *ptr)
Performs a reinterpret cast on the given pointer, then calls delete on it.
Definition class.h:98
bool IsValidRegistryIdentifier(const std::string &name)
Definition registry_util.cpp:54
std::string GetRegistryIdentifierMessage()
Definition registry_util.cpp:62
#define UG_THROW(msg)
Definition error.h:57
#define UG_API
Definition ug_config.h:65
the ug namespace
string TrimString(const string &str)
Definition string_util.cpp:104
function func(x, y, z, t, si)
#define UG_THROW_REGISTRY_ERROR(cls, msg)
Definition error.h:76
Definition class.h:471
static void * create(const ParameterStack &in)
Definition class.h:472
Definition param_to_type_value_list.h:88
ConstructorOverload(ExportedConstructor *func, size_t typeID)
Definition class.h:679
ExportedConstructor * m_constructor
Definition class.h:682
size_t m_typeID
Definition class.h:275
ExportedMethod * m_func
Definition class.h:274
Overload(ExportedMethod *func, size_t typeID)
Definition class.h:271
static void apply(const MethodPtrWrapper &method, void *obj, const ParameterStack &in, ParameterStack &out)
Definition class.h:331
static void apply(const MethodPtrWrapper &method, void *obj, const ParameterStack &in, ParameterStack &out)
Definition class.h:310
Definition class.h:285
static void apply(const MethodPtrWrapper &method, void *obj, const ParameterStack &in, ParameterStack &out)
Definition class.h:286
Definition param_to_type_value_list.h:71
Definition function_traits.h:525
Definition function_traits.h:59