34 #ifndef __H__UG_BRIDGE__CLASS__
35 #define __H__UG_BRIDGE__CLASS__
40 #include <boost/type_traits.hpp>
41 #include <boost/optional.hpp>
52 #error "You need to define UG_PROFILER to use PROFILE_BRIDGE"
70 template <
typename TMethod>
73 size =
sizeof(TMethod);
97 delete reinterpret_cast<const TClass*
>(ptr);
102 UG_THROW(
"Can't delete instance of class 'void'");
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)
124 #ifdef PROFILE_BRIDGE
133 #ifdef PROFILE_BRIDGE
138 #ifdef PROFILE_BRIDGE
144 template <
typename TFunc>
147 ExportedFunctionBase::create_parameter_stack<TFunc>();
169 #ifdef PROFILE_BRIDGE
170 mutable RuntimeProfileInfo m_dpi;
197 template <
class TFunc>
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)
204 size_t typeID = GetUniqueTypeID<TFunc>();
213 methodOptions, retValInfos,
214 paramInfos, tooltip, help);
220 func->create_parameter_stack<TFunc>();
231 template <
class TType>
234 size_t typeID = GetUniqueTypeID<TType>();
238 template <
class TType>
241 size_t typeID = GetUniqueTypeID<TType>();
279 template <
typename TClass,
typename TMethod,
290 TClass* objPtr = (TClass*) (obj);
304 template <
typename TClass,
typename TMethod>
314 TClass* objPtr = (TClass*) (obj);
325 template <
typename TClass,
typename TMethod>
335 TClass* objPtr = (TClass*) (obj);
360 const std::string& className,
const std::string& options,
361 const std::string& paramInfos,
362 const std::string& tooltip,
const std::string& help);
367 #ifdef PROFILE_BRIDGE
371 void *pRet = m_proxy_func(paramsIn);
373 #ifdef PROFILE_BRIDGE
380 const std::string&
options()
const {
return m_options;}
386 size_t num_infos(
size_t i)
const {
return m_vvParamInfo.at(i).size();}
392 const std::string&
parameter_info(
size_t i,
size_t j)
const {
return m_vvParamInfo.at(i).at(j);}
401 const std::string&
tooltip()
const {
return m_tooltip;}
404 const std::string&
help()
const {
return m_help;}
413 bool check_consistency(std::string classname)
const;
415 template <
typename TFunc>
423 const size_t MinNumInfos = 3;
426 m_vvParamInfo.resize(m_paramsIn.size());
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(
""));
436 void tokenize(
const std::string& str, std::vector<std::string>& tokens,
437 const char delimiter);
461 #ifdef PROFILE_BRIDGE
462 mutable RuntimeProfileInfo m_dpi;
466 template <
typename TClass,
typename TMethod>
479 return (
void*) newInst;
483 template <
typename TClass>
486 TClass* pObj = (TClass*)obj;
505 virtual const std::string&
name()
const = 0;
508 virtual const std::string&
group()
const = 0;
514 virtual const std::string&
tooltip()
const = 0;
601 virtual const std::string&
tooltip()
const;
657 virtual void destroy(
void* obj)
const;
697 template <
typename TClass>
737 return t.add_to(*
this);
751 template <
typename TMethod>
753 std::string retValInfos =
"", std::string paramInfos =
"",
754 std::string
tooltip =
"", std::string help =
"")
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);
768 strippedMethodName =
TrimString(strippedMethodName);
772 if(strippedMethodName.empty())
775 "Trying to register empty method name.");
781 "Trying to register method '"<< strippedMethodName <<
"' that"
782 <<
" contains illegal characters. "
804 methodOptions, retValInfos, paramInfos,
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.");
822 add_constructor<void (*)()>();
839 template <
typename TFunc>
841 std::string
tooltip =
"", std::string help =
"",
842 std::string options =
"")
848 "Trying to register constructor of class "
849 <<
name()<<
"with non-void return value in signature function.");
853 size_t typeID = GetUniqueTypeID<TFunc>();
859 "Trying to register constructor of class "
860 <<
name()<<
" with same signature twice.");
867 options, paramInfos,
tooltip, help);
882 return CastAndDelete<TClass>;
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 ¶msIn) 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 ¶mInfos, 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
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 ¶msIn, ParameterStack ¶msOut) 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 ¶mInfos, 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
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
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
static void * create(const ParameterStack &in)
Definition: class.h:469
static void create(ParameterInfo &in)
Definition: param_to_type_value_list.h:92
size_t m_typeID
Definition: class.h:680
ConstructorOverload(ExportedConstructor *func, size_t typeID)
Definition: class.h:676
ConstructorOverload()
Definition: class.h:675
ExportedConstructor * m_constructor
Definition: class.h:679
size_t m_typeID
Definition: class.h:272
Overload()
Definition: class.h:267
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
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