object.h
1 /*************************************************************************/
2 /* object.h */
3 /*************************************************************************/
4 /* This file is part of: */
5 /* GODOT ENGINE */
6 /* http://www.godotengine.org */
7 /*************************************************************************/
8 /* Copyright (c) 2007-2016 Juan Linietsky, Ariel Manzur. */
9 /* */
10 /* Permission is hereby granted, free of charge, to any person obtaining */
11 /* a copy of this software and associated documentation files (the */
12 /* "Software"), to deal in the Software without restriction, including */
13 /* without limitation the rights to use, copy, modify, merge, publish, */
14 /* distribute, sublicense, and/or sell copies of the Software, and to */
15 /* permit persons to whom the Software is furnished to do so, subject to */
16 /* the following conditions: */
17 /* */
18 /* The above copyright notice and this permission notice shall be */
19 /* included in all copies or substantial portions of the Software. */
20 /* */
21 /* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
22 /* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
23 /* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
24 /* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
25 /* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
26 /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
27 /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
28 /*************************************************************************/
29 #ifndef OBJECT_H
30 #define OBJECT_H
31 
32 #include "list.h"
33 #include "variant.h"
34 #include "set.h"
35 #include "map.h"
36 #include "vmap.h"
37 
38 #define VARIANT_ARG_LIST const Variant& p_arg1=Variant(),const Variant& p_arg2=Variant(),const Variant& p_arg3=Variant(),const Variant& p_arg4=Variant(),const Variant& p_arg5=Variant()
39 #define VARIANT_ARG_PASS p_arg1,p_arg2,p_arg3,p_arg4,p_arg5
40 #define VARIANT_ARG_DECLARE const Variant& p_arg1,const Variant& p_arg2,const Variant& p_arg3,const Variant& p_arg4,const Variant& p_arg5
41 #define VARIANT_ARG_MAX 5
42 #define VARIANT_ARGPTRS const Variant *argptr[5]={&p_arg1,&p_arg2,&p_arg3,&p_arg4,&p_arg5};
43 #define VARIANT_ARGPTRS_PASS *argptr[0],*argptr[1],*argptr[2],*argptr[3],*argptr[4]
44 #define VARIANT_ARGS_FROM_ARRAY(m_arr) m_arr[0],m_arr[1],m_arr[2],m_arr[3],m_arr[4]
45 
50 enum PropertyHint {
51  PROPERTY_HINT_NONE,
52  PROPERTY_HINT_RANGE,
53  PROPERTY_HINT_EXP_RANGE,
54  PROPERTY_HINT_ENUM,
55  PROPERTY_HINT_EXP_EASING,
56  PROPERTY_HINT_LENGTH,
57  PROPERTY_HINT_SPRITE_FRAME,
58  PROPERTY_HINT_KEY_ACCEL,
59  PROPERTY_HINT_FLAGS,
60  PROPERTY_HINT_ALL_FLAGS,
61  PROPERTY_HINT_FILE,
62  PROPERTY_HINT_DIR,
63  PROPERTY_HINT_GLOBAL_FILE,
64  PROPERTY_HINT_GLOBAL_DIR,
65  PROPERTY_HINT_RESOURCE_TYPE,
66  PROPERTY_HINT_MULTILINE_TEXT,
67  PROPERTY_HINT_COLOR_NO_ALPHA,
68  PROPERTY_HINT_IMAGE_COMPRESS_LOSSY,
69  PROPERTY_HINT_IMAGE_COMPRESS_LOSSLESS,
70  PROPERTY_HINT_MAX,
71 };
72 
73 enum PropertyUsageFlags {
74 
75  PROPERTY_USAGE_STORAGE=1,
76  PROPERTY_USAGE_EDITOR=2,
77  PROPERTY_USAGE_NETWORK=4,
78  PROPERTY_USAGE_EDITOR_HELPER=8,
79  PROPERTY_USAGE_CHECKABLE=16, //used for editing global variables
80  PROPERTY_USAGE_CHECKED=32, //used for editing global variables
81  PROPERTY_USAGE_INTERNATIONALIZED=64, //hint for internationalized strings
82  PROPERTY_USAGE_BUNDLE=128, //used for optimized bundles
83  PROPERTY_USAGE_CATEGORY=256,
84  PROPERTY_USAGE_STORE_IF_NONZERO=512, //only store if nonzero
85  PROPERTY_USAGE_STORE_IF_NONONE=1024, //only store if false
86  PROPERTY_USAGE_NO_INSTANCE_STATE=2048,
87 
88  PROPERTY_USAGE_DEFAULT=PROPERTY_USAGE_STORAGE|PROPERTY_USAGE_EDITOR|PROPERTY_USAGE_NETWORK,
89  PROPERTY_USAGE_DEFAULT_INTL=PROPERTY_USAGE_STORAGE|PROPERTY_USAGE_EDITOR|PROPERTY_USAGE_NETWORK|PROPERTY_USAGE_INTERNATIONALIZED,
90  PROPERTY_USAGE_NOEDITOR=PROPERTY_USAGE_STORAGE|PROPERTY_USAGE_NETWORK,
91 };
92 
93 
94 
95 
96 #define ADD_SIGNAL( m_signal ) ObjectTypeDB::add_signal( get_type_static(), m_signal )
97 #define ADD_PROPERTY( m_property, m_setter, m_getter ) ObjectTypeDB::add_property( get_type_static(), m_property, m_setter, m_getter )
98 #define ADD_PROPERTYI( m_property, m_setter, m_getter, m_index ) ObjectTypeDB::add_property( get_type_static(), m_property, m_setter, m_getter, m_index )
99 #define ADD_PROPERTYNZ( m_property, m_setter, m_getter ) ObjectTypeDB::add_property( get_type_static(), (m_property).added_usage(PROPERTY_USAGE_STORE_IF_NONZERO), m_setter, m_getter )
100 #define ADD_PROPERTYINZ( m_property, m_setter, m_getter, m_index ) ObjectTypeDB::add_property( get_type_static(), (m_property).added_usage(PROPERTY_USAGE_STORE_IF_NONZERO), m_setter, m_getter, m_index )
101 #define ADD_PROPERTYNO( m_property, m_setter, m_getter ) ObjectTypeDB::add_property( get_type_static(), (m_property).added_usage(PROPERTY_USAGE_STORE_IF_NONONE), m_setter, m_getter )
102 #define ADD_PROPERTYINO( m_property, m_setter, m_getter, m_index ) ObjectTypeDB::add_property( get_type_static(), (m_property).added_usage(PROPERTY_USAGE_STORE_IF_NONONE), m_setter, m_getter, m_index )
103 
104 struct PropertyInfo {
105 
106  Variant::Type type;
107  String name;
108  PropertyHint hint;
109  String hint_string;
110  uint32_t usage;
111 
112  _FORCE_INLINE_ PropertyInfo added_usage(int p_fl) const { PropertyInfo pi=*this; pi.usage|=p_fl; return pi; }
113 
114  PropertyInfo() { type=Variant::NIL; hint=PROPERTY_HINT_NONE; usage = PROPERTY_USAGE_DEFAULT; }
115  PropertyInfo( Variant::Type p_type, const String p_name, PropertyHint p_hint=PROPERTY_HINT_NONE, const String& p_hint_string="",uint32_t p_usage=PROPERTY_USAGE_DEFAULT) {
116  type=p_type; name=p_name; hint=p_hint; hint_string=p_hint_string; usage=p_usage;
117  }
118  bool operator<(const PropertyInfo& p_info) const {
119  return name<p_info.name;
120  }
121 };
122 
123 
124 
125 Array convert_property_list(const List<PropertyInfo> * p_list);
126 
127 struct MethodInfo {
128 
129  String name;
130  List<PropertyInfo> arguments;
131  Vector<Variant> default_arguments;
132  PropertyInfo return_val;
133  uint32_t flags;
134  int id;
135 
136  inline bool operator<(const MethodInfo& p_method) const { return id==p_method.id?(name < p_method.name):(id<p_method.id); }
137 
138  MethodInfo();
139  MethodInfo(const String& p_name);
140  MethodInfo(const String& p_name, const PropertyInfo& p_param1);
141  MethodInfo(const String& p_name, const PropertyInfo& p_param1,const PropertyInfo& p_param2);
142  MethodInfo(const String& p_name, const PropertyInfo& p_param1,const PropertyInfo& p_param2,const PropertyInfo& p_param3);
143  MethodInfo(const String& p_name, const PropertyInfo& p_param1,const PropertyInfo& p_param2,const PropertyInfo& p_param3,const PropertyInfo& p_param4);
144  MethodInfo(const String& p_name, const PropertyInfo& p_param1,const PropertyInfo& p_param2,const PropertyInfo& p_param3,const PropertyInfo& p_param4,const PropertyInfo& p_param5);
145  MethodInfo(Variant::Type ret);
146  MethodInfo(Variant::Type ret,const String& p_name);
147  MethodInfo(Variant::Type ret,const String& p_name, const PropertyInfo& p_param1);
148  MethodInfo(Variant::Type ret,const String& p_name, const PropertyInfo& p_param1,const PropertyInfo& p_param2);
149  MethodInfo(Variant::Type ret,const String& p_name, const PropertyInfo& p_param1,const PropertyInfo& p_param2,const PropertyInfo& p_param3);
150  MethodInfo(Variant::Type ret,const String& p_name, const PropertyInfo& p_param1,const PropertyInfo& p_param2,const PropertyInfo& p_param3,const PropertyInfo& p_param4);
151  MethodInfo(Variant::Type ret,const String& p_name, const PropertyInfo& p_param1,const PropertyInfo& p_param2,const PropertyInfo& p_param3,const PropertyInfo& p_param4,const PropertyInfo& p_param5);
152 };
153 
154 // old cast_to
155 //if ( is_type(T::get_type_static()) )
156 //return static_cast<T*>(this);
158 //return NULL;
159 
160 /*
161  the following is an uncomprehensible blob of hacks and workarounds to compensate for many of the fallencies in C++. As a plus, this macro pretty much alone defines the object model.
162 */
163 
164 #define REVERSE_GET_PROPERTY_LIST \
165 public:\
166 _FORCE_INLINE_ bool _is_gpl_reversed() const { return true; };\
167 private:
168 
169 #define UNREVERSE_GET_PROPERTY_LIST \
170 public:\
171 _FORCE_INLINE_ bool _is_gpl_reversed() const { return false; };\
172 private:
173 
174 
175 
176 #define OBJ_TYPE( m_type, m_inherits )\
177 private:\
178  void operator=(const m_type& p_rval) {}\
179  mutable StringName _type_name;\
180  friend class ObjectTypeDB;\
181 public:\
182 virtual String get_type() const { \
183  return String(#m_type);\
184 }\
185 virtual const StringName* _get_type_namev() const { \
186  if (!_type_name)\
187  _type_name=get_type_static();\
188  return &_type_name;\
189 }\
190 static _FORCE_INLINE_ void* get_type_ptr_static() { \
191  static int ptr;\
192  return &ptr;\
193 }\
194 static _FORCE_INLINE_ String get_type_static() { \
195  return String(#m_type);\
196 }\
197 static _FORCE_INLINE_ String get_parent_type_static() { \
198  return m_inherits::get_type_static();\
199 }\
200 static void get_inheritance_list_static(List<String>* p_inheritance_list) { \
201  m_inherits::get_inheritance_list_static(p_inheritance_list);\
202  p_inheritance_list->push_back(String(#m_type));\
203 }\
204 static String get_category_static() { \
205  String category = m_inherits::get_category_static();\
206  if (_get_category!=m_inherits::_get_category) {\
207  if (category!="")\
208  category+="/";\
209  category+=_get_category();\
210  }\
211  return category;\
212 }\
213 static String inherits_static() {\
214  return String(#m_inherits);\
215 }\
216 virtual bool is_type(const String& p_type) const { return (p_type==(#m_type))?true:m_inherits::is_type(p_type); }\
217 virtual bool is_type_ptr(void *p_ptr) const { return (p_ptr==get_type_ptr_static())?true:m_inherits::is_type_ptr(p_ptr); }\
218 \
219 \
220 static void get_valid_parents_static(List<String> *p_parents) {\
221 \
222  if (m_type::_get_valid_parents_static!=m_inherits::_get_valid_parents_static) { \
223  m_type::_get_valid_parents_static(p_parents);\
224  }\
225 \
226  m_inherits::get_valid_parents_static(p_parents);\
227 }\
228 protected:\
229 _FORCE_INLINE_ static void (*_get_bind_methods())() {\
230  return &m_type::_bind_methods;\
231 }\
232 public:\
233 static void initialize_type() {\
234  static bool initialized=false;\
235  if (initialized)\
236  return;\
237  m_inherits::initialize_type();\
238  ObjectTypeDB::_add_type<m_type>();\
239  if (m_type::_get_bind_methods() != m_inherits::_get_bind_methods())\
240  _bind_methods();\
241  initialized=true;\
242 }\
243 protected:\
244 virtual void _initialize_typev() {\
245  initialize_type();\
246 }\
247 _FORCE_INLINE_ bool (Object::* (_get_get() const))(const StringName& p_name,Variant&) const {\
248  return (bool (Object::*)(const StringName&,Variant&)const) &m_type::_get;\
249 }\
250 virtual bool _getv(const StringName& p_name, Variant& r_ret) const { \
251  if (m_type::_get_get() != m_inherits::_get_get()) {\
252  if (_get(p_name,r_ret))\
253  return true;\
254  }\
255  return m_inherits::_getv(p_name,r_ret);\
256 }\
257 _FORCE_INLINE_ bool (Object::* (_get_set() const))(const StringName& p_name,const Variant &p_property) {\
258  return (bool (Object::*)(const StringName&, const Variant&))&m_type::_set;\
259 }\
260 virtual bool _setv(const StringName& p_name,const Variant &p_property) { \
261  if (m_inherits::_setv(p_name,p_property)) return true;\
262  if (m_type::_get_set() != m_inherits::_get_set()) {\
263  return _set(p_name,p_property);\
264  \
265  }\
266  return false;\
267 }\
268 _FORCE_INLINE_ void (Object::* (_get_get_property_list() const))(List<PropertyInfo> *p_list) const{\
269  return (void (Object::*)(List<PropertyInfo>*)const)&m_type::_get_property_list;\
270 }\
271 virtual void _get_property_listv(List<PropertyInfo> *p_list,bool p_reversed) const { \
272  if (!p_reversed) {\
273  m_inherits::_get_property_listv(p_list,p_reversed);\
274  }\
275  p_list->push_back( PropertyInfo(Variant::NIL,get_type_static(),PROPERTY_HINT_NONE,String(),PROPERTY_USAGE_CATEGORY));\
276  if (!_is_gpl_reversed())\
277  ObjectTypeDB::get_property_list(#m_type,p_list,true);\
278  if (m_type::_get_get_property_list() != m_inherits::_get_get_property_list()) {\
279  _get_property_list(p_list);\
280  }\
281  if (_is_gpl_reversed())\
282  ObjectTypeDB::get_property_list(#m_type,p_list,true);\
283  if (p_reversed) {\
284  m_inherits::_get_property_listv(p_list,p_reversed);\
285  }\
286 \
287 }\
288 _FORCE_INLINE_ void (Object::* (_get_notification() const))(int){\
289  return (void (Object::*)(int)) &m_type::_notification;\
290 }\
291 virtual void _notificationv(int p_notification,bool p_reversed) { \
292  if (!p_reversed) \
293  m_inherits::_notificationv(p_notification,p_reversed);\
294  if (m_type::_get_notification() != m_inherits::_get_notification()) {\
295  _notification(p_notification);\
296  }\
297  if (p_reversed)\
298  m_inherits::_notificationv(p_notification,p_reversed);\
299 }\
300 \
301 private:
302 
303 
304 #define OBJ_CATEGORY(m_category)\
305 protected:\
306 _FORCE_INLINE_ static String _get_category() { return m_category; }\
307 private:
308 
309 #define OBJ_SAVE_TYPE(m_type) \
310 public: \
311 virtual String get_save_type() const { return #m_type; }\
312 private:
313 
314 class ScriptInstance;
315 typedef uint32_t ObjectID;
316 
317 class Object {
318 public:
319 
320  enum ConnectFlags {
321 
322  CONNECT_DEFERRED=1,
323  CONNECT_PERSIST=2, // hint for scene to save this connection
324  CONNECT_ONESHOT=4
325  };
326 
327  struct Connection {
328 
329  Object *source;
330  StringName signal;
331  Object *target;
332  StringName method;
333  uint32_t flags;
334  Vector<Variant> binds;
335  bool operator<(const Connection& p_conn) const;
336 
337  operator Variant() const;
338  Connection() { source=NULL; target=NULL; flags=0; }
339  Connection(const Variant& p_variant);
340  };
341 private:
342 #ifdef DEBUG_ENABLED
343 friend class _ObjectDebugLock;
344 #endif
345 friend bool predelete_handler(Object*);
346 friend void postinitialize_handler(Object*);
347 
348 
349  struct Signal {
350 
351  struct Target {
352 
353  ObjectID _id;
354  StringName method;
355 
356  _FORCE_INLINE_ bool operator<(const Target& p_target) const { return (_id==p_target._id)?(method<p_target.method):(_id<p_target._id); }
357 
358  Target(const ObjectID& p_id, const StringName& p_method) { _id=p_id; method=p_method; }
359  Target() { _id=0; }
360  };
361 
362  struct Slot {
363 
364  Connection conn;
366  };
367 
368  MethodInfo user;
369  VMap<Target,Slot> slot_map;
370  int lock;
371  Signal() { lock=0; }
372 
373  };
374 
375 
377  List<Connection> connections;
378 #ifdef DEBUG_ENABLED
379  SafeRefCount _lock_index;
380 #endif
381  bool _block_signals;
382  int _predelete_ok;
383  Set<Object*> change_receptors;
384  uint32_t _instance_ID;
385  bool _predelete();
386  void _postinitialize();
387  bool _can_translate;
388 #ifdef TOOLS_ENABLED
389  bool _edited;
390 #endif
391  ScriptInstance *script_instance;
392  RefPtr script;
393  Dictionary metadata;
394  mutable StringName _type_name;
395  mutable const StringName* _type_ptr;
396 
397  void _add_user_signal(const String& p_name, const Array& p_pargs=Array());
398  bool _has_user_signal(const StringName& p_name) const;
399  Variant _emit_signal(const Variant** p_args, int p_argcount, Variant::CallError& r_error);
400  Array _get_signal_list() const;
401  Array _get_signal_connection_list(const String& p_signal) const;
402  void _set_bind(const String& p_set,const Variant& p_value);
403  Variant _get_bind(const String& p_name) const;
404 
405  void property_list_changed_notify();
406 
407 protected:
408 
409  virtual bool _use_builtin_script() const { return false; }
410  virtual void _initialize_typev() { initialize_type(); }
411  virtual bool _setv(const StringName& p_name,const Variant &p_property) { return false; };
412  virtual bool _getv(const StringName& p_name,Variant &r_property) const { return false; };
413  virtual void _get_property_listv(List<PropertyInfo> *p_list,bool p_reversed) const {};
414  virtual void _notificationv(int p_notification,bool p_reversed) {};
415 
416  static String _get_category() { return ""; }
417  static void _bind_methods();
418  bool _set(const StringName& p_name,const Variant &p_property) { return false; };
419  bool _get(const StringName& p_name,Variant &r_property) const { return false; };
420  void _get_property_list(List<PropertyInfo> *p_list) const {};
421  void _notification(int p_notification) {};
422 
423  _FORCE_INLINE_ static void (*_get_bind_methods())() {
424  return &Object::_bind_methods;
425  }
426  _FORCE_INLINE_ bool (Object::* (_get_get() const))(const StringName& p_name,Variant &r_ret) const {
427  return &Object::_get;
428  }
429  _FORCE_INLINE_ bool (Object::* (_get_set() const))(const StringName& p_name,const Variant &p_property) {
430  return &Object::_set;
431  }
432  _FORCE_INLINE_ void (Object::* (_get_get_property_list() const))(List<PropertyInfo> *p_list) const{
433  return &Object::_get_property_list;
434  }
435  _FORCE_INLINE_ void (Object::* (_get_notification() const))(int){
436  return &Object::_notification;
437  }
438  static void get_valid_parents_static(List<String> *p_parents);
439  static void _get_valid_parents_static(List<String> *p_parents);
440 
441 
442  void cancel_delete();
443 
444  virtual void _changed_callback(Object *p_changed,const char *p_prop);
445 
446  //Variant _call_bind(const StringName& p_name, const Variant& p_arg1 = Variant(), const Variant& p_arg2 = Variant(), const Variant& p_arg3 = Variant(), const Variant& p_arg4 = Variant());
447  //void _call_deferred_bind(const StringName& p_name, const Variant& p_arg1 = Variant(), const Variant& p_arg2 = Variant(), const Variant& p_arg3 = Variant(), const Variant& p_arg4 = Variant());
448 
449  Variant _call_bind(const Variant** p_args, int p_argcount, Variant::CallError& r_error);
450  Variant _call_deferred_bind(const Variant** p_args, int p_argcount, Variant::CallError& r_error);
451 
452 
453  virtual const StringName* _get_type_namev() const {
454  if (!_type_name)
455  _type_name=get_type_static();
456  return &_type_name;
457  }
458 
459  DVector<String> _get_meta_list_bind() const;
460  Array _get_property_list_bind() const;
461  Array _get_method_list_bind() const;
462 
463  void _clear_internal_resource_paths(const Variant &p_var);
464 
465 public: //should be protected, but bug in clang++
466  static void initialize_type();
467  _FORCE_INLINE_ static void register_custom_data_to_otdb() {};
468 
469 public:
470 
471 #ifdef TOOLS_ENABLED
472  _FORCE_INLINE_ void _change_notify(const char *p_property="") { _edited=true; for(Set<Object*>::Element *E=change_receptors.front();E;E=E->next()) ((Object*)(E->get()))->_changed_callback(this,p_property); }
473 #else
474  _FORCE_INLINE_ void _change_notify(const char *p_what="") { }
475 #endif
476  static void* get_type_ptr_static() {
477  static int ptr;
478  return &ptr;
479  }
480 
481  bool _is_gpl_reversed() const { return false; }
482 
483  _FORCE_INLINE_ ObjectID get_instance_ID() const { return _instance_ID; }
484  // this is used for editors
485 
486  void add_change_receptor( Object *p_receptor );
487  void remove_change_receptor( Object *p_receptor );
488 
489  template<class T>
490  T *cast_to() {
491 
492 #ifndef NO_SAFE_CAST
493  return SAFE_CAST<T*>(this);
494 #else
495  if (!this)
496  return NULL;
497  if (is_type_ptr(T::get_type_ptr_static()))
498  return static_cast<T*>(this);
499  else
500  return NULL;
501 #endif
502  }
503 
504  template<class T>
505  const T *cast_to() const {
506 
507 #ifndef NO_SAFE_CAST
508  return SAFE_CAST<const T*>(this);
509 #else
510  if (!this)
511  return NULL;
512  if (is_type_ptr(T::get_type_ptr_static()))
513  return static_cast<const T*>(this);
514  else
515  return NULL;
516 #endif
517  }
518 
519  enum {
520 
521  NOTIFICATION_POSTINITIALIZE=0,
522  NOTIFICATION_PREDELETE=1
523  };
524 
525  /* TYPE API */
526  static void get_inheritance_list_static(List<String>* p_inheritance_list) { p_inheritance_list->push_back("Object"); }
527 
528  static String get_type_static() { return "Object"; }
529  static String get_parent_type_static() { return String(); }
530  static String get_category_static() { return String(); }
531 
532 
533  virtual String get_type() const { return "Object"; }
534  virtual String get_save_type() const { return get_type(); } //type stored when saving
535 
536 
537 
538  virtual bool is_type(const String& p_type) const { return (p_type=="Object"); }
539  virtual bool is_type_ptr(void *p_ptr) const { return get_type_ptr_static()==p_ptr; }
540 
541  _FORCE_INLINE_ const StringName& get_type_name() const {
542  if (!_type_ptr) {
543  return *_get_type_namev();
544  } else {
545  return *_type_ptr;
546  }
547  }
548 
549  /* IAPI */
550 // void set(const String& p_name, const Variant& p_value);
551 // Variant get(const String& p_name) const;
552 
553  void set(const StringName& p_name, const Variant& p_value, bool *r_valid=NULL);
554  Variant get(const StringName& p_name, bool *r_valid=NULL) const;
555 
556  void get_property_list(List<PropertyInfo> *p_list,bool p_reversed=false) const;
557 
558  bool has_method(const StringName& p_method) const;
559  void get_method_list(List<MethodInfo> *p_list) const;
560  Variant callv(const StringName& p_method,const Array& p_args);
561  virtual Variant call(const StringName& p_method,const Variant** p_args,int p_argcount,Variant::CallError &r_error);
562  virtual void call_multilevel(const StringName& p_method,const Variant** p_args,int p_argcount);
563  virtual void call_multilevel_reversed(const StringName& p_method,const Variant** p_args,int p_argcount);
564  Variant call(const StringName& p_name, VARIANT_ARG_LIST); // C++ helper
565  void call_multilevel(const StringName& p_name, VARIANT_ARG_LIST); // C++ helper
566 
567  void notification(int p_notification,bool p_reversed=false);
568 
569  //used mainly by script, get and set all INCLUDING string
570  virtual Variant getvar(const Variant& p_key, bool *r_valid=NULL) const;
571  virtual void setvar(const Variant& p_key, const Variant& p_value,bool *r_valid=NULL);
572 
573  /* SCRIPT */
574 
575  void set_script(const RefPtr& p_script);
576  RefPtr get_script() const;
577 
578  /* SCRIPT */
579 
580  bool has_meta(const String& p_name) const;
581  void set_meta(const String& p_name, const Variant& p_value );
582  Variant get_meta(const String& p_name) const;
583  void get_meta_list(List<String> *p_list) const;
584 
585 #ifdef TOOLS_ENABLED
586  void set_edited(bool p_edited);
587  bool is_edited() const;
588 #endif
589 
590  void set_script_instance(ScriptInstance *p_instance);
591  _FORCE_INLINE_ ScriptInstance* get_script_instance() const { return script_instance; }
592 
593 
594  void add_user_signal(const MethodInfo& p_signal);
595  void emit_signal(const StringName& p_name,VARIANT_ARG_LIST);
596  void emit_signal(const StringName& p_name, const Variant** p_args, int p_argcount);
597  void get_signal_list(List<MethodInfo> *p_signals ) const;
598  void get_signal_connection_list(const StringName& p_signal,List<Connection> *p_connections) const;
599  void get_all_signal_connections(List<Connection> *p_connections) const;
600 
601  Error connect(const StringName& p_signal, Object *p_to_object, const StringName& p_to_method,const Vector<Variant>& p_binds=Vector<Variant>(),uint32_t p_flags=0);
602  void disconnect(const StringName& p_signal, Object *p_to_object, const StringName& p_to_method);
603  bool is_connected(const StringName& p_signal, Object *p_to_object, const StringName& p_to_method) const;
604 
605  void call_deferred(const StringName& p_method,VARIANT_ARG_LIST);
606 
607  void set_block_signals(bool p_block);
608  bool is_blocking_signals() const;
609 
610  Variant::Type get_static_property_type(const StringName& p_property,bool *r_valid=NULL) const;
611 
612  virtual void get_translatable_strings(List<String> *p_strings) const;
613 
614  virtual void get_argument_options(const StringName& p_function,int p_idx,List<String>*r_options) const;
615 
616  StringName XL_MESSAGE(const StringName& p_message) const; //translate message (internationalization)
617  StringName tr(const StringName& p_message) const; //translate message (alternative)
618 
619  bool _is_queued_for_deletion; // set to true by SceneTree::queue_delete()
620  bool is_queued_for_deletion() const;
621 
622  _FORCE_INLINE_ void set_message_translation(bool p_enable) { _can_translate=p_enable; }
623  _FORCE_INLINE_ bool can_translate_messages() const { return _can_translate; }
624 
625  void clear_internal_resource_paths();
626 
627  Object();
628  virtual ~Object();
629 
630 };
631 
632 
633 bool predelete_handler(Object *p_object);
634 void postinitialize_handler(Object *p_object);
635 
636 class ObjectDB {
637 
638  struct ObjectPtrHash {
639 
640  static _FORCE_INLINE_ uint32_t hash(const Object *p_obj) {
641 
642  union {
643  const Object*p;
644  unsigned long i;
645  } u;
646  u.p=p_obj;
647  return HashMapHahserDefault::hash((uint64_t)u.i);
648  }
649  };
650 
651  static HashMap<uint32_t,Object*> instances;
652  static HashMap<Object*,ObjectID,ObjectPtrHash> instance_checks;
653 
654  static uint32_t instance_counter;
655 friend class Object;
656 friend void unregister_core_types();
657 
658  static void cleanup();
659  static uint32_t add_instance(Object *p_object);
660  static void remove_instance(Object *p_object);
661 public:
662 
663  typedef void (*DebugFunc)(Object *p_obj);
664 
665  static Object *get_instance(uint32_t p_instance_ID);
666  static void debug_objects(DebugFunc p_func);
667  static int get_object_count();
668 
669 #ifdef DEBUG_ENABLED
670  _FORCE_INLINE_ static bool instance_validate(Object* p_ptr) {
671 
672  return instance_checks.has(p_ptr);
673  }
674 #else
675  _FORCE_INLINE_ static bool instance_validate(Object* p_ptr) { return true; }
676 
677 #endif
678 
679 
680 
681 };
682 
683 //needed by macros
684 #include "object_type_db.h"
685 
686 #endif
Definition: ref_ptr.h:40
Definition: array.h:38
Element * push_back(const T &value)
Definition: list.h:220
Definition: variant.h:74
Definition: list.h:49
Definition: object.h:104
Definition: safe_refcount.h:336
Definition: string_db.h:48
Definition: object.h:327
Definition: object.h:636
Definition: vmap.h:36
Definition: dictionary.h:42
Definition: object.h:362
Definition: script_language.h:109
Definition: object.h:127
Definition: dvector.h:43
Definition: ustring.h:64
Definition: object.h:317
Definition: object.h:351
Definition: variant.h:379