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