29 #ifndef OBJECT_TYPE_DB_H 30 #define OBJECT_TYPE_DB_H 33 #include "method_bind.h" 34 #include "print_string.h" 50 hint_text=p_hint_text;
51 default_val=p_default_val;
59 _FORCE_INLINE_
ParamDef() { used=
false; }
64 #define DEFVAL( m_defval ) (m_defval) 69 #ifdef DEBUG_METHODS_ENABLED 71 struct MethodDefinition {
77 MethodDefinition(
const char *p_name) { name=p_name; }
78 MethodDefinition(
const StringName& p_name) { name=p_name; }
83 MethodDefinition _MD(
const char* p_name);
84 MethodDefinition _MD(
const char* p_name,
const char *p_arg1);
85 MethodDefinition _MD(
const char* p_name,
const char *p_arg1,
const char *p_arg2);
86 MethodDefinition _MD(
const char* p_name,
const char *p_arg1,
const char *p_arg2,
const char *p_arg3);
87 MethodDefinition _MD(
const char* p_name,
const char *p_arg1,
const char *p_arg2,
const char *p_arg3,
const char *p_arg4);
88 MethodDefinition _MD(
const char* p_name,
const char *p_arg1,
const char *p_arg2,
const char *p_arg3,
const char *p_arg4,
const char *p_arg5);
89 MethodDefinition _MD(
const char* p_name,
const char *p_arg1,
const char *p_arg2,
const char *p_arg3,
const char *p_arg4,
const char *p_arg5,
const char *p_arg6);
90 MethodDefinition _MD(
const char* p_name,
const char *p_arg1,
const char *p_arg2,
const char *p_arg3,
const char *p_arg4,
const char *p_arg5,
const char *p_arg6,
const char *p_arg7);
91 MethodDefinition _MD(
const char* p_name,
const char *p_arg1,
const char *p_arg2,
const char *p_arg3,
const char *p_arg4,
const char *p_arg5,
const char *p_arg6,
const char *p_arg7,
const char *p_arg8);
92 MethodDefinition _MD(
const char* p_name,
const char *p_arg1,
const char *p_arg2,
const char *p_arg3,
const char *p_arg4,
const char *p_arg5,
const char *p_arg6,
const char *p_arg7,
const char *p_arg8,
const char *p_arg9);
93 MethodDefinition _MD(
const char* p_name,
const char *p_arg1,
const char *p_arg2,
const char *p_arg3,
const char *p_arg4,
const char *p_arg5,
const char *p_arg6,
const char *p_arg7,
const char *p_arg8,
const char *p_arg9,
const char *p_arg10);
99 #ifdef NO_VARIADIC_MACROS 101 static _FORCE_INLINE_
const char* _MD(
const char* m_name, ...) {
return m_name; }
105 #define _MD(m_c, ...) m_c 113 struct PropertySetGet {
125 TypeInfo *inherits_ptr;
130 #ifdef DEBUG_METHODS_ENABLED 142 Object* (*creation_func)();
148 static Object *creator() {
157 #ifdef DEBUG_METHODS_ENABLED 158 static MethodBind* bind_methodfi(uint32_t p_flags,
MethodBind *p_bind ,
const MethodDefinition &method_name,
const Variant **p_defs,
int p_defcount);
160 static MethodBind* bind_methodfi(uint32_t p_flags,
MethodBind *p_bind ,
const char *method_name,
const Variant **p_defs,
int p_defcount);
170 static void _add_type() {
172 _add_type2(T::get_type_static(),T::get_parent_type_static());
174 GLOBAL_LOCK_FUNCTION;
178 ERR_FAIL_COND(types.has(name));
180 types[name]=TypeInfo();
181 TypeInfo &ti=types[name];
183 ti.inherits=T::get_parent_type_static();
187 ERR_FAIL_COND( !types.has(ti.inherits) );
188 ti.inherits_ptr = &types[ti.inherits];
191 ti.inherits_ptr=NULL;
197 static void register_type() {
199 GLOBAL_LOCK_FUNCTION;
200 T::initialize_type();
201 TypeInfo *t=types.
getptr(T::get_type_static());
203 t->creation_func=&creator<T>;
204 T::register_custom_data_to_otdb();
208 static void register_virtual_type() {
210 GLOBAL_LOCK_FUNCTION;
211 T::initialize_type();
216 static Object* _create_ptr_func() {
222 static void register_create_type() {
224 GLOBAL_LOCK_FUNCTION;
225 T::initialize_type();
226 TypeInfo *t=types.
getptr(T::get_type_static());
228 t->creation_func=&_create_ptr_func<T>;
229 T::register_custom_data_to_otdb();
235 static bool type_exists(
const StringName &p_type);
237 static bool can_instance(
const StringName &p_type);
241 template<
class N,
class M>
242 static MethodBind* bind_method(N p_method_name, M p_method,
251 return bind_methodf(METHOD_FLAGS_DEFAULT,p_method_name, p_method, d1,d2,d3,d4,d5);
256 template<
class N,
class M>
257 static MethodBind* bind_methodf(uint32_t p_flags, N p_method_name, M p_method,
268 GLOBAL_LOCK_FUNCTION;
270 MethodDefinition method_name=p_method_name;
272 MethodBind *bind = create_method_bind(p_method);
273 bind->set_name(method_name.name);
274 ERR_FAIL_COND_V(!bind,NULL);
276 String instance_type=bind->get_instance_type();
278 TypeInfo *type=types.
getptr(instance_type);
281 ERR_FAIL_COND_V(!type,NULL);
284 if (type->method_map.has(method_name.name)) {
287 ERR_EXPLAIN(
"Method already bound: "+instance_type+
"::"+method_name.name);
290 bind->set_argument_names(method_name.args);
291 type->method_map[method_name.name]=bind;
295 #define PARSE_DEFVAL(m_defval)\ 296 if (d##m_defval.used) defvals.insert(0,d##m_defval.val);\ 297 else goto set_defvals; 307 bind->set_default_arguments(defvals);
308 bind->set_hint_flags(p_flags);
316 template<
class N,
class M>
317 static MethodBind* bind_method(N p_method_name, M p_method,
326 MethodDefinition method_name=p_method_name;
328 MethodBind *bind = create_method_bind(p_method);
330 return bind_methodfi(METHOD_FLAGS_DEFAULT,bind,method_name,d1,d2,d3,d4,d5);
334 template<
class N,
class M>
335 static MethodBind* bind_method(N p_method_name, M p_method) {
337 MethodBind *bind = create_method_bind(p_method);
339 return bind_methodfi(METHOD_FLAGS_DEFAULT,bind,p_method_name,NULL,0);
342 template<
class N,
class M>
343 static MethodBind* bind_method(N p_method_name, M p_method,
const Variant& p_def1) {
345 MethodBind *bind = create_method_bind(p_method);
346 const Variant* ptr[1]={&p_def1};
348 return bind_methodfi(METHOD_FLAGS_DEFAULT,bind,p_method_name,ptr,1);
352 template<
class N,
class M>
355 MethodBind *bind = create_method_bind(p_method);
356 const Variant* ptr[2]={&p_def1,&p_def2};
358 return bind_methodfi(METHOD_FLAGS_DEFAULT,bind,p_method_name,ptr,2);
361 template<
class N,
class M>
364 MethodBind *bind = create_method_bind(p_method);
365 const Variant* ptr[3]={&p_def1,&p_def2,&p_def3};
367 return bind_methodfi(METHOD_FLAGS_DEFAULT,bind,p_method_name,ptr,3);
370 template<
class N,
class M>
373 MethodBind *bind = create_method_bind(p_method);
374 const Variant* ptr[4]={&p_def1,&p_def2,&p_def3,&p_def4};
376 return bind_methodfi(METHOD_FLAGS_DEFAULT,bind,p_method_name,ptr,4);
379 template<
class N,
class M>
382 MethodBind *bind = create_method_bind(p_method);
383 const Variant* ptr[5]={&p_def1,&p_def2,&p_def3,&p_def4,&p_def5};
385 return bind_methodfi(METHOD_FLAGS_DEFAULT,bind,p_method_name,ptr,5);
388 template<
class N,
class M>
391 MethodBind *bind = create_method_bind(p_method);
392 const Variant* ptr[6]={&p_def1,&p_def2,&p_def3,&p_def4,&p_def5,&p_def6};
394 return bind_methodfi(METHOD_FLAGS_DEFAULT,bind,p_method_name,ptr,6);
398 template<
class N,
class M>
399 static MethodBind* bind_methodf(uint32_t p_flags, N p_method_name, M p_method,
408 MethodDefinition method_name=p_method_name;
410 MethodBind *bind = create_method_bind(p_method);
412 return bind_methodfi(p_flags,bind,method_name,d1,d2,d3,d4,d5);
420 GLOBAL_LOCK_FUNCTION;
424 MethodBind *bind = create_native_method_bind(p_method,p_info);
425 ERR_FAIL_COND_V(!bind,NULL);
426 bind->set_name(p_name);
427 bind->set_default_arguments(p_default_args);
429 String instance_type=bind->get_instance_type();
431 TypeInfo *type=types.
getptr(instance_type);
434 ERR_FAIL_COND_V(!type,NULL);
437 if (type->method_map.has(p_name)) {
440 ERR_EXPLAIN(
"Method already bound: "+instance_type+
"::"+p_name);
443 type->method_map[p_name]=bind;
444 #ifdef DEBUG_METHODS_ENABLED 445 type->method_order.push_back(p_name);
460 static bool set_property(
Object* p_object,
const StringName& p_property,
const Variant& p_value,
bool *r_valid=NULL);
462 static Variant::Type get_property_type(
const StringName& p_type,
const StringName& p_property,
bool *r_is_valid=NULL);
473 static void add_virtual_method(
const StringName& p_type,
const MethodInfo& p_method,
bool p_virtual=
true );
476 static void bind_integer_constant(
const StringName& p_type,
const StringName &p_name,
int p_constant);
477 static void get_integer_constant_list(
const StringName& p_type,
List<String> *p_constants,
bool p_no_inheritance=
false);
478 static int get_integer_constant(
const StringName& p_type,
const StringName &p_name,
bool *p_success=NULL);
483 static void set_type_enabled(
StringName p_type,
bool p_enable);
484 static bool is_type_enabled(
StringName p_type);
486 static void add_resource_base_extension(
const StringName& p_extension,
const StringName& p_type);
487 static void get_resource_base_extensions(
List<String> *p_extensions);
492 static void cleanup();
496 #define BIND_CONSTANT(m_constant)\ 497 ObjectTypeDB::bind_integer_constant( get_type_static() , #m_constant, m_constant); 501 #define BIND_VMETHOD(m_method)\ 502 ObjectTypeDB::add_virtual_method( get_type_static() , m_method ); 506 #define BIND_VMETHOD(m_method)
Definition: object_type_db.h:56
Definition: string_db.h:48
Definition: object_type_db.h:39
_FORCE_INLINE_ TData * getptr(const TKey &p_key)
Definition: hash_map.h:341
Definition: method_bind.h:128
Definition: object_type_db.h:111